root/morphix/trunk/scripts-main/saveconfig

Revision 2, 8.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 # saveconfig - create KNOPPIX configuration floppy
3 # (C) Klaus Knopper Mar 2002
4 # Spanish translation by Luis Llorente, luis.llorente@hispalinux.es
5 #
6 # $Id: saveconfig 410 2004-04-12 00:06:03Z paul_c $
7 #
8
9 PATH="/bin:/sbin:/usr/bin:/usr/sbin"
10 export PATH
11
12 XDIALOG_HIGH_DIALOG_COMPAT=1
13 export XDIALOG_HIGH_DIALOG_COMPAT
14
15 # Get root
16 [ "`id -u`" != "0" ] && exec sudo "$0" "$@"
17
18 TMP="/tmp/saveconfig.tmp$$"
19
20 bailout(){
21 rm -f "$TMP" "$TMP.done" "$TMP.err"
22 umount "$DIRECTORY"
23 exit 0
24 }
25
26 DIALOG="dialog"
27 [ -n "$DISPLAY" ] && [ -x /usr/bin/Xdialog ] && DIALOG="Xdialog"
28
29 trap bailout 1 2 3 15
30
31 # LANGUAGE etc.
32 [ -f /etc/sysconfig/knoppix ] && . /etc/sysconfig/knoppix
33 [ -z "$LANG" ] && export LANG
34 [ -z "$LANGUAGE" ] && export LANGUAGE
35 [ -z "$CHARSET" ] && export CHARSET
36
37 DESKTOPKB="$(du -sk $HOME/Desktop 2>/dev/null | awk '{print $1}')"
38
39 # Language-dependent Messages
40 case "$LANGUAGE" in
41 de*|at*|ch*)
42 TITLE1="KNOPPIX Konfigurationsarchiv anlegen"
43 MESSAGE1="Konfigurationsdateien auswählen:"
44 MESSAGE2="Bitte legen Sie jetzt eine leere DOS- oder ext2-formatierte, schreibbare Diskette ein."
45 MESSAGE3="Archiviere geänderte Konfigurationsdateien..."
46 MESSAGE4="Bitte wählen Sie das Verzeichnis, in das Sie die Konfigurationsdateien schreiben wollen."
47 E1="Persönliche Einstellungen (Desktop, Programme)"
48 E2="Netzwerk Einstellungen (LAN, Modem, ISDN, ASDL)"
49 E3="Grafik Subsystem Einstellungen (XF86Config)"
50 E4="Weitere systemweite Einstellungen (Drucker etc.)"
51 E5="Alle Desktop-Dateien (${DESKTOPKB}kB)"
52 ERROR="Leider konnte die KNOPPIX-Konfiguration NICHT gespeichert werden:"
53 ;;
54 es*)
55 TITLE1="Crear un archive de configuración de KNOPPIX"
56 MESSAGE1="Elija el tipo de archivos de configuración:"
57 MESSAGE2="Por favor, inserte un disquete vacío escribible formateado para DOS o ext2."
58 MESSAGE3="Grabando archivos de la configuración..."
59 MESSAGE4="Por favor, seleccione el directorio para los archivos de la configuración del ahorro."
60 E1="Configuración personal (escritorio, programas)"
61 E2="Configuración de Red (LAN, Modem, RDSI, ADSL)"
62 E3="Configuración del subsistema gráfico (XF86Config)"
63 E4="Otras configuraciones del sistema (impresora, etc.)"
64 E5="Todos los archivos en el Escritorio (${DESKTOPKB}kB)"
65 ERROR="No se pudo crear de configuración de KNOPPIX:"
66 ;;
67 *)
68 TITLE1="Create KNOPPIX/Morphix configuration archive"
69 MESSAGE1="Chose type of configuration files:"
70 MESSAGE2="Please insert an empty DOS- or ext2-formatted, writable floppy disk."
71 MESSAGE3="Saving configuration archive..."
72 MESSAGE4="Please select directory for saving configuration files:"
73 E1="Personal configuration (desktop, programs)"
74 E2="Network settings (LAN, Modem, ISDN, ADSL)"
75 E3="Graphics subsystem settings (XF86Config)"
76 E4="Other system configuration (printer etc.)"
77 E5="All files on the Desktop (${DESKTOPKB}kB)"
78 ERROR="The Morphix configuration could NOT be saved:"
79 ;;
80 esac
81
82 $DIALOG --clear --title "$TITLE1" --checklist "$MESSAGE1" 18 75 9 p "$E1" on d "$E5" off n "$E2" on x "$E3" on o "$E4" on 2>"$TMP" || bailout
83
84 FILES=""
85 SAVEHOME=""
86 SAVEDESK=""
87 SAVEETC=""
88 SAVENET=""
89 SAVEX=""
90 CHOWNHOME=""
91 NETFILES='/etc/network|/etc/ppp|/etc/chat|/etc/isdn|/etc/sysconfig/isdn|/etc/sysconfig/provider|/etc/resolv\.conf|/etc/hosts|/etc/hosts\.|/etc/inetd\.conf'
92 XFILES='/etc/X11'
93 for i in `sed 's,",,g;s,/, ,g;' < "$TMP"`; do
94 case $i in
95 p) SAVEHOME="yes" ;;
96 d) SAVEDESK="yes" ;;
97 n|x|o) SAVEETC="yes"; case "$i" in n) SAVENET="yes";; x) SAVEX="yes";; esac ;;
98 esac
99 done
100
101 [ -n "$SAVEHOME" -o -n "$SAVEDESK" ] && CHOWNHOME="chown -R $(ls -ld $HOME | awk '{print $3"."$4}') $HOME"
102
103 # Find changes in (real) files of dir1 ... dir2
104 findchanged(){
105 if [ -d "$1" ]; then
106 for i in `( cd "$1"; find . -type f | sed 's,^\./,,g' | grep -v ' ' )`; do
107 cmp -s "$1/$i" "$2/$i" || echo "$1/$i"
108 done
109 elif [ -e "$1" ]; then
110 cmp -s "$1" "$2" || echo "$1"
111 fi
112 }
113
114 writescript(){
115 cat >"$1" <<EOT
116 #!/bin/sh
117 [ "\`id -u\`" = "0" ] || { echo "You need root privileges to modify the system!" >&2 ; exit 1; }
118 [ -d "\$1" ] && CONFIGS="\$1/configs.tgz"
119 [ -f "\$CONFIGS" ] || CONFIGS="/cdrom/MorphixCD/configs.tgz"
120 [ -f "\$CONFIGS" ] || CONFIGS="/mnt/floppy/configs.tgz"
121 if [ -f "\$CONFIGS" ]; then
122 echo "Extracting config archive \$CONFIGS..."
123 tar -zpPtf "\$CONFIGS" | while read i; do rm -f "\$i"; done
124 tar -zpPxf "\$CONFIGS" ; $CHOWNHOME
125 fi
126 EOT
127 return "$?"
128 }
129
130 FLOPPYDIR="$(ls -l /mnt/floppy | awk '{print $NF}')"
131
132 umountfloppy(){
133 mount | grep -q "$FLOPPYDIR" && umount "$FLOPPYDIR" 2>/dev/null
134 }
135
136 # Directory selector
137 PARTITIONS="/mnt/floppy [Floppy] on"
138 for i in `awk '/^\/dev\/[hs]d[a-z].*\/mnt\/[hs]d[a-z]/{if(!/ntfs/){print $2}}' /etc/fstab`; do
139 PARTITIONS="$PARTITIONS ${i} [Disk/Partition] off"
140 done
141
142
143 rm -f "$TMP"
144 $DIALOG --clear --title "$TITLE1" --radiolist "$MESSAGE4" 18 75 9 $PARTITIONS 2>"$TMP" || bailout
145
146 DIRECTORY="$(<$TMP)"
147 [ -z "$DIRECTORY" -o ! -e "$DIRECTORY" ] && bailout
148
149 case "$DIRECTORY" in *floppy*)
150 DIRECTORY="$FLOPPYDIR"
151 KNOPPIXSH="$DIRECTORY/morphix.sh"
152 while :; do
153 umountfloppy
154 $DIALOG --title "$TITLE1" --yesno "$MESSAGE2" 8 65 || bailout
155 echo "$FLOPPYDIR" | grep -q auto || mount /mnt/floppy
156 [ "$?" = "0" ] && writescript "$KNOPPIXSH" && break
157 done
158 ;;
159 *)
160 rm -f "$TMP.err"
161 mount | grep -q "$DIRECTORY" || mount -r "$DIRECTORY" >"$TMP.err"
162 [ "$?" != "0" ] && { $DIALOG --title "$TITLE1" --msgbox "$ERROR `cat $TMP.err`" 10 75; bailout; }
163 mount | grep -q "$DIRECTORY.*ntfs" && { $DIALOG --title "$TITLE1" --msgbox "$ERROR NTFS" 10 75; bailout; }
164 mount -o remount,rw "$DIRECTORY"
165 KNOPPIXSH="$DIRECTORY/morphix.sh"
166 writescript "$KNOPPIXSH"
167 esac
168
169 gpid=""
170
171 gauge(){
172 status=0
173 while [ ! -e "$TMP.done" ]; do echo "$status" ; status="`expr \( 100 - $status \) / 4 + $status`"; sleep 2; done | $DIALOG --title "$TITLE1" --gauge "$MESSAGE3" 8 65 0
174 }
175
176 # Start status bar
177 # if [ "$DIALOG" = "dialog" ]; then
178 gauge &
179 # else
180 ## Gauge doesn't work yet with gdialog
181 # $DIALOG --title "$TITLE1" --gauge "$MESSAGE3" 8 65 75 &
182 # gpid="$!"
183 # fi
184
185 rm -f "$TMP"
186 touch "$TMP"
187
188 [ -n "$SAVEHOME" ] && for i in $HOME/.??* $HOME/office $HOME/evolution; do findchanged "$i" /etc/skel/$(basename "$i"); done | egrep -v -e '(\.ICEauthority|ksycoka|\.xsession-errors|\.DCOP|\.MCOP|kio_http/cache|\.mozilla/.*/Cache/|favicons|office/user/work)' >"$TMP"
189 [ -n "$SAVEDESK" ] && for i in $HOME/Desktop; do findchanged "$i" /etc/skel/$(basename "$i"); done >>"$TMP"
190
191 IGNORE='/etc/ioctl.save|/etc/mtab'
192
193 if [ -n "$SAVEETC" -a -d /etc ]; then
194 findchanged /etc /etc >>"$TMP"
195 [ -n "$SAVENET" ] || IGNORE="$IGNORE|$NETFILES"
196 [ -n "$SAVEX" ] || IGNORE="$IGNORE|$XFILES"
197 fi
198
199 rm -f "$TMP.tmp"
200 egrep -v -e '('"$IGNORE"')' "$TMP" > "$TMP.tmp"
201 mv -f "$TMP.tmp" "$TMP"
202
203 SCRIPTS=""
204 STARTNET=""
205 STARTPCMCIA=""
206 STARTCUPS=""
207 REINIT=""
208
209 while read i; do
210 case "$i" in
211 /etc/network/interfaces) STARTNET="yes";;
212 /etc/pcmcia/*) STARTPCMCIA="yes";;
213 /etc/cups*) STARTCUPS="yes";;
214 /etc/inittab) REINIT="yes";;
215 esac
216 done <"$TMP"
217
218
219 [ -n "$STARTNET" ]    && { echo "killall pump 2>/dev/null && sleep 2 && killall -9 pump 2>/dev/null && sleep 2" >>"$KNOPPIXSH" ; SCRIPTS="$SCRIPTS ifupdown networking"; }
220 [ -n "$STARTPCMCIA" ] && echo 'echo "(Re)starting PCMCIA services."; killall cardmgr 2>/dev/null && sleep 4; cardmgr && sleep 4' >>"$KNOPPIXSH"
221 [ -n "$STARTCUPS" ]   && SCRIPTS="$SCRIPTS cupsys"
222
223 if [ -n "$SCRIPTS" ]; then
224 echo 'echo "Starting daemons..."' >>"$KNOPPIXSH"
225 echo "for i in $SCRIPTS; do [ -x /etc/init.d/\$i ] && /etc/init.d/\$i start; done" >>"$KNOPPIXSH"
226 fi
227
228 [ -n "$REINIT" ] && echo 'echo "Reloading INIT." ; init q' >> "$KNOPPIXSH"
229
230 rm -f "$TMP.err"
231 BZIP2=-9 tar -T - -cpPzf "$DIRECTORY/configs.tgz" <"$TMP" 2>"$TMP.err"
232
233 RC="$?"
234
235 if [ "$DIRECTORY" = "$FLOPPYDIR" ]; then
236 umountfloppy
237 else
238 umount "$DIRECTORY"
239 fi
240
241 # More language-dependent Messages
242 case "$LANGUAGE" in
243 de*|at*|ch*)
244 SUCCESS="Die KNOPPIX-Konfiguration wurde erfolgreich gespeichert. Ihre Konfigurationsdateien werden beim nächsten KNOPPIX-Bootvorgang in die Ramdisk restauriert, wenn Sie im Bootscreen \"knoppix myconfig=$DIRECTORY\" bzw. \"knoppix myconfig=scan\" (automatische Suche) angeben."
245 ;;
246 es*)
247 SUCCESS="La creación del configuración de KNOPPIX fue satisfactoria. Sus archivos de configuración serán reinstalados en el siguiente arranque de KNOPPIX si especifica \"knoppix myconfig=$DIRECTORY\" o \"knoppix myconfig=scan\" (automatic) en la línea de comandos del arranque."
248 ;;
249 *)
250 SUCCESS="Creation of the KNOPPIX/Morphix configuration archive was successful. Your configuration files will be reinstalled to the ramdisk on next Morphix boot if you specify \"morphix myconfig=$DIRECTORY\", or \"morphix myconfig=scan\" (automatic search) at the boot prompt."
251 ;;
252 esac
253
254
255 # Stop status bar
256 # [ "$DIALOG" = "dialog" ] && { touch "$TMP.done" ; wait ; rm -f "$TMP.done" ; } || { [ -n "$gpid" ] && kill "$gpid" 2>/dev/null; sleep 1; }
257 touch "$TMP.done" ; wait ; rm -f "$TMP.done"
258
259 [ "$RC" = "0" ] && $DIALOG --title "$TITLE1" --msgbox "$SUCCESS" 12 65 || $DIALOG --title "$TITLE1" --msgbox "$ERROR `cat $TMP.err`" 10 75
260
261 bailout
Note: See TracBrowser for help on using the browser.