source: pkg/main/parsix-installer/trunk/parsix-installer @ 722

Revision 722, 32.5 KB checked in by alanbach-guest, 6 years ago (diff)

Some p-i 0.80.0 fixes

Line 
1#!/bin/bash
2#
3# Installs Parsix to harddisk
4#
5# GPL
6#
7# Authors:
8#               Fabian Franz <knoppix-installer@fabian-franz.de>
9#               Joerg Schirottke <master@kanotix.de>
10#               Stefan Lippers-Hollmann <s.l-h@gmx.de>
11#               Alan Baghumian <alan@technotux.org>
12#               Andreas Loibl <andreas@andreas-loibl.de>
13#
14# Based on work by Christian Perle & Klaus Knopper
15#
16
17#
18# Constants
19#
20
21VERSION="0.80.0"
22CONFIG_FILE="$HOME/.knofig"
23LOG="$HOME/.knofig_log"
24
25TARGET_MNT_POINT="/media/hdinstall" # TR1 in old installer
26TARGET_MNT_NAME="hdinstall" # TR1 in old installer
27
28# make use of distro-defaults
29if [ -f /etc/defaults/distro ]; then
30        source /etc/defaults/distro
31
32        [ -n "$FLL_LIVE_USER" ] && DEFAULT_USER="$FLL_LIVE_USER" || DEFAULT_USER="parsix"
33        [ -n "$FLL_MEDIA_DIR" ] && DEFAULT_DIR="$FLL_MEDIA_DIR"  || DEFAULT_DIR="KNOPPIX"
34else
35        DEFAULT_USER="parsix"
36        DEFAULT_DIR="KNOPPIX"
37fi
38
39DEFAULT_NAME=$(getent passwd "$DEFAULT_USER" | cut -f5 -d: | cut -f1 -d,)
40
41# It's Parsix/Kanotix
42INSTALL_KANO="yes"
43
44
45[ -f /proc/cmdline ] || mount -t proc proc /proc 2>/dev/null
46
47MEM_SWAP_NEEDED=$((512*1000)) # need some lower so that people with 512 MB can use this option
48SWAP_MIN=$((128*1024))
49if grep -q unionfs /proc/mounts; then
50        ROOT_MIN_RAW=$(du -sm "/$DEFAULT_DIR" | awk '{print $1}')
51else
52        ROOT_MIN_RAW=$(df -m "/$DEFAULT_DIR" | tail -1 | awk '{print $3}')
53        grep -q squashfs /proc/mounts && ROOT_MIN_RAW=$(($ROOT_MIN_RAW*270/100)) #fix status bar for squashfs
54fi
55ROOT_MIN_CORR=$[ROOT_MIN_RAW*115/100] # + 15% Filesystem overhead
56ROOT_MIN=$(($ROOT_MIN_CORR*1024))
57
58# Localisation
59export TEXTDOMAINDIR="/usr/share/locale"
60export TEXTDOMAIN=parsix-installer
61
62#
63# Include needed Bash-Modules
64#
65
66SEARCHPATH="/usr/share/parsix-installer"
67[ -f ./modules/00-parsix-utils.bm ] && SEARCHPATH="."
68
69# workaround for buggy knoppix-installer-latest-web and self-made installations
70[ "$SEARCHPATH" = "." ] && chown -R root:root .
71
72for i in $(find $SEARCHPATH -name "*.bm"); do
73        source $i
74done
75
76#
77# Main program
78#
79
80clean_exit(){
81        [ -n "$TMPDIR" ] && rm -rf "$TMPDIR"
82        logit $"knoppix-installer terminated"
83        logit
84}
85
86trap clean_exit EXIT
87
88function logit
89{
90        TIME=$(date)
91        [ -n "$*" ] && echo $TIME: "$@" >> $LOG || echo >> $LOG
92}
93
94function exit_proc
95{
96        unset IFS
97        $DIALOG --backtitle "$BT" --title $"Save configuration?" --yesno $"Do you want to save your configuration?" 10 60
98        RC=$?
99        [ $RC -eq 0 ] && save_config $CONFIG_FILE # save of configuration
100        [ $RC -ne 255 ] && exit 0
101        RC=0
102}
103
104function setup_dialog_messages()
105{
106        MAX=5 # number of steps
107
108        BT=$"Parsix GNU/Linux Installation"" (v$VERSION)"
109        DT=$"Installation of Parsix GNU/Linux to harddisk (Step 0/$MAX)"
110        INIT_T=$"Parsix GNU/Linux installation"
111        T1=$INIT_T
112        ET=$"Installation failed"
113        ST=$"Installation successfull"
114        FATAL_DIALOG=$"Fatal dialog error"
115
116        N=1; # Step 1
117}
118
119setup_dialog "knoppix-installer" # FIXME! Check for Commandline-Params
120setup_dialog_messages
121
122#
123# Variables and Config File Management
124#
125
126function add_var
127{
128        case "$REGISTERED" in *$1*) return 1;; esac
129        REGISTERED="$REGISTERED $1"
130}
131
132function register_vars
133{
134        for i in $@; do
135                add_var "$i"
136        done
137}
138
139#
140# Syntax: base, comment, allowed, checkfunc, default
141#
142
143function register_var
144{
145        export $1"_COMMENT"="$2"
146        export $1"_ALLOWED"="$3"
147        export $1"_CHECKIT"="$4"
148        export $1"_DEFAULT"="$5"
149        [ -z "${!1}" -a -n "$5" ] && export $1="$5"
150}
151
152function update_status
153{
154        echo -e "XXX\n$*\nXXX"
155        logit "$*"
156}
157
158
159#
160# FIXME: This management sucks!
161#
162
163# Beware: The real modules are set by module_system_set_modules
164
165MODULES=(hd swap name user userpass rootpass host services boot system)
166NUM_MODULES=${#MODULES[@]}
167MODULES_AUTO="swap services"
168MODULES_NUMAUTO=$(echo $MODULES_AUTO | wc -w | tr -d ' ')
169MODULES_LOAD="hd swap services boot system"
170
171function create_config
172{
173        T1=$"Choose System Type"
174 
175        # Configure system as the _very_ first
176        # TODO: How to get back there ...
177
178        module_system 0 || return 1
179        if [ "$SYSTEM_MODULE" == "configured" ]; then
180                # Set MODULES / NUM_MODULES for the configured system type.
181                module_system_set_modules
182        fi
183 
184        NUM_REAL_MODULES=$[$NUM_MODULES-$MODULES_NUMAUTO]
185        T1=$"Creating Parsix GNU/Linux Configuration Step (0/$NUM_REAL_MODULES)"
186        N=1
187        I=0
188        DIR=0
189        while [ "$I" -lt "$NUM_MODULES" ]; do
190                "module_${MODULES[$I]}" $DIR
191                RC=$?
192                DIR=0
193                [ $RC -eq 1 ] && DIR=-1
194                [ $RC -eq 0 ] && DIR=1
195                I=$[$I+$DIR]
196                [ $I -lt 0 ] && return 1
197                stringinstring "${MODULES[$I]}" "$MODULES_AUTO" || N=$[$N+$DIR]
198        done
199        INSTALL_READY="yes"
200        register_vars "INSTALL_READY"
201        return 0
202}
203
204function check_param
205{
206        TEMP=$(eval echo \$$1"_ALLOWED")
207        if [ -n "$TEMP" ]; then
208                if ! stringinstring "$2|" "$TEMP|"; then
209                        DEFAULT_TEMP=$(eval echo \$$1"_DEFAULT")
210                        msgbox $"Error: Unknown value $2 for $1\nSetting to default value ($DEFAULT_TEMP)." 10 60
211                        export "$1"="$DEFAULT_TEMP"
212                        logit $"Error: Unknown value $2 for $1\nSetting to default value ($DEFAULT_TEMP)."
213                fi
214        fi
215
216        TEMP=$(eval echo \$$1"_CHECKIT")
217        if [ -n "$TEMP" ]; then
218                if ! $TEMP; then
219                        msgbox $"Error: Check failed for $1 ($2)\nThe configuration module will now be started." 10 60
220                        export "$1"=""
221                        logit $"Error: Check failed for $1 ($2)\nThe configuration module will now be started."
222
223                        RC=1
224                        while [ "$RC" -eq "1" ]; do
225                                ${TEMP/_check/} 1
226                                RC=$?
227                        done
228                fi
229        fi
230        return 0
231}
232
233function load_config
234{
235        T1=$"Loading Parsix GNU/Linux configuration"
236        if [ -z "$1" ]; then
237                wizard $"Here you can input a filename to load an existing configuration" --inputbox $"Input the configuration filename to be loaded" 10 60 "$CONFIG_USER"
238                [ $? -ne 0 ] && return 1
239                CONFIG_USER=$(cat $TMP)
240                if [ ! -r "$CONFIG_USER" ]; then
241                        msgbox $"File $CONFIG_USER could not be found. The loading of the configuration will be aborted." 10 60
242                        return 1
243                fi
244                set -- "$CONFIG_USER"
245        fi
246        logit "$T1 $1"
247        source $1
248
249        for i in $MODULES_LOAD; do
250                "module_${i}_defaults"
251        done
252 
253        for i in $REGISTERED; do
254                #echo "$i=${!i}"
255                #echo check_param "$i" "${!i}"
256                check_param "$i" "${!i}"
257        done
258}
259
260function save_config
261{
262        T1=$"Saving Parsix GNU/Linux configuration"
263        if [ -z "$1" ]; then
264                wizard $"Here you can input a filename to save the configuration" --inputbox $"Input a filename for the configuration" 10 60 "$CONFIG_USER"
265                [ $? -ne 0 ] && return 1
266                CONFIG_USER=$(cat $TMP)
267                [ -z "$CONFIG_USER" ] && return 1
268                if [ -r "$CONFIG_USER" ]; then
269                        wizard $"If you click yes, the file will be overwritten, otherwise this program will abort" --defaultno --yesno $"Do you really want to overwrite $CONFIG_USER?" 10 60
270                        [ $? -ne 0 ] && return 1
271                fi
272                set -- "$CONFIG_USER"
273        fi
274        logit "$T1 $1"
275        echo "REGISTERED='$REGISTERED'" > $1
276        for i in $REGISTERED; do
277                [ "${!i}" = "configured" ] && echo "" >> $1
278                TEMP=$(eval echo \$$i"_COMMENT")
279                [ -n "$TEMP" ] && echo "# $TEMP" >> $1
280                TEMP=$(eval echo \$$i"_ALLOWED")
281                [ -n "$TEMP" ] && echo "#" $"Possible are:" $TEMP >> $1
282                TEMP=$(eval echo \$$i"_CHECKIT")
283                [ -n "$TEMP" ] && echo "#" $"This value will be checked by function" $TEMP >> $1
284                TEMP=$(eval echo \$$i"_DEFAULT")
285                [ -n "$TEMP" ] && echo "#" $"Default value is:" $TEMP >> $1
286
287                echo "$i='${!i}'" >> $1
288        done
289}
290
291function show_install_options
292{
293        echo > $TMP
294        I=0
295        # System needs an extra sausage (german limerick ;-) )
296        module_system_showinfo >> $TMP
297
298        while [ "$I" -lt "$NUM_MODULES" ]; do
299                "module_${MODULES[$I]}_showinfo"
300                I=$[I+1]
301        done >> $TMP
302        echo "" >> $TMP
303        echo $"Several of this options can only be changed in the Configuration file $CONFIG_FILE." >> $TMP
304        echo $"The Installation will now be started. The author and parsix.org give no warranty against any damage caused by this program." >> $TMP
305        echo "" >> $TMP
306        echo $"Do you want to proceed with these parameters?" >> $TMP
307        DISP_TEXT=$(cat $TMP)
308        wizard $"Make sure you agree to all parameters, if so proceed with the installation." --yesno "$DISP_TEXT" 35 60
309}
310
311function old_installer
312{
313        if [ "$SYSTEM_TYPE" = "knoppix" ]; then
314                system_type_knoppix
315                return 0
316        fi
317       
318        system_type_beginner
319       
320        [ "$SYSTEM_TYPE" = "beginner" ] && return 0
321
322        update_status $"Building Udev and Hotplug subsystem..."
323
324        [ "$INSTALL_KANO" == "yes" ] && [ ! -e /etc/init.d/udev ] && cp -af $TEMPLATE_PATH/etc/hotplug/usb/usb-storage $TARGET_MNT_POINT/etc/hotplug/usb/
325
326        system_services
327
328        return 0
329}
330
331function do_install
332{
333        echo ""
334        INSTALL_LIST="module_hd_doaction module_swap_doaction update_fstab old_installer add_bootmanager :"
335        INSTALL_LIST_NUM=$[6-1]
336        N=0;
337        for i in $INSTALL_LIST; do
338                echo $[$N*100/$INSTALL_LIST_NUM]
339                "${i}"
340                [ $? -ne 0 ] && return 1
341                N=$[$N+1]
342        done
343        return 0
344}
345
346function start_install
347{
348        if [ -z "$INSTALL_READY" ]; then
349                create_config
350                [ $? -ne 0 ] && return 1
351        fi
352        T1=$"Parsix GNU/Linux installation"
353        if [ -z "$INSTALL_READY" ]; then
354                msgbox $"Error: No complete Configuration found" 10 60
355                return 1
356        fi
357        show_install_options
358        [ $? -ne 0 ] && return 1
359        touch $TMPDIR/errors
360        save_config $CONFIG_FILE
361        T1=$"Parsix GNU/Linux installation"
362        do_install | $DIALOG --backtitle "$BT" --title "$T1" --gauge $"Installing" 10 60
363        RC=$?
364        MODULE_ERROR=$(<$TMPDIR/errors)
365        if [ -n "$MODULE_ERROR" ]; then
366                msgbox "Error: $MODULE_ERROR" 10 60
367                return 1
368        fi
369        [ $RC -ne "0" ] && return 1
370
371        #
372        # FLOPPY DISK!
373        #
374
375        if [ "$BOOT_DISK" = "yes" ]; then
376                $DIALOG --backtitle "$BT" --title $"Creating floppy disk" --defaultno --yesno $"Please insert now an empty floppy disk into your floppydrive.\nWarning: All data on it will be lost. If you don't want to create a disk you can choose No." 0 0
377                if [ $? -eq 0 ]; then
378                        make_floppy
379                fi
380        fi
381
382        # /var/tmp workaround
383        chmod 777 $TARGET_MNT_POINT/var/tmp
384
385         for i in $HD_MAP; do
386                point=$(echo $i | cut -d":" -f2)
387                umount $TARGET_MNT_POINT$point
388        done
389                     
390        # Just to be sure :-)
391        #umount $TARGET_MNT_POINT/proc
392        umount $TARGET_MNT_POINT
393        # Success Message and end installer
394        #T1=$"Success!"
395        T1=$ST
396 
397        msgbox $"Parsix GNU/Linux was successfully installed to hard disk." 15 60
398        logit $"Parsix GNU/Linux was successfully installed to hard disk."
399
400        $DIALOG --backtitle "$T1" --title "$T1" --defaultno --yesno $"Would you like to reboot now?" 10 50
401        if [ $? -eq 0 ]; then
402                sudo reboot
403        fi
404
405        exit 0
406}
407
408function start_update
409{
410        ROOT_PARTS=$(find_root_partitions $HD_CHOICE)
411         
412        radiolist $"Here you must choose one of the available partitions\n to update an existing Parsix GNU/Linux installation." $"Choose the partition to update your existing Parsix GNU/Linux" $ROOT_PARTS
413        [ $? -eq 1 ] && return 1
414         
415        HD_UPDATE_CHOICE="$(cat $TMP)"
416
417        register_vars "HD_UPDATE_CHOICE"
418        T1=$"Parsix GNU/Linux installation"
419        BT=$"Parsix GNU/Linux update installation"
420        do_update | $DIALOG --backtitle "$BT" --title "$T1" --gauge $"Starting update installation tasks..." 10 60
421        RC=$?
422        [ $RC -ne "0" ] && return 1
423
424        #################### Finished ;-) ####################
425        msgbox $"Parsix GNU/Linux is now updated." 10 60
426        logit $"Parsix GNU/Linux is now updated."
427
428        $DIALOG --backtitle "$BT" --title "$T1" --defaultno --yesno $"Would you like to reboot now?" 10 50
429        if [ $? -eq 0 ]; then
430                sudo reboot
431        fi
432        exit 0
433}
434
435function menu_main
436{
437  T1=$"Parsix GNU/Linux installation"
438  BT=$"Installation Main Menu"
439  do_menu $"Thats the main menu\nChoose your wanted action" $"Choose an action" \
440  "create_config" $"Configure Installation" $"Create a new configuration" \
441  "start_install" $"Start installation" $"Start the installation" \
442  "start_update" $"Update installation" $"Update existing installation" \
443  "action-part-later" $"Partition" $"Partition the hard disk" \
444  "load_config" $"Load config" $"Load an existing configuration" \
445  "save_config" $"Save config" $"Save the configuration" \
446  "exit_proc" $"Quit" $"Quit the program"
447}
448
449function main()
450{
451logit $"parsix-installer started"
452msgbox $"This program installs Parsix GNU/Linux to hard disk or updates \nexisting Parsix GNU/Linux installations.\n\nNote that this program is still under development. Please report bugs to http://bugs.parsix.org" 12 60
453rebuildfstab -r
454while ! check_partition_ok;
455do
456  msgbox $"The installer detected that the installation requierements are not fullfilled yet.\
457\n\nPlease make sure that you have an free partition with at least $[ROOT_MIN/(1024*1024)] GB to install Parsix GNU/Linux on. \
458Also we need a swap partition with at least $[SWAP_MIN/1024] MB, if you don't have 512 MB Memory or more.\
459\n\nIn the following menu, you can start some tools to partition your harddrive.\
460\nIf you really really know what you are doing start with: IGNORE_CHECK=1 sudo parsix-installer to avoid the menu." 21 60
461  menu_part
462done
463logit $"Partition check succeeded"
464[ -f "$CONFIG_FILE" ] && load_config $CONFIG_FILE # auto load of configuration
465
466while true; do
467        menu_main
468done
469}
470
471#
472# UNTESTED-Please DO!
473# Added non-interactive mode, FF 29.09.2003
474#
475
476function ni-main
477{
478        logit $"parsix-installer started"
479 
480        rebuildfstab -r
481        logit $"Partition check succeeded"
482 
483        if [ ! -f "$CONFIG_FILE" ]; then
484                echo $"Config file $CONFIG_FILE could not be found. This is necessary for non-interactive mode."
485                return
486        fi
487        load_config $CONFIG_FILE # auto load of configuration
488 
489        touch $TMPDIR/errors
490        T1=$"Parsix GNU/Linux installation"
491        do_install | $DIALOG --backtitle "$BT" --title "$T1" --gauge $"Installing" 10 60
492        RC=$?
493        MODULE_ERROR=$(<$TMPDIR/errors)
494 
495        if [ -n "$MODULE_ERROR" ]; then
496                msgbox "Error: $MODULE_ERROR" 10 60
497                return 1
498        fi
499
500        for i in $HD_MAP; do
501                point=$(echo $i | cut -d":" -f2)
502                umount $TARGET_MNT_POINT$point
503        done
504                     
505        # Just to be sure :-)
506        #umount $TARGET_MNT_POINT/proc
507        umount $TARGET_MNT_POINT
508        # Success Message and end installer
509        logit $"Parsix GNU/Linux was successfully installed to hard disk."
510        exit 0
511}
512
513do_update()
514{
515
516EXCLUDE_LIST="/etc/fstab
517/etc/group
518/etc/passwd
519/etc/shadow
520/etc/gshadow
521/etc/hostname
522/etc/mailname
523/etc/exports
524/etc/ndiswrapper
525/etc/hosts
526/etc/ssh
527/etc/iftab
528/etc/resolv.conf
529/etc/dhcpc/resolv.conf
530/etc/ppp
531/etc/chatscripts
532/etc/samba
533/etc/gpm.conf
534/etc/network/interfaces
535/etc/network/wep.*
536/etc/wpa_supplicant.conf
537/etc/cups
538/usr/src
539/usr/src/fglrx*
540/usr/src/NVIDIA*
541/usr/src/linux-*tar.bz2
542/etc/X11/xorg.conf
543/home
544/root
545/srv
546/var"
547
548
549INCLUDE_LIST="/etc/init.d
550/etc/rc?.d
551/etc/modprobe.d
552/etc/modules*
553/etc/modutils
554/etc/network/options
555/var/log
556/var/tmp
557/var/lib/alsa/asound.state
558/var/lib
559/var/run
560/var/lock
561/var/spool
562/var/cache/apt/*.bin
563/var/cache/apt-show-versions
564/var/cache/apt-build
565/var/cache/man
566/var/cache/debconf
567/var/cache/samba
568/var/cache/apache
569/var/cache/chrootkit
570/var/cache/locate"
571
572MOUNTPOINTS_TO_OVERWRITE="/bin
573/dev
574/etc
575/lib
576/sbin
577/usr
578/boot
579/root
580/home
581/var"
582
583# override tool behaviour through distro-defaults
584[ -r /etc/default/distro ] && source /etc/default/distro
585[ "$FLL_MOUNTPOINT" ] || FLL_MOUNTPOINT="/KNOPPIX"
586[ "$FLL_LIVE_USER" ] || FLL_LIVE_USER="parsix"
587
588MEDIA_DIR="/media"
589
590ROOT_DEV="$HD_UPDATE_CHOICE"
591ROOT_MP="$MEDIA_DIR/$(basename "$HD_UPDATE_CHOICE")"
592
593#################### Remount Root-Partition r/w ####################
594if ! ( mount | egrep "^$ROOT_DEV" 2>/dev/null >/dev/null ); then
595mount "$ROOT_DEV" 2>/dev/null
596MOUNTED_BY_SCRIPT=1
597fi
598mount -o remount,rw "$ROOT_DEV" 2>/dev/null >/dev/null
599BACKDIR="$(pwd)"
600cd "$ROOT_MP"
601
602T1=$"Parsix GNU/Linux installation"
603BT=$"Parsix GNU/Linux update installation"
604#################### Check for Kanotix ####################
605if [ ! -e "./etc/parsix-version" ]; then
606    msgbox $"Error: No Parsix GNU/Linux Installation found on $ROOT_MP ($ROOT_DEV)" 10 60
607    cd "$BACKDIR"
608    [ $MOUNTED_BY_SCRIPT ] && umount "$ROOT_DEV"
609    return 1
610else
611    if [ ! -e "./etc/parsix-version" ]; then
612            update_status $"Updating Old Parsix GNU/Linux to $(cat "/etc/parsix-version")..."
613            echo 0
614    else
615            update_status $"Updating $(cat "./etc/parsix-version") to $(cat "/etc/parsix-version")..."
616            echo 0
617    fi         
618fi
619
620#################### First check if all MP's are unmounted ####################
621MP_LIST="$(cat "./etc/fstab" | egrep -v "^([\s]*[^/].*|)$" | awk '{print $1 ":" $2}' | egrep -v "^(/|[^/].*)$")"
622for i in $MP_LIST
623do
624    part=$(echo $i | cut -d":" -f1)
625    point=$(echo $i | cut -d":" -f2)
626    if grep -q "$(basename "$part")" /proc/partitions; then
627       if ( echo "$MOUNTPOINTS_TO_OVERWRITE" | egrep "^$point$" 2>/dev/null >/dev/null); then
628           if grep -q ^$part /proc/mounts; then
629                msgbox $ "Error: Partition $part ($point) is already mounted!" 10 60
630                cd "$BACKDIR"
631                [ $MOUNTED_BY_SCRIPT ] && umount "$ROOT_DEV"
632                return 1
633           fi
634       fi
635    fi
636done
637
638#################### Add Mountpoints to rescue list ####################
639MP_LIST="$(cat "./etc/fstab" | egrep -v "^([\s]*[^/].*|)$" | awk '{print $1 ":" $2}' | egrep -v "^(/|[^/].*)$")"
640for i in $MP_LIST
641do
642    part=$(echo $i | cut -d":" -f1)
643    point=$(echo $i | cut -d":" -f2)
644    if grep -q "$(basename "$part")" /proc/partitions; then
645       if ( echo "$MOUNTPOINTS_TO_OVERWRITE" | egrep "^$point$" 2>/dev/null >/dev/null); then
646           mkdir -p ".$point"
647           mount "$part" ".$point" 2> /dev/null
648           update_status $"Mounted $part to $ROOT_MP$point, content will be deleted (if path not in exclude list)"
649       else
650           EXCLUDE_LIST="$EXCLUDE_LIST
651$point"
652       fi
653       CONFIG_HDMAP="$CONFIG_HDMAP
654$part:$point"
655    fi
656done
657
658#################### Create a .knofig-File for the installer ####################
659ROOT_FSTYPE="$(egrep -v "^([\s]*[^/].*|)$" ./etc/fstab | awk '{if($2=="/"){print $3}}')"
660if ! grep -q "x:1000:1000:" ./etc/passwd; then
661    msgbox $"Could not detect default user with id 1000. Update not possible!" 10 60
662    return 1
663fi
664CONFIG_NAME="$(egrep "x:1000:1000:" ./etc/passwd | cut -d: -f5)"
665CONFIG_USER="$(egrep "x:1000:1000:" ./etc/passwd | cut -d: -f1)"
666CONFIG_HOST="$(cat ./etc/hostname)"
667CONFIG_HDMAP="$(echo "$CONFIG_HDMAP" | egrep  "^/dev/[hs]d..:/." | egrep -v "/dev/[hs]d..:$MEDIA_DIR/[hs]d..")"
668[ "$BOOT_LOADER" ] && CONFIG_BOOT_LOADER="$BOOT_LOADER" || CONFIG_BOOT_LOADER="grub"
669[ "$BOOT_WHERE" ] && CONFIG_BOOT_WHERE="$BOOT_WHERE" || CONFIG_BOOT_WHERE="mbr"
670
671cat <<END >$HOME/.knofig
672REGISTERED=' SYSTEM_MODULE SYSTEM_TYPE HD_MODULE HD_FORMAT HD_FSTYPE HD_CHOICE HD_MAP HD_IGNORECHECK SWAP_MODULE SWAP_AUTODETECT NAME_MODULE NAME_NAME USER_MODULE USER_NAME USERPASS_MODULE USERPASS_CRYPT ROOTPASS_MODULE ROOTPASS_CRYPT HOST_MODULE HOST_NAME SERVICES_MODULE SERVICES_START BOOT_MODULE BOOT_LOADER BOOT_DISK BOOT_WHERE INSTALL_READY'
673
674SYSTEM_MODULE='configured'
675# Determines if the system is a debian-derivate, a copy from CD or a nice mix of both
676# Possible are: knoppix|debian
677# Default value is: debian
678SYSTEM_TYPE='debian'
679
680HD_MODULE='configured'
681# Determines if the HD should be formatted. (mkfs.*)
682# Possible are: yes|no
683HD_FORMAT='no'
684# Sets the Filesystem type.
685# Possible are: ext3|ext2|reiserfs|reiser4|xfs|jfs
686HD_FSTYPE='$ROOT_FSTYPE'
687# Here the Kanotix-System will be installed
688# This value will be checked by function module_hd_check
689HD_CHOICE='$ROOT_DEV'
690# Here you can give additional mappings. (Experimental) You need to have the partitions formatted yourself and give the correct mappings like: "/dev/hda4:/boot /dev/hda5:/var /dev/hda6:/tmp"
691HD_MAP='$CONFIG_HDMAP'
692# If set to yes, the program will NOT check if there is enough space to install knoppix on the selected partition(s). Use at your own risk! Useful for example with HD_MAP if you only have a small root partition.
693# Possible are: yes|no
694HD_IGNORECHECK='yes'
695
696SWAP_MODULE='configured'
697# If set to yes, the swap partitions will be autodetected.
698# Possible are: yes|no
699# Default value is: yes
700SWAP_AUTODETECT='yes'
701
702NAME_MODULE='configured'
703NAME_NAME='$CONFIG_NAME'
704
705USER_MODULE='configured'
706USER_NAME='$CONFIG_USER'
707
708USERPASS_MODULE='configured'
709USERPASS_CRYPT='------------'
710
711ROOTPASS_MODULE='configured'
712ROOTPASS_CRYPT='------------'
713
714HOST_MODULE='configured'
715HOST_NAME='$CONFIG_HOST'
716
717SERVICES_MODULE='configured'
718# Possible services are for now: kdm cupsys smail ssh samba
719# Default value is: kdm cupsys
720SERVICES_START='gdm cupsys'
721
722BOOT_MODULE='configured'
723# Chooses the Boot-Loader
724# Possible are: lilo|grub
725# Default value is: grub
726BOOT_LOADER='$CONFIG_BOOT_LOADER'
727# If set to 'yes' a boot disk will be created!
728# Possible are: yes|no
729BOOT_DISK='no'
730# Where the Boot-Loader will be installed
731# Possible are: mbr|partition
732# Default value is: mbr
733BOOT_WHERE='$CONFIG_BOOT_WHERE'
734INSTALL_READY='yes'
735END
736
737$DIALOG --backtitle "$BT" --title "$T1" --defaultno --yesno $"The bootloader ($CONFIG_BOOT_LOADER) will be installed to the $CONFIG_BOOT_WHERE.\nThe Installer-Configuration has been written to $HOME/.knofig.\n\nThe next step in the Updating-Process is to delete everything on the Root-Partition \n($ROOT_MP) except some files. These files will be backed-up during the update \nprocess and will put back after the installation of the new Parsix GNU/Linux version. \nIf anything goes wrong here your data can be lost. We really recommend to backup \nyour data now.\n\nAre you sure that want to continue?" 0 0
738
739if [ ! $? -eq 0 ]; then
740        msgbox $"Update process aborted." 10 50
741        exit 0
742fi
743
744echo 20
745
746#################### Check knofig ####################
747if which kanotix-check-knofig >/dev/null; then
748    kanotix-check-knofig $HOME/.knofig
749    ERROR=$?
750    if [ $ERROR -ne 0 ]; then
751        $DIALOG --backtitle "$BT" --title $"Update Warning" --defaultno --yesno $"ERROR: parsix-check-knofig returned $ERROR as error code!\nDo you want to force the update?" 0 0
752        if [ ! $? -eq 0 ]; then
753                msgbox $"Update process aborted." 10 50
754                exit 0
755        fi
756    fi
757fi
758
759#################### Starting Timer ####################
760START_TIME=$(date +%s)
761TMP_TIME="$(mktemp -t timediff.XXXXXX)"
762
763#################################################################################################################
764CUR_PACKAGES=$(dpkg -l|awk '/^ii/{print $2}')
765NEW_KERNEL=$(uname -r)
766CUR_PACKAGES=$(echo $CUR_PACKAGES|tr ' ' '\n'|grep -v $NEW_KERNEL)
767OLD_PACKAGES=$(chroot . dpkg -l|awk '/^ii/{print $2}')
768cd ./boot
769for v in vmlinuz-*; do
770    KERNEL=$(echo $v|sed s/vmlinuz-//)
771    OLD_PACKAGES=$(echo $OLD_PACKAGES|tr ' ' '\n'|grep -v $KERNEL)
772done
773for PACKAGE in $CUR_PACKAGES
774do
775    OLD_PACKAGES=$(echo $OLD_PACKAGES|tr ' ' '\n'|grep -v -e "^$PACKAGE$")
776done
777cd ..
778echo $OLD_PACKAGES|tr ' ' '\n' > ./root/diffpackages-$(date +%Y%m%d-%H%M).txt
779#update_status $"Saved old and new package Diff-List in /root/diffpackages-$(date +%Y%m%d-%H%M).txt"
780
781#################### Update Groups and Users in ./etc/groups, ./etc/passwd and ./etc/shadow ####################
782
783DIFF_GROUPS="$( ( cut -d: -f1 ./etc/group; cut -d: -f1 /etc/group ) | sort | uniq -u | grep -v -e $FLL_LIVE_USER -e $CONFIG_USER)"
784
785for GROUP in $DIFF_GROUPS
786do
787        GROUP_LINE="$(false)";
788        if GROUP_LINE="$(egrep "^$GROUP:" /etc/group)"; then
789                #update_status $"Adding group '$GROUP' to /etc/group..."
790                echo "$GROUP_LINE" >> ./etc/group
791        fi
792done
793
794DIFF_USERS="$( ( cut -d: -f1 ./etc/passwd; cut -d: -f1 /etc/passwd) | sort | uniq -u | grep -v -e $FLL_LIVE_USER -e $CONFIG_USER)"
795
796for USER in $DIFF_USERS
797do
798        USER_LINE="$(false)";
799        if USER_LINE="$(egrep "^$USER:" /etc/passwd)"; then
800                #update_status $"Adding user '$USER' to /etc/passwd..."
801                echo "$USER_LINE" >> ./etc/passwd
802                if ! egrep -q "^$USER:" ./etc/shadow; then
803                  SHADOW_LINE="$(egrep "^$USER:" /etc/shadow)"
804                  if [ "$SHADOW_LINE" ]; then
805                    #update_status $"Adding user '$USER' to /etc/shadow..."
806                    echo "$SHADOW_LINE" >> ./etc/shadow
807                  fi
808                fi
809        fi
810done
811
812DIFF_GROUPMEMBERS="$( ( grep $FLL_LIVE_USER /etc/group | cut -d: -f1; grep $CONFIG_USER ./etc/group | cut -d: -f1 ) | sort | uniq -u | grep -v -e $FLL_LIVE_USER -e $CONFIG_USER )"
813
814for GROUP in $DIFF_GROUPMEMBERS
815do
816        IS_MEMBER="$(false)";
817        if IS_MEMBER="$(egrep "^$GROUP:" ./etc/group | grep -v $CONFIG_USER)"; then
818                #update_status $"Adding '$CONFIG_USER' to group '$GROUP'..."
819                if egrep -q "^$GROUP.*:$" ./etc/group; then
820                  sed -i "s/^$GROUP.*$/\0$CONFIG_USER/g" ./etc/group
821                else
822                  sed -i "s/^$GROUP.*$/\0,$CONFIG_USER/g" ./etc/group
823                fi
824        fi
825done
826
827USERS=$(cut -d: -f4 /etc/group | tr ',' '\n' | sort | uniq | sed '/^$/d' | grep -v -e $FLL_LIVE_USER -e $CONFIG_USER)
828for USER in $USERS
829do
830    DIFF_GROUPMEMBERS="$( ( grep $USER /etc/group | cut -d: -f1; grep $USER ./etc/group | cut -d: -f1 ) | sort | uniq -u )"
831   
832    for GROUP in $DIFF_GROUPMEMBERS
833    do
834            IS_MEMBER="$(false)";
835            if IS_MEMBER="$(egrep "^$GROUP:" ./etc/group | grep -v $USER)"; then
836                    #update_status $"Adding '$USER' to group '$GROUP'..."
837                    if egrep -q "^$GROUP.*:$" ./etc/group; then
838                        sed -i "s/^$GROUP.*$/\0$USER/g" ./etc/group
839                    else
840                        sed -i "s/^$GROUP.*$/\0,$USER/g" ./etc/group
841                    fi
842            fi
843    done
844done
845
846update_status $"Updated Groups and Users."
847echo 50
848sleep 3
849update_status $"Please wait a bit, the files are being deleted now..."
850echo 55
851
852#################### Delete the things that have to be deleted ####################
853
854for WITH in $INCLUDE_LIST
855do
856    rm -r ".$WITH" 2>/dev/null
857done
858
859echo 60
860
861#################### Search for the files to move ####################
862
863# Move the things to save into "$MOUNTPOINT/parsix-update"
864DIRS="$(grep $PWD /proc/mounts | awk '{print $2}' | sort -r)"
865for DIR in $DIRS
866do
867        MOUNTPOINT="${DIR/*$PWD}"
868        if [ "$MOUNTPOINT" ]; then
869                [ "$DIRS_ALREADY_SAVED" ] && DIRS_ALREADY_SAVED="$DIRS_ALREADY_SAVED|^$MOUNTPOINT" || DIRS_ALREADY_SAVED="^$MOUNTPOINT"
870                for THING in $(echo "$EXCLUDE_LIST" | grep ^$MOUNTPOINT)
871                do
872                        [ -e "${DIR}/parsix-update" ] || mkdir -p "${DIR}/parsix-update"
873                        THING=".$THING"
874                        for THING_P in $THING
875                        do
876                                mp=${THING_P:1}
877                                if [ -d "${PWD}${mp}" ]; then
878                                        mv ${PWD}${mp}/.* ${PWD}${mp}/* ${DIR}/parsix-update 2>/dev/null
879                                elif [ -e "${PWD}${mp}" ] || ls "${PWD}${mp}" 2>/dev/null; then
880                                        SUBDIR="$(dirname "${mp}")"
881                                        [ -d "${DIR}/parsix-update${SUBDIR/*$MOUNTPOINT}" ] || mkdir -p ${DIR}/parsix-update${SUBDIR/*$MOUNTPOINT}
882                                        mv ${PWD}${mp} ${DIR}/parsix-update${SUBDIR/*$MOUNTPOINT} 2>/dev/null
883                                fi
884                        done
885                done
886        fi
887done
888
889echo 70
890
891# Move the things to save into "/parsix-update"
892[ "$DIRS_ALREADY_SAVED" ] && THINGS_TO_SAVE=$(echo "$EXCLUDE_LIST" | grep -v -E $DIRS_ALREADY_SAVED) || THINGS_TO_SAVE="$EXCLUDE_LIST"
893for THING in $THINGS_TO_SAVE
894do
895        [ -e "parsix-update" ] || mkdir "parsix-update"
896        THING=".$THING"
897        for THING_P in $THING
898        do
899                if [ -e $THING_P ] || ls "$THING_P" 2>/dev/null; then
900                        [ -d "$(dirname "./parsix-update${THING_P:1}")" ] || mkdir -p "$(dirname "./parsix-update${THING_P:1}")"
901                        mv $THING_P ./parsix-update${THING_P:1} 2>/dev/null
902                fi
903        done
904done
905
906echo 85
907
908# Delete everything exept "parsix-update"-Folders
909DIRS="$(grep $PWD /proc/mounts | awk '{print $2}' | sort -r)"
910for DIR in $DIRS
911do
912        for FOLDER in $DIR/*
913        do
914                if [ "$(basename $FOLDER)" != "parsix-update" ]; then
915                        if ! grep $PWD /proc/mounts | awk '{print $2}' | grep -q "$FOLDER"; then
916                                rm -rf $FOLDER
917                        fi
918                fi
919        done
920done
921
922#################### Everything is deleted now. ####################
923update_status $"Everything is deleted, now starting the installation..."
924echo 100
925
926logit $"parsix-installer started"
927 
928rebuildfstab -r
929logit $"Partition check succeeded"
930 
931if [ ! -f "$CONFIG_FILE" ]; then
932        echo $"Config file $CONFIG_FILE could not be found. This is necessary for non-interactive mode."
933        return
934fi
935load_config $CONFIG_FILE # auto load of configuration
936 
937touch $TMPDIR/errors
938
939echo 0
940
941T1=$"Parsix GNU/Linux installation"
942do_install
943RC=$?
944MODULE_ERROR=$(<$TMPDIR/errors)
945 
946if [ -n "$MODULE_ERROR" ]; then
947        msgbox "Error: $MODULE_ERROR" 10 60
948        return 1
949fi
950for i in $HD_MAP; do
951        point=$(echo $i | cut -d":" -f2)
952        umount $TARGET_MNT_POINT$point
953done
954                     
955# Just to be sure :-)
956#umount $TARGET_MNT_POINT/proc
957umount $TARGET_MNT_POINT
958#################### Start the installer ####################
959
960if [ $? -ne 0 ]; then
961    msgbox $"Parsix-Installer failed.\nYour data should be saved at $ROOT_MP/parsix-update. If it isn't there... "
962    exit 0
963fi
964echo 0
965update_status $"Update installation has finished.\nRestoring backup and doing final tasks..."
966sleep 3
967echo 25
968
969#################### Put the backup back ####################
970if ! ( mount | egrep "^$ROOT_DEV" 2>/dev/null >/dev/null ); then
971    mount "$ROOT_DEV" 2>/dev/null
972    MOUNTED_BY_SCRIPT=1
973fi
974mount -o remount,rw "$ROOT_DEV" 2>/dev/null >/dev/null
975cd "$ROOT_MP"
976DIRS="$(grep $PWD /proc/mounts | awk '{print $2}' | sort -r)"
977ROOTDIR="$PWD"
978echo 35
979for DIR in $DIRS
980do
981        MOUNTPOINT="${DIR/*$PWD}"
982        if [ -d "$DIR/parsix-update" ]; then
983        cd $DIR/parsix-update
984        find . -type d -exec sh -c 'mv "{}" ".$(dirname "{}")"' \; 2>/dev/null
985        find . ! -type d -exec mv '{}' '.{}' \; 2>/dev/null
986        cd $ROOTDIR
987        rm -rf $DIR/parsix-update
988        fi
989done
990
991echo 70
992
993#################### Patch some things ####################
994if [ -x /etc/init.d/udev ]; then
995    rm -f "./etc/skel/Desktop"/Floppy
996
997    for HOME_DIR in ./home/*
998    do
999        rm -f "$HOME_DIR/Desktop"/[sh]d[a-z][1-9]
1000        rm -f "$HOME_DIR/Desktop"/[sh]d[a-z][1-9][0-9]
1001        rm -f "$HOME_DIR/Desktop"/CD-ROM\ \[cdrom\]
1002        rm -f "$HOME_DIR/Desktop"/CD-ROM\ \[cdrom[1-9]\]
1003        rm -f "$HOME_DIR/Desktop"/Floppy
1004        rm -rf "$HOME_DIR/Desktop"/Trash
1005
1006        USER_ID="$(egrep "^$(basename "$HOME_DIR"):" ./etc/passwd | cut -d: -f3)"     
1007    done
1008   
1009    # Patch automount of USB-devices
1010    TARGET_MNT_POINT="."
1011    export TARGET_MNT_POINT
1012    . /usr/share/parsix-installer/modules/install/01-fstab.bm
1013    USBDEVS=$(get_usb_devices)
1014    [ -n "$USBDEVS" ] && PERLREGEX="${USBDEVS// /|}" || PERLREGEX=".\*"
1015    perl -pi -e 'if (! m#^/dev/('$PERLREGEX')#) { s#^(/dev/[sh]d.*)noauto(.*)$#${1}auto${2}# }' $TARGET_MNT_POINT/etc/fstab
1016   
1017    FSTAB=./etc/fstab
1018
1019    # Being sure that devpts line exists
1020    COUNT=`grep -c devpts ./etc/fstab`
1021
1022    F=$(grep -v -e ^$ -e ^'#' -e proc -e usbfs -e sysfs -e tmpfs -e ^/mnt/app -e cdrom -e dvd -e floppy $FSTAB)
1023    {
1024    echo "# /etc/fstab: static file system information."
1025    echo "#"
1026    printf "%-15s %-15s %-7s %-15s %-7s %s\n" "# <file system>" "<mount point>" "<type>" "<options>" "<dump>" "<pass>"
1027    if [ $COUNT -ne 1 ]; then   
1028        printf "%-15s %-15s %-7s %-15s %-7s %s\n" "devpts" "/dev/pts" "devpts" "defaults" "0" "0"
1029    fi
1030    while read a b c d e f; do
1031    if [[ $b == /mnt/* && $b != /mnt/app/* ]] ; then
1032    b=${b/mnt/media}
1033    [ -d .$b ] || mkdir -p .$b
1034    fi
1035    [[ $c == swap ]] && d=sw
1036    printf "%-15s %-15s %-7s %-15s %-7s %s\n" $a $b $c $d $e $f
1037    done <<<"$F"
1038    for c in $(ls -d /dev/cdrom* 2>/dev/null); do
1039    m=${c#/dev}
1040    [ "$m" == "/cdrom" ] && m="/cdrom0"
1041    [ -d ./media$m ] || mkdir -p ./media$m
1042    printf "%-15s %-15s %-7s %-15s %-7s %s\n" "$c" "/media$m" "udf,iso9660" "user,noauto" "0" "0"
1043    done
1044    for f in $(ls -d /sys/block/fd* 2>/dev/null); do
1045    [ -d ./media/floppy${f#/sys/block/fd} ] || mkdir -p ./media/floppy${f#/sys/block/fd}
1046    printf "%-15s %-15s %-7s %-15s %-7s %s\n" "/dev${f#/sys/block}" "/media/floppy${f#/sys/block/fd}" "auto" "rw,user,noauto" "0" "0"
1047    done
1048    } > ./etc/fstab.new
1049    mv ./etc/fstab ./etc/fstab.old
1050    mv ./etc/fstab.new ./etc/fstab
1051       
1052    DEVLINE=`printf "%-15s %-15s %-7s %-15s %-7s %s\n" "devpts" "/dev/pts" "devpts" "defaults" "0" "0"`
1053
1054    if [ $COUNT -ne 1 ]; then
1055        perl -pi -e "s|^# <file (.*)|# <file \1\n$DEVLINE|g" ./etc/fstab
1056    fi
1057
1058    # Ensure that there is no proc and usbfs lines
1059    perl -pi -e "s|^proc(.*)||" ./etc/fstab
1060    perl -pi -e "s|^usbfs(.*)||" ./etc/fstab
1061    sed -ie '/^$/d' ./etc/fstab
1062fi
1063
1064echo 85
1065
1066# Patching /mnt to /media
1067FILES_TO_PATCH_MNT_MEDIA="./etc/exports
1068./etc/samba/smb.conf"
1069for FILE_TO_PATCH in $FILES_TO_PATCH_MNT_MEDIA
1070do
1071   if [ -e "$FILE_TO_PATCH" ]; then
1072      perl -pi -e 's|/mnt|/media|g' "$FILE_TO_PATCH"
1073   fi
1074done
1075
1076# Update GRUB menu.list for splash
1077export GROOT=$(cat ./boot/grub/menu.lst | awk {'print $2'} | awk '/Parsix/{getline;print}' | awk {'line = $0'}END{'print line'})
1078perl -pi -e "s|^color (.*)|color \1\nsplashimage=$GROOT/boot/grub/parsix-grub.xpm.gz|g" ./boot/grub/menu.lst
1079
1080# Backing up xorg.conf
1081cp ./etc/X11/xorg.conf ./etc/X11/xorg.conf.pi.backup
1082cp /etc/X11/XF86Config-4 ./etc/X11/xorg.conf
1083
1084$DIALOG --backtitle "$BT" --title $"X.Org Configuration Restore" --defaultno --yesno $"Would you like to restore your original xorg.conf file?\nThis will restore your graphical settings." 0 0
1085if [ $? -eq 0 ]; then
1086        mv ./etc/X11/xorg.conf.pi.backup ./etc/X11/xorg.conf
1087fi
1088
1089#cleaning unwanted link
1090if [ -x ./etc/rc5.d/S99xsession ]; then
1091        rm -f ./etc/rc5.d/S99xsession
1092fi
1093
1094cd "$BACKDIR"
1095[ $MOUNTED_BY_SCRIPT ] && umount "$ROOT_DEV" 2>/dev/null
1096
1097echo 100
1098
1099return 0
1100}
1101
1102function format_timediff()
1103{
1104        SEK_DIFF=$1
1105        OUTPUT="$[SEK_DIFF%60]s"
1106        if [ $SEK_DIFF -gt 60 ]; then
1107                MINUTES=$[SEK_DIFF/60]
1108                OUTPUT="$[MINUTES%60]m$OUTPUT"
1109                if [ $MINUTES -gt 60 ]; then
1110                        HOURS=$[MINUTES/60]
1111                        OUTPUT="${HOURS}h$OUTPUT"
1112                fi
1113        fi
1114        echo $OUTPUT
1115}
1116
1117function get_time()
1118{
1119        LAST_TIME=$(<$TMP_TIME)
1120        NOW_TIME=$(date +%s)
1121        ALL_DIFF=$[NOW_TIME-START_TIME]
1122        LAST_DIFF=$[NOW_TIME-LAST_TIME]
1123        LAST_TIME=$NOW_TIME
1124        echo $LAST_TIME > "$TMP_TIME"
1125        echo -n "(+$(format_timediff $LAST_DIFF)/($(format_timediff $ALL_DIFF)):"
1126}
1127
1128if [ "$1" = "--non-interactive" ]; then
1129        ni-main
1130        exit 1 # something did go wrong
1131fi
1132
1133if [ $UID -eq 0 ]; then
1134         main
1135else
1136        echo $"root permission needed."
1137fi
1138
Note: See TracBrowser for help on using the repository browser.