source: pkg/kev/main/parsix-installer/trunk/parsix-installer @ 5876

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