-
Notifications
You must be signed in to change notification settings - Fork 0
/
installerz-debian_20110428
executable file
·1005 lines (845 loc) · 30.1 KB
/
installerz-debian_20110428
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
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# installerz-debian-20110428
# Copyright 2011 fsmithred@gmail.com
# License: GPL-3
# This is free software with NO WARRANTY. Use at your own risk!
#
# DESCRIPTION
# This script is used for installing a live system to a hard drive. User
# input is via popup windows created by zenity. It should be run from
# a terminal; if it's started from a menu item or a panel launcher, it
# should be run in a persistent terminal, so that progress messages can
# be seen and for user input in a few places.
# SYNOPSIS
# User has option to exit and use custom excludes file.
# User selects installation options -
# create a root account, change username, select up to three
# partitions (/, /boot, /home), select filesystem type for each partition,
# choose whether to encrypt partitions or not, choose whether to write
# random data or zeros to partitions, option to skip installing bootloader.
# User can run partitioner inside the installer.
# Summary window asks to proceed with installation.
# Stuff happens with some interaction (passwords, username, edit /etc/sudoers)
#
# Stuff:
# Cleanup (in case of previous aborted run)
# Create encrypted volumes
# Write random data or zeros
# Mount partition(s) and create filesystem(s)
# Copy system with rsync
# Create swapfile
# Copy update-initramfs
# Set up fstab
# Set up crypttab
# Install bootloader
# Cleanup
# Change username and passwords, create root account, edit /etc/sudoers
# Disable sudo-mode for gksu if appropriate.
error_log="z-unlive-error_log.txt"
exec 2>"$error_log"
rsync_excludes="./exclude.list"
# function to exit the script if there are errors
check_exit () {
[[ $? -eq 0 ]] || { echo "
Exit due to error: $?
See $error_log for details.
" ; zenity --error --text="Exit due to error: $?
See $error_log for details." &
exit 1 ; }
}
# Check that user is root.
[[ $(id -u) -eq 0 ]] || { echo -e "\t You need to be root!\n" ; exit 1 ; }
# Check that rsync excludes file exists, or create one.
if ! [[ -f $rsync_excludes ]] ; then
zenity --question --ok-label=Continue --cancel-label=Exit \
--text="There is no rsync excludes file, or its name does not match what this script expects. You should let the script create one, or if you have a custom exlcudes file, and you know what you're doing, you can exit the script and edit the rsync_excludes variable at the top so that it matches the name and path of your custom file.
If you have any other drives or partitions mounted that you want to be copied, you'll need to edit the rsync commands to remove the -x."
if [[ $? = 0 ]] ; then
rsync_excludes="./exclude.list"
cat > "$rsync_excludes" <<EOF
- /dev/*
- /cdrom/*
- /media/*
- /target
- /swapfile
- /mnt/*
- /sys/*
- /proc/*
- /tmp/*
- /live
- /boot/grub/grub.cfg
- /boot/grub/menu.lst
- /boot/grub/device.map
- /etc/udev/rules.d/70-persistent-cd.rules
- /etc/udev/rules.d/70-persistent-net.rules
- /etc/fstab
- /etc/mtab
- /home/snapshot/
EOF
check_exit
else
exit 0
fi
fi
# Select installation options
opts=$(zenity --list --title="Installation Options" \
--text="Check the options you want for the installation" \
--checklist --column "Choose" --column "Num" --column "Option" \
--width=590 --height=400 \
FALSE 01 "Create a root account" \
FALSE 02 "Change user name" \
FALSE 03 "Disable autologin to desktop" \
FALSE 04 "Disable autologin to console" \
FALSE 05 "Create a separate /home partition" \
FALSE 06 "Create a separate /boot partition" \
FALSE 07 "Encrypt the root filesystem (separate /boot required)" \
FALSE 08 "Encrypt the /home partition (separate /home required)" \
FALSE 09 "Write random data to encrypted partitions (more secure)" \
FALSE 10 "Write zeroes to all partitions (to erase previous data)" \
FALSE 11 "Do not install bootloader. I'll handle it myself." \
FALSE 12 "Exit the installation now.")
echo "$opts"
if $(echo $opts | grep -q 01); then
make_root="yes"
fi
if $(echo $opts | grep -q 02); then
change_user="yes"
fi
if $(echo $opts | grep -q 03); then
disable_auto_desktop="yes"
fi
if $(echo $opts | grep -q 04); then
disable_auto_console="yes"
fi
if $(echo $opts | grep -q 05); then
sep_home="yes"
fi
if $(echo $opts | grep -q 06); then
sep_boot="yes"
fi
if $(echo $opts | grep -q 07); then
encrypt_os="yes"
fi
if $(echo $opts | grep -q 08); then
encrypt_home="yes"
fi
if $(echo $opts | grep -q 09); then
write_random="yes"
fi
if $(echo $opts | grep -q 10); then
write_zero="yes"
fi
if $(echo $opts | grep -q 11); then
bootloader="no"
else
bootloader="yes"
fi
if $(echo $opts | grep -q 12); then
exit 0
fi
if $(echo $opts | grep -q 09) && $(echo $opts | grep -q 10); then
echo "
Zeroing will be disabled in favor of random data write.
"
write_zero="no" ### Add zenity error window???
fi
echo "@@@ one @@@"
if [[ $encrypt_os = "yes" ]] || [[ $encrypt_home = "yes" ]]; then
# test for cryptsetup
# if ! $(type -p /sbin/cryptsetup) ; then # this way works in text installer
if ! [[ -f /sbin/cryptsetup ]] ; then
zenity --question --title=Error \
--ok-label="Proceed without encrypting partitions" \
--cancel-label=Exit --text="You need to install cryptsetup and run the command, 'sudo modprobe dm-mod' before you can use encryption."
if [[ $? = 0 ]] ; then
encrypt_os="no"
encrypt_home="no"
else
exit 1
fi
fi
# end test for cryptsetup
fi
# Partition a disk
zenity --question --title=Partitioning --ok-label=Yes --cancel-label=No \
--text="You need to have at least one partition ready for the installation, plus one for each separate partition that you chose.
Run GParted Partition Editor now?"
if [[ $? = 0 ]] ; then
gparted
fi
# # test to make sure there's a separate /boot partition
if [[ $sep_boot = "no" ]]; then
if [[ $encrypt_os = "yes" ]]; then
zenity --question --title=Error \
--ok-label="Proceed without encrypting partition" \
--cancel-label=Exit --text="You MUST have a separate, unencrypted /boot partition if you intend to boot an encrypted operating system. You can proceed without encrypting the root filesystem, or you can exit and start over."
if [[ $? = 0 ]] ; then
encrypt_os="no"
else
exit 1
fi
fi
fi
echo "@@@ two @@@"
# Find hard drives, and choose one for grub
choose_grub () {
grub_dev=$(find /dev -mindepth 1 -maxdepth 1 -name "*[sh]d[a-z]" \
| sort | awk '{print "FALSE\n" $0 }' \
| zenity --list --title=Bootloader --text="Choose a location to install the bootloader." \
--radiolist --multiple --column ' ' --column 'Hard Drives' --height=200)
if [[ -z $grub_dev ]] ; then
zenity --question --title=Error --ok-label="Yes, I'm sure." --cancel-label="Go back" \
--text="No bootloader will be installed. Are you sure you want this?"
if [[ $? != 0 ]] ; then
choose_grub
fi
elif ! [[ -b $grub_dev ]] ; then
zenity --question --title=Error --ok-label=Exit --cancel-label="Go back" \
--text="Something is wrong. Maybe you checked more than one box. You said you want to install the bootloader in $grub_dev"
if [[ $? = 0 ]] ; then
exit 1
else
choose_grub
fi
fi
}
if [[ $bootloader = "yes" ]]; then
choose_grub
fi
# Show the partition list in a menu, and choose one for /boot
choose_boot () {
boot_dev=$(find /dev -mindepth 1 -maxdepth 1 -name "*[sh]d[a-z][1-9]*" \
| sort | awk '{print "FALSE\n" $0 }' \
| zenity --list --title="/boot partition" --text="Select a partition for /boot." \
--radiolist --multiple --column ' ' --column 'Partitions' --height=380 --width=150)
echo "boot_dev is $boot_dev"
}
if [[ $sep_boot = "yes" ]]; then
choose_boot
fi
# Choose filesystem type for /boot
choose_fs_boot () {
if [[ -n $boot_dev ]]; then
fs_type_boot=$(zenity --list --title="/boot filesystem" --text="What type of filesystem would you like on $boot_dev?" \
--radiolist --column "Choose" --column "Format" --height=200\
FALSE "ext2" \
FALSE "ext3" \
FALSE "ext4")
fi
if [[ -z $fs_type_boot ]]; then
zenity --question --title=Error --ok-label="Go back" --cancel-label=Exit \
--text="You must choose a file system type for /boot"
if [[ $? = 0 ]]; then
choose_fs_boot
else
exit 1
fi
fi
}
if [[ -n $boot_dev ]]; then
choose_fs_boot
fi
echo "@@@ three @@@"
# Show the partition list in a menu, and choose one for the OS
choose_root () {
install_dev=$(find /dev -mindepth 1 -maxdepth 1 -name "*[sh]d[a-z][1-9]*" \
| sort | awk '{print "FALSE\n" $0 }' \
| zenity --list --title="Root Partition" --text="Choose a partition to use for the installation of the operating system." \
--radiolist --multiple --column ' ' --column 'Partitions' --height 380 --width 150)
if [[ -z $install_dev ]] ; then
zenity --question --title=Error --ok-label="Go back" --cancel-label="Exit" \
--text="Nothing was selected. You must select a partition for the installation. What would you like to do?"
if [[ $? = 0 ]] ; then
choose_root
else
exit 1
fi
elif ! [[ -b $install_dev ]] ; then
zenity --question --title=Error --ok-label="Go back" --cancel-label="Exit" \
--text=" Something is wrong. Maybe you checked
more than one box. You said you want to install
the system to $install_dev"
if [[ $? = 0 ]] ; then
choose_root
else
exit 1
fi
elif
[[ $install_dev = $boot_dev ]] ; then
zenity --info --title=Error --text="You chose the same partition for the operating system as the one for /boot. Try again."
choose_root
fi
}
choose_root
# Choose filesystem type for OS.
choose_fs_os () {
fs_type_os=$(zenity --list --title="Root Filesystem" --text="What type of filesystem would you like on $install_dev?" \
--radiolist --column "Choose" --column "Format" --height=200\
FALSE "ext2" \
FALSE "ext3" \
FALSE "ext4")
if [[ -z $fs_type_os ]]; then
zenity --question --ok-label="Go back" --cancel-label=Exit \
--text="You must choose a file system type
for the operating system"
if [[ $? = 0 ]]; then
choose_fs_os
else
exit 1
fi
fi
}
choose_fs_os
echo "@@@ four @@@"
# Show the partition list in a menu, and choose one for /home
choose_home () {
home_dev=$(find /dev -mindepth 1 -maxdepth 1 -name "*[sh]d[a-z][1-9]*" \
| sort | awk '{print "FALSE\n" $0 }' \
| zenity --list --title="/home partition" --text="Select a partition for /home" \
--radiolist --multiple --column ' ' --column 'Partitions' --height=380 --width=150)
if [[ -n $home_dev ]] ; then
if ! [[ -b $home_dev ]] ; then
zenity --question --ok-label="Go back" --cancel-label=Exit \
--text=" Something is wrong. Maybe you checked
more than one box. You said you want to install
the system to $home_dev"
if [[ $? = 0 ]] ; then
choose_home
else
exit 1
fi
elif
[[ $install_dev = $home_dev ]] ; then
zenity --info --title=Error --text="You chose the same partition for /home as the one for the operating system. If you don't want a separate /home partition, then click OK without selecting one."
choose_home
elif
[[ $boot_dev = $home_dev ]] ; then
zenity --info --title=Error --text="You chose the same partition for /home as the one for /boot. Try again."
choose_home
fi
fi
}
if [[ $sep_home = "yes" ]]; then
choose_home
fi
# Choose filesystem type for /home
choose_fs_home () {
if [[ -n $home_dev ]]; then
fs_type_home=$(zenity --list --title="/home filesystem" --text="What type of filesystem would you like on $home_dev?" \
--radiolist --column "Choose" --column "Format" --height=200\
FALSE "ext2" \
FALSE "ext3" \
FALSE "ext4")
fi
if [[ -z $fs_type_home ]]; then
zenity --question --title=Error --ok-label="Go back" --cancel-label=Exit \
--text="You must choose a file system type for /home"
if [[ $? = 0 ]]; then
choose_fs_home
else
exit 1
fi
fi
}
if [[ -n $home_dev ]]; then
choose_fs_home
fi
echo "@@@ five @@@"
# Show a summary of what will be done
if [[ $change_user = "yes" ]]; then
user_message="User name will be changed."
fi
if [[ $disable_auto_desktop = "yes" ]]; then
desktop_message="Autologin will be disabled for the desktop."
fi
if [[ $disable_auto_console = "yes" ]]; then
console_message="Autologin will be disabled for the console."
fi
if [[ -z $grub_dev ]] ; then
grub_dev_message="--> Bootloader will not be installed."
else
grub_dev_message="--> Bootloader will be installed in $grub_dev"
fi
if [[ $encrypt_os = yes ]] ; then
os_enc_message=", and will be encrypted."
fi
if [[ -z $home_dev ]] ; then
home_dev_message="--> /home will not be on a separate partition."
else
home_dev_message="--> /home will be installed on $home_dev and formatted as $fs_type_home"
fi
if [[ -n $home_dev ]] && [[ $encrypt_home = yes ]] ; then
home_enc_message=", and will be encrypted."
fi
if [[ -n $boot_dev ]] ; then
boot_dev_message="--> /boot will be installed on $boot_dev and formatted as $fs_type_boot."
fi
if [[ $encrypt_os = yes ]] || [[ $encrypt_home = yes ]] ; then
proceed_message="*** IF YOU PROCEED, YOU WILL NEED TO RESPOND TO SOME QUESTIONS IN THE TERMINAL. Be prepared to create passphrases for any encrypted partitions (several times each.) When you see the progress bar come up, you can take a break."
fi
zenity --question --title=Summary --ok-label="Proceed with the installation." --cancel-label="Exit" \
--text="Here is a summary of what will be done. This is your last chance to exit before any changes are made.
$grub_dev_message
--> Operating system will be installed on $install_dev and formatted as $fs_type_os$os_enc_message
$home_dev_message$home_enc_message
$boot_dev_message
$user_message
$desktop_message
$console_message
$proceed_message"
if [[ $? != 0 ]] ; then
exit 0
fi
# Actual installation begins here
# Unmount or close anything that might need unmounting or closing
cleanup () {
echo -e "\n Cleaning up...\n"
if $(df | grep -q /target/proc/) ; then
umount /target/proc/
fi
if $(df | grep -q /target/dev/) ; then
umount /target/dev/
fi
if $(df | grep -q /target/sys/) ; then
umount /target/sys/
fi
# grep gives an error if $boot_dev is null
if $(df | grep -q $boot_dev) ; then
umount $boot_dev
fi
if $(df | grep -q /target_home) ; then
umount -l /target_home/
fi
# grep gives an error if $home is null
if $(df | grep -q $home_dev) ; then
umount $home_dev
fi
if $(df | grep -q "\/dev\/mapper\/home-fs") ; then
umount /dev/mapper/home-fs
fi
if [[ -h /dev/mapper/home-fs ]] ; then
cryptsetup luksClose home-fs
fi
if $(df | grep -q /target) ; then
umount -l /target/
fi
if $(df | grep -q $install_dev) ; then
umount $install_dev
fi
if $(df | grep "\/dev\/mapper\/root-fs") ; then
umount /dev/mapper/root-fs
fi
if [[ -h /dev/mapper/root-fs ]] ; then
cryptsetup luksClose /dev/mapper/root-fs
fi
# These next ones might be unnecessary
if [[ -d /target ]] ; then
rm -rf /target
fi
if [[ -d /target_home ]] ; then
rm -rf /target_home
fi
if [[ -d /target_boot ]] ; then
rm -rf /target_boot
fi
}
cleanup
# Write random data to OS partition
if [[ $write_random = "yes" ]]; then
if [[ $encrypt_os = "yes" ]]; then
# # Redirect stderr so we can see the output of dd
echo "
Writing random data to $install_dev
"
exec 2>&1
dd if=/dev/urandom of="$install_dev"
# # Resume logging errors in file
exec 2>>"$error_log"
else
echo "
$install_dev is not to be encrypted; skipping random data write!!!
"
fi
fi
# Write random data to /home partition
if [[ $write_random = "yes" ]]; then
if [[ $encrypt_home = "yes" ]]; then
# # Redirect stderr so we can see the output of dd
echo "
Writing random data to $home_dev
"
exec 2>&1
dd if=/dev/zero of="$home_dev"
# # Resume logging errors in file
exec 2>>"$error_log"
else
echo "
$home_dev is not to be encrypted; skipping random data write!!!
"
fi
fi
# Write zeros to partitions
if [[ $write_zero = "yes" ]]; then
echo "
Writing zeros to erase old data on $install_dev
"
# # Redirect stderr so we can see the output of dd
exec 2>&1
dd if=/dev/urandom of="$install_dev"
if [[ $sep_home = "yes" ]]; then
echo "
Writing zeros to erase old data on $home_dev
"
dd if=/dev/zero of="$home_dev"
fi
if [[ $sep_boot = "yes" ]]; then
echo "
Writing zeros to erase old data on $boot_dev
"
dd if=/dev/zero of="$boot_dev"
fi
# # Resume logging errors in file
exec 2>>"$error_log"
fi
# make mount point, format, adjust reserve and mount
# install_dev must maintain the device name for cryptsetup
# install_part will be either device name or /dev/mapper name as needed.
echo -e "\n Creating filesystem on $install_dev...\n"
mkdir /target ; check_exit
if [[ $encrypt_os = yes ]] ; then
echo " You will need to create a passphrase."
cryptsetup luksFormat "$install_dev" ; check_exit
echo "Encrypted partition created. Opening it..."
cryptsetup luksOpen "$install_dev" root-fs ; check_exit
install_part="/dev/mapper/root-fs"
else
install_part="$install_dev"
fi
mke2fs -t $fs_type_os "$install_part" ; check_exit
tune2fs -r 10000 "$install_part" ; check_exit
mount "$install_part" /target ; check_exit
# make mount point for separate home if needed
# and add /home/* to the excludes list if it's not already there
if [[ -n $home_dev ]] ; then
echo "
Creating filesystem on $home_dev...
"
mkdir /target_home ; check_exit
if [[ $encrypt_home = yes ]]; then
echo "
You will need to create a passphrase.
"
cryptsetup luksFormat "$home_dev"
check_exit
echo "Encrypted partition created. Opening it..."
cryptsetup luksOpen "$home_dev" home-fs
check_exit
home_part="/dev/mapper/home-fs"
else
home_part=$home_dev
fi
mke2fs -t $fs_type_home "$home_part" ; check_exit
tune2fs -r 10000 "$home_part" ; check_exit
mount "$home_part" /target_home ; check_exit
if ! $(grep -q "\/home\/\*" "$rsync_excludes"); then
echo "- /home/*" >> "$rsync_excludes"
fi
fi
# make mount point for separate /boot if needed
# and add /boot/* to the excludes list if it's not already there
# allow default for reserved blocks (don't need tune2fs here)
if [[ -n $boot_dev ]] ; then
mkdir /target_boot ; check_exit
mke2fs -t $fs_type_boot $boot_dev ; check_exit
mount $boot_dev /target_boot
if ! $(grep -q "\/boot\/\*" "$rsync_excludes"); then
echo "- /boot/*" >> "$rsync_excludes"
fi
fi
# make sure there's not a leftover entry in excludes list for /home/*
# or /boot/* from a previous run if not needed this time.
if [[ -z $boot_dev ]] ; then
sed -i 's:- /boot/\*::' "$rsync_excludes"
fi
if [[ -z $home_dev ]] ; then
sed -i 's:- /home/\*::' "$rsync_excludes"
fi
# copy everything over except the things listed in the exclude list
echo -e "\n Copying system to new partition.\n Wait...\n"
rsync -a -x --progress / /target/ --exclude-from="$rsync_excludes" | \
tee >(zenity --progress --pulsate --auto-close \
--text="Copying system to new partition.")
check_exit
# copy separate /home if needed
echo -e "\n Copying home folders to new partition.\n Wait...\n"
if ! [[ -z $home_dev ]] ; then
rsync -a -x --progress /home/ /target_home/ --exclude=/home/snapshot | \
tee >(zenity --progress --pulsate --auto-close \
--text="Copying home folders to new partition.")
check_exit
fi
# copy separate /boot if needed
if [[ -n $boot_dev ]] ; then
echo -e "\n Copying files to boot partitions...\n"
rsync -a -x --progress /boot/ /target_boot/ ; check_exit | \
tee >(zenity --progress --pulsate --auto-close \
--text="Copying files to boot partition.")
check_exit
fi
echo "five"
# create swap
echo -e "\n Making a swap file.\n Wait...\n"
dd if=/dev/zero of=/target/swapfile bs=1048 count=256000 | \
tee >(zenity --progress --pulsate --auto-close \
--text="Making a swap file...")
check_exit
mkswap /target/swapfile ; check_exit
# copy the real update-initramfs back in place
echo -e "\n Copying update-initramfs...\n"
if [[ -f /target/usr/sbin/update-initramfs.distrib ]] ; then
cp /target/usr/sbin/update-initramfs.distrib /target/usr/sbin/update-initramfs
fi
if [[ -f /target/usr/sbin/update-initramfs.debian ]] ; then
cp /target/usr/sbin/update-initramfs.debian /target/usr/sbin/update-initramfs
fi
echo "six"
# setup fstab
echo -e "\n Creating /etc/fstab...\n"
echo -e "proc\t\t/proc\tproc\tdefaults\t0\t0
/swapfile\tswap\tswap\tdefaults\t0\t0
$install_part\t/\t$fs_type_os\tdefaults,noatime\t0\t1" >> /target/etc/fstab
check_exit
# add entry for /home to fstab if needed
if ! [[ -z $home_dev ]] ; then
echo -e "\n Adding /home entry to fstab...\n"
echo -e "$home_part\t/home\t$fs_type_home\tdefaults,noatime\t0\t2" >> /target/etc/fstab
check_exit
fi
# add entry for /boot to fstab if needed
if [[ -n $boot_dev ]] ; then
echo -e "\n Adding /boot entry to fstab...\n"
echo -e "$boot_dev\t/boot\t$fs_type_boot\tdefaults,noatime,\t0\t2" >> /target/etc/fstab
check_exit
fi
# Add entry for root filesystem to crypttab if needed
if [[ $encrypt_os = yes ]] ; then
echo -e "\n Adding $install_part entry to crypttab...\n"
echo -e "root-fs\t\t$install_dev\t\tnone\t\tluks" >> /target/etc/crypttab
fi
# Add entry for /home to crypttab if needed
if [[ $encrypt_home = yes ]] ; then
echo -e "\n Adding $home_part entry to crypttab...\n"
echo -e "home-fs\t\t$home_dev\t\tnone\t\tluks" >> /target/etc/crypttab
fi
echo "eight"
# mount stuff so grub will behave
echo -e "\n Mounting tmpfs and proc...\n"
mount -t tmpfs --bind /dev/ /target/dev/ ; check_exit
mount -t proc --bind /proc/ /target/proc/ ; check_exit
mount -t sysfs --bind /sys/ /target/sys/ ; check_exit
# Setup GRUB
# If /boot is separate partition, need to mount it in chroot for grub
if [[ -n $boot_dev ]] ; then
chroot /target mount $boot_dev /boot
fi
if [[ -n $grub_dev ]]; then
echo -e "\n Installing the boot loader...\n"
chroot /target grub-install $grub_dev ; check_exit
fi
echo "nine"
# Run update-initramfs to include dm-mod if using encryption
if [[ $encrypt_os = yes ]] || [[ $encrypt_home = yes ]] ; then
chroot /target update-initramfs -u
fi
if [[ -n $grub_dev ]]; then
chroot /target update-grub ; check_exit
fi
echo "@ten@"
# BEGIN SPLICE FROM mkunlive.sh
replace_inittab () {
# make a backup copy of /etc/inittab if one doesn't exist
if ! [[ -f /target/etc/inittab.live ]]; then
echo " Backing up /etc/inittab"
cp /target/etc/inittab /target/etc/inittab.live
check_exit
else
echo "
inittab was already backed up as /target/etc/inittab.live
"
fi
# replace inittab if it wasn't already done
if $(grep -q inittabreplacement /etc/inittab) ; then
echo "
/etc/inittab was replaced previously. Leaving it alone.
"
else
echo " Replacing /etc/inittab to disable auto-login on tty.
"
echo "# /etc/inittab: init(8) configuration.
# inittabreplacement
# $Id: inittab,v 1.91 2002/01/25 13:35:21 miquels Exp $
# The default runlevel.
id:2:initdefault:
# Boot-time system configuration/initialization script.
# This is run first except when booting in emergency (-b) mode.
si::sysinit:/etc/init.d/rcS
# What to do in single-user mode.
~~:S:wait:/sbin/sulogin
# /etc/init.d executes the S and K scripts upon change
# of runlevel.
#
# Runlevel 0 is halt.
# Runlevel 1 is single-user.
# Runlevels 2-5 are multi-user.
# Runlevel 6 is reboot.
l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6
# Normally not reached, but fallthrough in case of emergency.
z6:6:respawn:/sbin/sulogin
# What to do when CTRL-ALT-DEL is pressed.
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
# Action on special keypress (ALT-UpArrow).
#kb::kbrequest:/bin/echo \"Keyboard Request--edit /etc/inittab to let this work.\"
# What to do when the power fails/returns.
pf::powerwait:/etc/init.d/powerfail start
pn::powerfailnow:/etc/init.d/powerfail now
po::powerokwait:/etc/init.d/powerfail stop
# /sbin/getty invocations for the runlevels.
#
# The \"id\" field MUST be the same as the last
# characters of the device (after \"tty\").
#
# Format:
# <id>:<runlevels>:<action>:<process>
#
# Note that on most Debian systems tty7 is used by the X Window System,
# so if you want to add more getty's go ahead but skip tty7 if you run X.
#
#1:2345:respawn:/bin/login -f user </dev/tty1 >/dev/tty1 2>&1
#2:23:respawn:/bin/login -f user </dev/tty2 >/dev/tty2 2>&1
#3:23:respawn:/bin/login -f user </dev/tty3 >/dev/tty3 2>&1
#4:23:respawn:/bin/login -f user </dev/tty4 >/dev/tty4 2>&1
#5:23:respawn:/bin/login -f user </dev/tty5 >/dev/tty5 2>&1
#6:23:respawn:/bin/login -f user </dev/tty6 >/dev/tty6 2>&1
#
1:2345:respawn:/sbin/getty 38400 tty1
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3
4:23:respawn:/sbin/getty 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
6:23:respawn:/sbin/getty 38400 tty6
# Example how to put a getty on a serial line (for a terminal)
#
#T0:23:respawn:/bin/login -f user </dev/tty >/dev/tty 2>&1
#T1:23:respawn:/bin/login -f user </dev/tty >/dev/tty 2>&1
# Example how to put a getty on a modem line.
#
#T3:23:respawn:/bin/login -f user </dev/tty >/dev/tty 2>&1
" > /target/etc/inittab
check_exit
fi
}
# Disable autologin for console by replacing /etc/inittab
# REFRACTA: comment out 'replace_inittab' below.
if [[ $disable_auto_console = "yes" ]]; then
replace_inittab
fi
echo "@@@ eleven @@@"
# Disable autologin for gdm or gdm3
if [[ $disable_auto_desktop = "yes" ]]; then
if [[ -f /target/etc/gdm/gdm.conf ]]; then
sed -i 's/AutomaticLogin/#AutomaticLogin/' /target/etc/gdm/gdm.conf
fi
if [[ -f /target/etc/gdm3/daemon.conf ]]; then
sed -i 's/AutomaticLogin/#AutomaticLogin/' /target/etc/gdm3/daemon.conf
fi
fi
# Need to mount the target home partition under the target root partition
# so the commands can find it (for changing user configs gksu)
if [[ $sep_home = "yes" ]]; then
mount $home_part /target/home
fi
echo "@@@ twelve @@@"
# Change the username
if [[ $change_user = "yes" ]]; then
oldname=$(awk -F: '/1000:1000/ { print $1 }' /target/etc/passwd)
newname=$(zenity --entry --title="Change user name" --text="The primary user's current login name is $oldname.
Enter the new login name you want to use.")
echo "New user name is $newname"
chroot /target usermod -l $newname $oldname ; check_exit
chroot /target groupmod -n $newname $oldname ; check_exit
chroot /target usermod -d /home/$newname -m $newname ; check_exit
for i in $(grep -r "/home/$oldname" /target/home/$newname/.config | awk -F":" ' { print $1 }'); do
sed -i "s/\/home\/$oldname/\/home\/$newname/g" "$i" ; check_exit
done
fi
# Change user password
if [[ $change_user = "yes" ]]; then
zenity --question --title="Change user password" --ok-label=Yes --cancel-label=No \
--text="Would you like to change the user's password? The new user still has the old user's password. You'll need to go to the terminal again to do this."
if [[ $? = 0 ]]; then
exec 2>&1
echo "Change user passowrd"
chroot /target passwd "$newname"
# # Resume logging errors in file
exec 2>>"$error_log"
fi
fi
# Change user's real name in /etc/passwd (for Debian)
if [[ $change_user = "yes" ]]; then
if $(grep -q "Debian\ Live\ user" /target/etc/passwd); then
real_name=$(zenity --entry --title="Change user name" --text="Enter the user's real name.")
sed -i~ "s/Debian\ Live\ user/$real_name/" /target/etc/passwd
fi
fi
echo "@@@ thirteen @@@"
# Change/create root password
if [[ $make_root = "yes" ]]; then
zenity --question --title="Change/create root password" --ok-label=Yes --cancel-label=No \
--text="You should create a root password next. If you're not going to put your new user name in /etc/sudoers, you MUST create a root password, or you won't be able to do any administrative tasks.
You'll need to go to the terminal again...
Change root password? (I really shouldn't give you a choice here.)"
if [[ $? = 0 ]]; then
# # Redirect stderr from the error log to the screen,
# # so we can see the prompts from passwd
exec 2>&1
echo "Change root passowrd"
chroot /target passwd
# # Resume logging errors in file
exec 2>>"$error_log"
fi
fi
echo "@@@ fourteen @@@"
# Edit /etc/sudoers
zenity --question --title="Edit /etc/sudoers" --ok-label=Yes --cancel-label=No \
--text="You should edit /etc/sudoers. If there's no root password, then you MUST replace \"user\" with the new user name. A simple text-editor will open in the terminal if you do this now. When you're finished editing, hit ctrl-x to save changes and exit the editor.
If you created a root password, it's safe to comment out the last line.
Edit /etc/sudoers now?"
if [[ $? = 0 ]]; then
edit_sudoers="yes"
chroot /target visudo
fi
echo "@@@ fifteen @@@"
# Disable sudo-mode for gksu
if [[ $edit_sudoers = "yes" ]]; then
zenity --question --title="Disable sudo mode for gksu" --ok-label="Yes, I commented out the line." --cancel-label="No, I replaced \"user\" with the new username." \
--text="If you commented out the last line in /etc/sudoers in the last step, one more file will be changed for you so that gksu will work properly."
if [[ $? = 0 ]]; then
if [[ -n $newname ]]; then
sed -i~ '/sudo-mode/s/true/false/' /target/home/"$newname"/.gconf/apps/gksu/%gconf.xml
else
sed -i~ '/sudo-mode/s/true/false/' /target/home/user/.gconf/apps/gksu/%gconf.xml
fi
fi
fi
echo "@@@ sixteen @@@"
# call cleanup function
cleanup