-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjinarch
executable file
·687 lines (602 loc) · 19.2 KB
/
jinarch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
#!/bin/bash
# ##############################################################################
# ############################### jinarch ######################################
# ##############################################################################
# Copyright (c) 2015-2017 Md. Jahidul Hamid
#
# -----------------------------------------------------------------------------
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * The names of its contributors may not be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# Disclaimer:
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# ##############################################################################
myself="$BASH_SOURCE"
pname=jinarch
author="Md. Jahidul Hamid <jahidulhamid@yahoo.com>"
bugt="https://github.com/neurobin/$pname"
pver='1.0.1'
verinfo="
*********** $pname ***********
Version: $pver
Author: $author
Bug report: $bugt
"
if [ "$1" = -v ] || [ "$1" = --version ]; then
echo "$verinfo"
exit 1
fi
if [ -f jinarch.conf ]; then
. jinarch.conf
elif [ -f /etc/jinarch.conf ]; then
. /etc/jinarch.conf
else
echo "W: jinarch.conf file not found" >/dev/stderr
fi
DEF_KEYMAP=us
DEF_KBD_DELAY=200
DEF_KBD_RATE=30
DEF_MIRRORS=20
DEF_TIME_ZONE=Asia/Dhaka
DEF_LOCALE_LANG=en_US.UTF-8
DEF_HOSTNAME=archlinux
DEF_INTEL_UCODE=y
DEF_USER="$pname"
DEF_OPT_DEV=none
DEF_USE_REFLECTOR=y
DEF_RSYNC_WITH_HOST=y
DEF_CREATE_USER=y
mps=('/' '/boot' '/home' '/var' '/tmp' 'swap')
declare -A opn=([/boot]=BOOT_DEV [/home]=HOME_DEV [/var]=VAR_DEV [/tmp]=TMP_DEV)
msg_out(){
printf "*** $*\n" #> /dev/stdout
}
_star_s(){
if [ "$1" = '' ]; then
title='**********'
else
title=" ($1) "
fi
local s="************************$title*****************************"
printf "\n\n\n*** $s\n" > /dev/stdout
}
_star_e(){
local s='***************************************************************'
printf "*** $s\n" > /dev/stdout
}
err_out(){
printf "\nE: $*\n" > /dev/stderr
}
wrn_out(){
printf "\nW: $*\n" > /dev/stderr
}
err_exit(){
err_out "$*"
exit 1
}
chkroot(){
if [ "$(id -u)" != "0" ]; then
err_out "root access required."
exit 1
fi
}
chknorm(){
if [ "$(id -u)" = "0" ]; then
wrn_out "Running as root not recommended. May produce some problems. Better run as a normal user."
return 1
fi
}
chkcmd(){
if command -v "$1" >/dev/null 2>&1; then
return 0
else
return 1
fi
}
get_yn(){
#$1: msg
#$2: timeout
local msg="
=== $(printf "$1")"
msg=$(echo "$msg" |sed -e 's/^[[:blank:]]*//')
local yn
local timeout="$2"
if [ "$timeout" = "" ]; then
read -p "$msg" yn >/dev/stderr 2>&1
else
read -t "$timeout" -p "$msg" yn >/dev/stderr 2>&1
fi
if [ "$yn" = y ] || [ "$yn" = Y ]; then
echo y > /dev/stdout
else
echo n > /dev/stdout
fi
}
get_yes_no(){
#$1: msg
#$2: timeout
local msg="
=== $(printf "$1")"
msg=$(echo "$msg" |sed -e 's/^[[:blank:]]*//')
local yn
local timeout="$2"
while true; do
if [ "$timeout" = "" ]; then
read -p "$msg (yes/no)?: " yn >/dev/stderr
else
read -t "$timeout" -p "$msg (yes/no)?: " yn >/dev/stderr
fi
if [ "$yn" = yes ]; then
echo yes > /dev/stdout
break
elif [ "$yn" = no ]; then
echo no > /dev/stdout
break
else
err_out "Either enter 'yes' or 'no'"
fi
done
}
get_prop_yn(){
local prop="$1"
local def="$2"
local msg="$3"
local cmd="$4"
local timeout="$5"
local bval="${!prop}"
local val="$bval"
if [ "$bval" = "" ]; then
#$cmd > /dev/stderr
local val=$(get_yn "$msg (Y/n)? (default '$def'): " "$timeout")
[ "$val" = "" ] && val="$def"
fi
if [ "$val" = y ] || [ "$val" = Y ]; then
echo y >/dev/stdout
else
echo n >/dev/stdout
fi
}
get_input(){
#$1: msg
#$2: timeout
local msg="
=== $(printf "$1")"
msg=$(echo "$msg" |sed -e 's/^[[:blank:]]*//')
local inp
local timeout="$2"
if [ "$timeout" = "" ]; then
read -p "$msg" inp >/dev/stderr
else
read -t "$timeout" -p "$msg" inp >/dev/stderr
fi
echo "$inp" > /dev/stdout
}
list_keymaps(){
msg_out 'Listing keymaps ...'
find /usr/share/kbd/keymaps -type f -printf '%P\n' |sed -e 's=.*/==' -e 's/\..*$//' | sort -u
}
chknet(){
dhcpcd
if ping -c 1 google.com; then
msg_out 'Network available'
return 0
elif ping -c 1 8.8.8.8; then
wrn_out 'Network available but DNS resolving not working. Fix /etc/resolv.conf'
return 1
else
wrn_out 'Network not available'
return 2
fi
}
get_prop_input(){
local prop="$1"
local def="$2"
local msg="$3"
local cmd="$4"
local timeout="$5"
local bval="${!prop}"
local val="$bval"
if [ "$bval" = "" ]; then
$cmd > /dev/stderr
val=$(get_input "$msg (default '$def'): " "$timeout")
if [ "$val" = "" ]; then
val="$def"
fi
fi
echo "$val" >/dev/stdout
}
insert_prop(){
prop=$1
val=$2
file=$3
if grep -qs -e "^[[:blank:]]*$prop[[:blank:]]*=[[:blank:]]*" "$file"; then
sed -i.bak "s/\(^[[:blank:]]*$prop[[:blank:]]*=[[:blank:]]*\).*/\1$val/" "$file" &&
msg_out "Successfully inserted '$prop=$val' in $file" ||
err_out "Failed to insert '$prop=$val' in $file"
else
cat >> "$file" <<< "$prop=$val" &&
msg_out "Successfully inserted '$prop=$val' in $file" ||
err_out "Failed to insert '$prop=$val' in $file"
fi
}
rename_mv(){
mv -f "$1" "$2" &&
msg_out "Renamed $1 --> $2" ||
err_out "Failed to rename $1 -- > $2"
}
update_mirrorlist(){
n=$(get_prop_input MIRRORS $DEF_MIRRORS 'Enter no. of mirrors to include')
rename_mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bkp
reflector --verbose --latest "$n" --sort rate --save /etc/pacman.d/mirrorlist
}
select_shell(){
if [ "$LOGIN_SHELL" != '' ] && chkcmd "$LOGIN_SHELL"; then
echo "$LOGIN_SHELL"
return 0
fi
while IFS= read -r -d $'\n'; do
if [[ "${REPLY:0:1}" = / ]]; then
array+=("$REPLY")
fi
done < <(cat /etc/shells)
printf "\nChoose a shell to set as the login shell:\n" >>/dev/stderr
for((i=0;i<${#array[@]};i++));do
echo "$i. ${array[$i]}" >>/dev/stderr
done
arri=""
while [[ ! "$arri" =~ ^[0-9]+$ ]];do
read -r -p "Enter your choice: " arri >>/dev/stderr
done
echo "${array[arri]}"
}
confirm_disk(){
dev="$1"
mp=$2
msg_out "Giving more info for confirmation"
msg_out "'fdisk -l $dev' says: \n\n$(fdisk -l "$dev")"
msg_out "'blkid $dev' says: \n\n$(blkid "$dev")"
msg_out
msg_out "$dev is going to be mounted as $mp"
read -p "=== Please confirm (Y/n)?: " conf
if [ "$conf" = Y ] || [ "$conf" = y ]; then
msg_out "$dev confirmed as $mp..."
return 0
else
return 1
fi
}
select_disk(){
mp=$1
oIFS="$IFS"
IFS=$'\n'
diskl=($(fdisk -l 2>/dev/null |grep -i '^/dev/.*linux'))
IFS="$oIFS"
if [ "$mp" != '/' ]; then
last_option="Do not use a separate $mp"
diskl+=("$last_option")
fi
PS3="
=== Choose a device (#?): "
printf "\n=== Please choose a partition for $mp: \n" >/dev/stderr
echo >/dev/stderr
select dev in "${diskl[@]}"; do
if [ "$dev" != "$last_option" -o "$last_option" = '' ]; then
if [ "$dev" = "" ]; then
continue
fi
dev=$(echo "$dev" | sed -n 's#\(/dev/[^[:blank:]]*\).*#\1#p')
msg_out "you have chosen: $dev" >/dev/stderr
if confirm_disk "$dev" "$mp" >/dev/stderr; then
echo "$dev"
break
fi
else
if [ "$mp" != swap ]; then
msg_out "$mp will be inside root filesystem (/)." >/dev/stderr
else
msg_out "swap will not be used." >/dev/stderr
fi
break
fi
done
}
get_uuid(){
lsblk -no UUID "$1"
}
finish(){
mounted=$(mount |awk '{print $3}')
rm -f /mnt/usr/bin/jinarch /mnt/etc/jinarch.conf /mnt/jinarch /mnt/jinarch.conf &&
msg_out "Uninstalled $pname" ||
err_out "Failed to uninstall $pname"
for (( idx=${#mps[@]}-1 ; idx>=0 ; idx-- )) ; do
mp="${mps[idx]}"
mpt="/mnt$mp"
mpt="${mpt/%\//}"
if echo "$mounted" |grep -qF "$mpt"; then
if umount "$mpt" || umount -lf "$mpt" ; then
msg_out "unmount $mpt success"
else
err_out "Failed to unmount $mpt"
fi
fi
done
}
chkroot
trap finish SIGTERM EXIT SIGQUIT
if [ "$1" = '' ]; then
_star_s
msg_out Checking network connection
_star_e
chknet
_star_s
msg_out 'Updating the system clock'
_star_e
timedatectl set-ntp true &&
msg_out "Successfully ran 'timedatectl set-ntp true'" ||
err_out "Failed to update the system clock"
_star_s
msg_out Mounting partitions
msg_out "We do not create/delete/change/format partitions in any way."
msg_out 'Please prepare the paritions manually. You may use tools like'
msg_out 'parted, cfdisk etc...'
msg_out 'If you are in a virtual console, you can use Alt+Arrows to'
msg_out 'open up terminals to do additional tasks.'
_star_e
yn="$PARTITIONS_READY"
while true; do
if [ "$yn" = yes ]; then
break
fi
yn=$(get_yes_no "Are the partitions ready")
done
declare -A dev
fmps=()
for mp in "${mps[@]}"; do
dev[$mp]="${DEV[$mp]}"
if [ "$mp" = '/' ]; then
if [ "${dev[$mp]:0:1}" != / ]; then
dev[$mp]=$(select_disk $mp)
fi
if [ "${dev[$mp]}" != '' ]; then
fmps+=("$mp")
fi
elif [ "$mp" = swap ] && [ "${dev[$mp]}" != none ]; then
if [ "${dev[$mp]:0:1}" != / ]; then
dev[$mp]=$(select_disk $mp)
fi
if [ "${dev[$mp]}" != '' ]; then
fstabs="UUID=$(get_uuid "${dev[$mp]}") none swap defaults 0 0"
fi
elif [ "${dev[$mp]}" != none ]; then
if [ "${dev[$mp]:0:1}" != / ]; then
dev[$mp]=$(select_disk $mp)
fi
if [ "${dev[$mp]}" != '' ]; then
fmps+=("$mp")
fi
else
if [ "$mp" != swap ]; then
msg_out "$mp will be inside /"
else
msg_out "$mp is not being used"
fi
fi
done
for mp in "${fmps[@]}"; do
mpdir="/mnt$mp"
mkdir -p "$mpdir"
umount "$mpdir" 2>/dev/null || umount -lf "$mpdir" 2>/dev/null
mount "${dev[$mp]}" "$mpdir" &&
msg_out "Successfully mounted ${dev[$mp]} in $mpdir" ||
err_exit "Failed to mount ${dev[$mp]} in $mpdir"
done
_star_s
msg_out Selecting mirrors
msg_out 'We use the reflector tool from the repository to rank the mirrors.'
msg_out 'If you wish to do this yourself, you may halt this step and open'
msg_out 'another terminal (Alt+Arrows in virtual console) and use your own'
msg_out 'method (e.g using rankmirrors). Skip this step ((y/n):n) when done'
_star_e
yn=$(get_prop_yn USE_REFLECTOR "$DEF_USE_REFLECTOR" 'Update mirrors with reflector ranking')
if [ "$yn" = y ]; then
if ! chkcmd reflector; then
pacman -Sy reflector --noconfirm
fi
update_mirrorlist
else
msg_out 'Continuing without changing mirrorlist'
fi
_star_s
msg_out Installing the base packages
msg_out Copying files ...
_star_e
yn=$(get_prop_yn RSYNC_WITH_HOST $DEF_RSYNC_WITH_HOST 'rsync with host')
if [ "$yn" = y ]; then
rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/var/cache/pacman/pkg/*"} / /mnt
else
yn=$(get_yn "Install base using Internet (pacstrap)? (Y/n): ")
if [[ "$yn" = [Yy] ]]; then
pacstrap /mnt base
cp -L /etc/pacman.d/mirrorlist /mnt/etc/pacman.d/mirrorlist
fi
fi
_star_s
msg_out Generating /etc/fstab file
msg_out 'genfstab -U /mnt >> /mnt/etc/fstab'
_star_e
genfstab -U /mnt >> /mnt/etc/fstab
sed -i.bak -e '/^.*[[:blank:]][^[:blank:]][^[:blank:]]*[[:blank:]][[:blank:]]*swap[[:blank:]].*$/d' /mnt/etc/fstab
cat >> /mnt/etc/fstab <<< "$fstabs" &&
msg_out "Successfully generated fstab" ||
err_out "Failed to generate fstab"
cp jinarch jinarch.conf /mnt/ 2>/dev/null ||
cp /usr/bin/jinarch /etc/jinarch.conf /mnt/ 2>/dev/null
[ $? -eq 0 ] &&
msg_out "Copied $pname to /mnt" ||
err_exit "Failed to copy $pname to /mnt"
_star_s
msg_out 'Changing root to new system'
msg_out "arch-chroot /mnt"
_star_e
arch-chroot /mnt ./$pname --chroot &&
msg_out "Entered in chroot of the new system" ||
err_out "Failed to chroot into the new system"
fi
if [ "$1" = --chroot ]; then
yn=$(get_prop_yn INTEL_UCODE "$DEF_INTEL_UCODE" 'Do you wish to enable microcode update ('must' for Intel CPU)')
if [ "$yn" = y ]; then
pacman -Sy intel-ucode --noconfirm
else
msg_out 'Continuing without microcode update'
fi
_star_s chroot
msg_out "Installing grub"
_star_e
pacman -Sy grub --noconfirm
if [ "${DEV[grub]:0:1}" != '/' ]; then
gdev=$(get_input "Enter the device for installing grub: ")
else
gdev="${DEV[grub]}"
fi
msg_out "Installing grub in $gdev ..."
grub-install --target=i386-pc "$gdev"
if [ ! $? -eq 0 ]; then
err_out "Grub install failed"
yn=$(get_yn "Continue without grub (y/n)?: ")
if [ "$yn" != y ]; then
err_exit "Aborted on grub-install failure"
fi
fi
_star_s chroot
msg_out 'Configuring grub'
_star_e
grub-mkconfig -o /boot/grub/grub.cfg
_star_s chroot
msg_out 'Setting time zone'
msg_out 'ln -sf /usr/share/zoneinfo/Region/City /etc/localtime'
msg_out "hwclock --systohc' to generate /etc/adjtime"
_star_e
time_zone=$(get_prop_input TIME_ZONE "$DEF_TIME_ZONE" "Enter time zone")
ln -sf "/usr/share/zoneinfo/$time_zone" /etc/localtime
hwclock --systohc
_star_s chroot
msg_out 'Setting locale'
_star_e
lang=$(get_prop_input LOCALE_LANG "$DEF_LOCALE_LANG" 'Enter your locale language')
# uncomment $lang in /etc/locale.gen
locale_gen=/etc/locale.gen
sed -i.bak -e "s/^[[:blank:]]*#\([[:blank:]]*$lang[[:blank:]]*.*\)/\1/i" "$locale_gen" &&
msg_out "Enabled $lang in $locale_gen" ||
err_out "Failed to enable $lang in locale_gen"
insert_prop LANG "$lang" /etc/locale.conf
_star_s chroot
msg_out 'KeyMap settings'
_star_e
keymap_conf=/etc/vconsole.conf
keymap_prop=KEYMAP
KEYMAP=$(get_prop_input $keymap_prop "$DEF_KEYMAP" "Enter keymap" list_keymaps)
insert_prop $keymap_prop $KEYMAP "$keymap_conf"
_star_s chroot
msg_out 'Teypematic delay and rate'
msg_out 'The typematic delay indicates the amount of time'
msg_out '(typically in miliseconds) a key needs to be pressed and held'
msg_out 'in order for the repeating process to begin.'
msg_out 'After the repeating process has been triggered,'
msg_out 'the character will be repeated with a certain frequency'
msg_out '(usually given in Hz) specified by the typematic rate.'
msg_out 'These values can be changed using the kbdrate command'
_star_e
KBD_DELAY=$(get_prop_input KBD_DELAY "$DEF_KBD_DELAY" 'Enter typematic delay')
KBD_RATE=$(get_prop_input KBD_RATE "$DEF_KBD_RATE" 'Enter typematic rate')
kbdrate_service_s="[Unit]
Description=Keyboard repeat rate in tty.
[Service]
Type=oneshot
RemainAfterExit=yes
StandardInput=tty
StandardOutput=tty
ExecStart=/usr/bin/kbdrate -s -d $KBD_DELAY -r $KBD_RATE
[Install]
WantedBy=multi-user.target
"
kbdrate_service_f=/etc/systemd/system/kbdrate.service
cat > "$kbdrate_service_f" <<< "$kbdrate_service_s" &&
msg_out "Sucessfully created $kbdrate_service_f with content:
$kbdrate_service_s" ||
err_out "Failed to create $kbdrate_service_f"
systemctl enable kbdrate &&
msg_out "Successfully enabled kbdrate.service" ||
err_out "Failed to enable kbdrate.service"
_star_s chroot
msg_out 'Setting hostname'
_star_e
hf=/etc/hostname
hn=$(get_prop_input HOSTNAME "$DEF_HOSTNAME" 'Enter hostname')
cat > "$hf" <<< "$hn" &&
msg_out "Wrote $hn to $hf" ||
err_out "Failed to write $hn to $hf"
hostsf=/etc/hosts
hs="127.0.1.1 $hn.localdomain $hn"
cat >> "$hostsf" <<< "$hs" &&
msg_out "Appended '$hs' to $hostsf" ||
err_out "Failed to append '$hs' to $hostsf"
_star_s chroot
msg_out 'Checking network status in chroot'
_star_e
chknet
_star_s chroot
msg_out 'Setting the root password'
_star_e
passwd
_star_s chroot
msg_out 'Setting the default login shell'
_star_e
shell=$(select_shell)
chsh -s "$shell"
yn=$(get_prop_yn CREATE_USER $DEF_CREATE_USER "Create a standard user")
if [ "$yn" = y ]; then
_star_s chroot
msg_out 'Creating a standard user'
_star_e
user=$(get_prop_input USER "$DEF_USER" 'Enter a user name')
groupadd sudo &&
msg_out 'Created a group named sudo' ||
err_out 'Failed to create sudo group'
useradd -m -U -G sudo -s "$shell" "$user" &&
msg_out "Successfully created user $user" ||
err_out "Failed to create user $user"
passwd "$user"
sudoers=/etc/sudoers
sed -i.bak -e 's/^[[:blank:]]*#*[[:blank:]]*\(%sudo[[:blank:]][[:blank:]]*ALL=(ALL).*\)/\1/' "$sudoers" &&
msg_out "Enabled group sudo in $sudoers" ||
err_out "Failed to enable group sudo in $sudoers"
fi
_star_s chroot
msg_out 'We will leave the chroot in your hand so that you may make'
msg_out "additional changes. When you are done, run 'exit' to exit"
_star_e
exec $SHELL
fi
msg_out 'Done'