root/morphix/trunk/scripts-main/mkpersistenthome

Revision 2, 10.7 kB (checked in by nextime, 2 years ago)

Initial import, branching from morphix svn

  • Property svn:executable set to
Line 
1 #!/bin/bash
2 # mkpersistenthome - create KNOPPIX home directory image
3 # (C) Klaus Knopper Feb 2003
4 #
5 # $Id: mkpersistenthome 410 2004-04-12 00:06:03Z paul_c $
6 #
7
8 PATH="/bin:/sbin:/usr/bin:/usr/sbin"
9 export PATH
10
11 XDIALOG_HIGH_DIALOG_COMPAT=1
12 export XDIALOG_HIGH_DIALOG_COMPAT
13 #XDIALOG_FORCE_AUTOSIZE=1
14 #export XDIALOG_FORCE_AUTOSIZE
15
16 # Get root
17 [ "`id -u`" != "0" ] && exec sudo "$0" "$@"
18
19 TMP="/tmp/mkpersistenthome.tmp$$"
20
21 DIRECTORY=""
22
23 bailout(){
24 rm -f "$TMP" "$TMP.done" "$TMP.err"
25 [ -n "$DIRECTORY" ] && umount "$DIRECTORY" 2>/dev/null
26 exit 0
27 }
28
29 DIALOG="dialog"
30 [ -n "$DISPLAY" ] && [ -x /usr/bin/Xdialog ] && DIALOG="Xdialog"
31
32 trap bailout 1 2 3 15
33
34 # LANGUAGE etc.
35 [ -f /etc/sysconfig/knoppix ] && . /etc/sysconfig/knoppix
36 [ -z "$LANG" ] && export LANG
37 [ -z "$LANGUAGE" ] && export LANGUAGE
38 [ -z "$CHARSET" ] && export CHARSET
39
40 HOMEKB="$(du -sk $HOME 2>/dev/null | awk '{print $1}')"
41
42 # Language-dependent Messages
43 case "$LANGUAGE" in
44 de*|at*|ch*)
45 TITLE1="Permanentes KNOPPIX Heimverzeichnis anlegen"
46 MESSAGE1="Dieses Skript richtet ein permanentes Heimverzeichnis für den User \"knoppix\" auf Ihrer Festplatte oder einem Wechselmedium wie Memorystick, Compactflash oder ZIP-Medium ein. Hierdurch ist es möglich, Daten und persönliche Konfigurationen über einen Reboot hinaus zu speichern, sofern sie im persönlichen Heimverzeichnis des Benutzers abgelegt werden. Per Bootoption, z.B. \"home=/dev/sda1\" für die erste Partition einer SCSI-Festplatte oder eines USB-Memorystick, können Sie beim Systemstart das permanente Heimverzeichnis wieder aktivieren. Die Bootoption \"home=scan\" durchsucht automatisch alle Partitionen und erkannten Speichermedien nach einem persistenten KNOPPIX-Heimverzeichnis.
47
48 Möchten Sie das Heimverzeichnis des Benutzers \"knoppix\" permanent speichern?"
49 MESSAGE2="Bitte wählen Sie die Partition, auf der Sie das Heimverzeichnis (oder ein Image davon) anlegen möchten."
50 MESSAGE3="Möchten Sie die KOMPLETTE Partition verwenden und mit den Linux-Dateisystem formatieren?
51 NEIN=Image-Datei auf bestehendem Dateisystem anlegen."
52 E1="Persönliche Einstellungen (Desktop, Programme)"
53 E2="Netzwerk Einstellungen (LAN, Modem, ISDN, ASDL)"
54 E3="Grafik Subsystem Einstellungen (XF86Config)"
55 E4="Weitere systemweite Einstellungen (Drucker etc.)"
56 E5="Alle Desktop-Dateien (${DESKTOPKB}kB)"
57 SUCCESS="FERTIG!
58
59 Die KNOPPIX-Konfiguration wurde erfolgreich gespeichert. Ihre Konfigurationsdateien werden beim nächsten KNOPPIX-Bootvorgang in die Ramdisk restauriert, wenn Sie im Bootscreen \"knoppix floppyconfig\" (Diskette) bzw. \"knoppix myconfig=/mnt/verzeichnisname\" angeben."
60 ERROR="Leider konnte die KNOPPIX-Konfiguration NICHT gespeichert werden:"
61 ;;
62 *)
63 TITLE1="Create persistent KNOPPIX/Morphix home directory"
64 MESSAGE1="This script creates a persistent home directory for the \"morph\" account on your harddisk or on a changeable medium like memory stick, compact flash or zip media. Using this features makes it possible to store personal data and config files permanently over a reboot, if they are stored inside the home directory of the \"morph\" user. The boot option \"home=/dev/sda1\", for the first partition of a SCSI harddisk or USB memory stick as example, activates the persistent home directory at system startup. You can also let Morphix scan all autodetected storage devices using the boot option \"home=scan\".
65
66 Do you want to create a persistent home directory for the \"morph\" user?"
67
68 MESSAGE2="Please select partition for creating persistent homedir (or image):"
69 MESSAGE3="Do you want to use the ENTIRE Partition, and would like to format it with the Linux filesystem?
70 NO=Just create an image in the existing filesystem."
71 E1="Personal configuration (desktop, programs)"
72 E2="Network settings (LAN, Modem, ISDN, ADSL)"
73 E3="Graphics subsystem settings (XF86Config)"
74 E4="Other system configuration (printer etc.)"
75 E5="All files on the Desktop (${DESKTOPKB}kB)"
76 SUCCESS="SUCCESS!
77
78 Creation of KNOPPIX/Morphix configuration floppy was successful. Your configuration files will be reinstalled to the ramdisk on next Morphix boot if you specify \"morphix floppyconf\" (floppy disk), or \"morphix myconfig=/mnt/directoryname\" at the boot prompt."
79 ERROR="The Morphix configuration could NOT be saved:"
80 ;;
81 esac
82
83 $DIALOG --cr-wrap --clear --title "$TITLE1" --yesno "$MESSAGE1" 18 75 || bailout
84
85 # Partition selector
86 PARTITIONS=""
87 count=0
88 for i in `awk '/^\/dev\/[hs]d[a-z].*\/mnt\/[hs]d[a-z]/{if(!/ntfs/){print $1}}' /etc/fstab`; do
89 PARTITIONS="$PARTITIONS ${i} [Disk/Partition] off"
90 done
91
92 DIRECTORY=""
93 PARTITION=""
94 while [ -z "$PARTITION" -o -z "$DIRECTORY" -o ! -e "$DIRECTORY" ]; do
95 rm -f "$TMP"
96 $DIALOG --cr-wrap --clear --title "$TITLE1" --radiolist "$MESSAGE2" 18 75 9 $PARTITIONS 2>"$TMP" || bailout
97 PARTITION="$(<$TMP)"
98 DIRECTORY="/mnt/${PARTITION##/dev/}"
99 done
100
101 DEVICE=""
102 if $DIALOG --cr-wrap --clear --title "$TITLE1" --defaultno "$MESSAGE3" 15 75; then
103 DEVICE="$PARTITION"
104 else
105 DEVICE="$DIRECTORY/morphix.img"
106 mount | grep -q "$DIRECTORY" || mount -r "$DIRECTORY" 2>"$TMP.err"
107 [ "$?" != "0" ] && { $DIALOG --cr-wrap --title "$TITLE1" --msgbox "$ERROR `cat $TMP.err`" 10 75; bailout; }
108 mount | grep -q "$DIRECTORY.*ntfs" && { $DIALOG --cr-wrap --title "$TITLE1" --msgbox "$ERROR NTFS" 10 75; bailout; }
109 mount -o remount,rw "$DIRECTORY"
110 fi
111
112
113 # More language-dependent Messages
114 case "$LANGUAGE" in
115 de*|at*|ch*)
116 MESSAGE4="Sind Sie ABSOLUT SICHER, dass Sie die Partition $PARTITION formatieren möchten? ALLE DATEN WERDEN DADURCH GELÖSCHT!"
117 MESSAGE5="Möchten Sie Ihr Heimverzeichnis mit AES256 (=Advanced Encryption Standard 256bit, s.a. http://csrc.nist.gov/encryption/aes/) verschlüsselt speichern? Hierzu ist die Eingabe eines sehr langen Passwortes beim Einrichten sowie beim Einbinden des Verzeichnisses beim Systemstart erforderlich. NEIN=unverschlüsselt"
118 MESSAGE6="Bitte geben Sie die gewünschte Größe Ihres persistenten Heimverzeichnisses in MB an (aktuell belegt: $HOMEKB Kilobyte, verfügbar:"
119 MESSAGE7="Formatiere $DEVICE mit dem ext2 Dateisystem und kopiere Daten..."
120 SUCCESS="$DEVICE wurde erfolgreich mit dem Linux ext2 Dateisystem formatiert, und Ihre Heimverzeichnis-Daten wurden darauf transferiert.
121
122 Sie können jetzt Ihren Computer neu starten, und beim KNOPPIX boot:-Prompt durch Eingabe von \"knoppix home=$PARTITION\" oder \"knoppix home=scan\" Ihr permanentes Heimverzeichnis aktivieren. Falls Sie außerdem (mit dem saveconfig Skript) die Systemeinstellungen gesichert haben, können Sie diese Option mit der Angabe von \"myconf=$PARTITION\" oder \"myconf=scan\" kombinieren."
123 ;;
124 *)
125 MESSAGE4="Are you positively SURE that you want to format partition $PARTITION? ALL DATA WILL BE LOST!"
126 MESSAGE5="Do you want to save your home directory encrypted with AES256 (Advanced Encryption Standard, see http://csrc.nist.gov/encryption/aes/)? If yes, you will have to specify a very long password at homedir creation and boot time."
127 MESSAGE6="Please enter the desired size of your persistent homedir in MB (currently used: $HOMEKB kB, available:"
128 MESSAGE7="Formatting $DEVICE with ext2 filesystem and copying data..."
129 SUCCESS="$DEVICE has been succeessfully formatted with the Linux ext2 filesystem, and your home directory has been transferred to it.
130
131 You may now reboot your computer and type \"morphix home=$PARTITION\" or \"morphix home=scan\" at the Morphix boot: prompt to take advantage of your new persistent home directory. If you have also saved the system configuration (using the saveconfig script), you can use this in combination with \"myconf=$PARTITION\" or \"myconf=scan\"."
132 ;;
133 esac
134
135 if [ "$DEVICE" = "$PARTITION" ]; then
136 $DIALOG --cr-wrap --clear --title "$TITLE1" --defaultno --yesno "$MESSAGE4" 6 75 || bailout
137 else
138 AMOUNT=0
139 AVAIL="$(df -m $DIRECTORY/. | awk '/^\/dev\//{print $4}')"
140 until [ "$AMOUNT" -ge 1 -a "$AMOUNT" -le "$AVAIL" ] 2>/dev/null; do
141 $DIALOG --cr-wrap --clear --title "$TITLE1" --inputbox "$MESSAGE6 $AVAIL MB)" 10 62 "30" 2>"$TMP" || bailout
142 AMOUNT="$(<$TMP)"
143 done
144 dd if=/dev/urandom of="$DEVICE" bs=1M count="$AMOUNT" || { sleep 2; bailout; }
145 fi
146
147 ENCRYPTION=""
148 $DIALOG --cr-wrap --clear --title "$TITLE1" --defaultno --yesno "$MESSAGE5" 9 75 && ENCRYPTION="AES256"
149
150 gauge(){
151 rm -f "$TMP.done"
152 status=0
153 while [ ! -e "$TMP.done" ]; do echo "$status" ; status="`expr \( 100 - $status \) / 4 + $status`"; sleep 2; done | $DIALOG --title "$TITLE1" --gauge "$1" 8 75 0
154 }
155
156 # Stop status bar
157 killgauge(){
158 touch "$TMP.done" ; wait ; rm -f "$TMP.done"
159 }
160
161 findfreeloop(){
162 i=0
163 for i in 0 1 2 3 4 5 6 7; do
164 LOOP="/dev/loop$i"
165 losetup "$LOOP" >/dev/null 2>&1 || { echo "$LOOP"; return 0; }
166 done
167 return 1
168 }
169
170 getpassword(){
171 case "$LANGUAGE" in
172 de*|at*|ch*)
173 HEADER="AES256 Verschlüsselungs-Passwort (Minimum 20 Zeichen!)"
174 ENTER="Eingabe:"
175 AGAIN="Noch einmal, um sicherzugehen:"
176 ;;
177 *)
178 HEADER="AES256 encryption password (minimum 20 characters!)"
179 ENTER="Enter:"
180 AGAIN="Again, just to be sure:"
181 ;;
182 esac
183 PASS1=""
184 PASS2=""
185 until [ -n "$PASS1" -a "$PASS1" = "$PASS2" ]; do
186 rm -f "$TMP.pass"
187 if [ "$DIALOG" = "Xdialog" ]; then
188 Xdialog --title "$TITLE1" --password --password --2inputsbox "$HEADER" 15 60 "$ENTER" "" "$AGAIN" "" 2>"$TMP.pass" || bailout
189 PASSWORDS="$(<$TMP.pass)"
190 PASS1="${PASSWORDS%%/*}"
191 PASS2="${PASSWORDS##*/}"
192 else
193 dialog --title "$HEADER" --passwordbox "$ENTER" 8 65 "" 2>"$TMP.pass" || bailout
194 PASS1="$(<$TMP.pass)"
195 dialog --title "$HEADER" --passwordbox "$AGAIN" 8 65 "" 2>"$TMP.pass" || bailout
196 PASS2="$(<$TMP.pass)"
197 fi
198 done
199 rm -f "$TMP.pass"
200 echo "$PASS1" >&2
201 }
202
203 LOOPDEV="$(findfreeloop)"
204 FORMAT=""
205 if [ -n "$ENCRYPTION" -a -n "$LOOPDEV" ]; then
206 getpassword 2>"$TMP"
207 PASSWORD="$(<$TMP)"
208 rm -f "$TMP"
209 losetup -p0 -e "$ENCRYPTION" "$LOOPDEV" "$DEVICE" 2>"$TMP.err" <<EOT
210 $PASSWORD
211 EOT
212 if [ "$?" != "0" ]; then
213 $DIALOG --cr-wrap --title "$TITLE1" --msgbox "$ERROR `cat $TMP.err`" 10 75
214 bailout
215 fi
216 # Start progress display
217 gauge "$MESSAGE7" &
218 mke2fs -m0 "$LOOPDEV" 2>"$TMP.err" || { killgauge; $DIALOG --cr-wrap --title "$TITLE1" --msgbox "$ERROR `cat $TMP.err`" 10 75; bailout; }
219 mkdir -p /tmp/knxhome
220 mount -t ext2 "$LOOPDEV" /tmp/knxhome 2>"$TMP.err" && rsync -Ha "$HOME/" /tmp/knxhome 2>"$TMP.err" || { killgauge; $DIALOG --cr-wrap --title "$TITLE1" --msgbox "$ERROR `cat $TMP.err`" 10 75; bailout; }
221 umount -l /tmp/knxhome
222 losetup -d "$LOOPDEV"
223 umount "$DIRECTORY" 2>/dev/null
224 killgauge
225 else
226 # Normal loopback file or partition
227 gauge "$MESSAGE7" &
228 # Just to make sure...
229 umount "$DEVICE" 2>/dev/null
230 mke2fs -F -m0 "$DEVICE" 2>"$TMP.err" || { killgauge; $DIALOG --cr-wrap --title "$TITLE1" --msgbox "$ERROR `cat $TMP.err`" 10 75; bailout; }
231 LOOPOPT=""
232 [ -f "$DEVICE" ] && LOOPOPT="-o loop"
233 mkdir -p /tmp/knxhome
234 mount -t ext2 $LOOPOPT "$DEVICE" /tmp/knxhome 2>"$TMP.err" && rsync -Ha "$HOME/" /tmp/knxhome 2>"$TMP.err" || { killgauge; umount /tmp/knxhome 2>/dev/null; $DIALOG --cr-wrap --title "$TITLE1" --msgbox "$ERROR `cat $TMP.err`" 10 75; bailout; }
235 umount /tmp/knxhome
236 umount "$DIRECTORY" 2>/dev/null
237 killgauge
238 fi
239
240 $DIALOG --cr-wrap --title "$TITLE1" --msgbox "$SUCCESS" 17 65
241
242 bailout
Note: See TracBrowser for help on using the browser.