#!/bin/bash REMAINING_UNAFFECTED="/etc/fstab /etc/group /etc/passwd /etc/shadow /etc/gshadow /etc/hostname /etc/mailname /etc/exports /etc/ndiswrapper /etc/hosts /etc/ssh /etc/iftab /etc/resolv.conf /etc/dhcpc/resolv.conf /etc/ppp /etc/chatscripts /etc/samba /etc/gpm.conf /etc/network/interfaces /etc/network/wep.* /etc/wpa_supplicant.conf /usr/src/fglrx* /usr/src/ati-driver-installer* /usr/src/NVIDIA* /usr/src/linux-*tar.bz2 /home /root /srv /var" FORCED_DELETION="/etc/init.d /etc/rc?.d /etc/modprobe.d /etc/modules* /etc/modutils /etc/network/options /etc/X11/xkb /var/log /var/tmp /var/lib/alsa/asound.state /var/lib /var/run /var/lock /var/spool /var/cache/apt/*.bin /var/cache/apt-show-versions /var/cache/apt-build /var/cache/man /var/cache/debconf /var/cache/samba /var/cache/apache /var/cache/chrootkit /var/cache/locate /home/*/.kde/share/config/kmixctrlrc /home/*/.kde/share/config/kmixrc /root/.kde/share/config/kmixctrlrc /root/.kde/share/config/kmixrc" if ((UID)); then echo "You must be root tu run this script!" exit 1 fi if [ $# -ne 3 ]; then echo "Usage: $(basename "$0") {grub|lilo} Examples: $(basename "$0") /dev/hda1 grub /dev/hda to update the installation on /dev/hda1 and install Grub to MBR of /dev/hda $(basename "$0") /dev/hda1 grub /dev/hda1 to update the installation on /dev/hda1 and install Grub into the root-partition" exit 2 fi # load distro defaults [ -r /etc/default/distro ] && source /etc/default/distro [ "$FLL_MOUNTPOINT" ] || FLL_MOUNTPOINT="/KNOPPIX" [ "$FLL_LIVE_USER" ] || FLL_LIVE_USER="knoppix" # check for live system if [ ! "$FLL_DISTRO_MODE" == "live" ]; then echo "ERROR: $0 has to be executed from Live-CD" exit 3 fi # load installer backend modules SEARCHPATH="/usr/share/acritoxinstaller" if [ ! -e "$SEARCHPATH" ]; then echo "ERROR: acritoxinstaller modules could not be found... ($SEARCHPATH)" exit 4 fi for i in $(find $SEARCHPATH/modules/ -type f); do source $i done # handle arguments case $2 in grub|lilo) BOOTLOADER=$2;; *) echo "ERROR: only 'grub' or 'lilo' allowed as bootloader!"; exit 1;; esac [ ! -e $1 ] && echo "ERROR: $1 does not exist!" && exit 1 [ ! -e $3 ] && echo "ERROR: $3 does not exist!" && exit 1 ROOT_TARGET="$1" set_config bootloader $BOOTLOADER set_config bootloadertarget "$3" # clean exit function clean_exit() { cd / umount_all_affected /media/hdinstall umount_all_affected $ROOT_TARGET exit $1 } init_filesystems umount_all_affected $ROOT_TARGET umount_all_affected /media/hdinstall mkdir -p /media/hdinstall mount $ROOT_TARGET /media/hdinstall cd /media/hdinstall if [ ! -e "./etc/kanotix-version" ]; then echo "Error: No KANOTIX-Installation found on $ROOT_MP ($ROOT_DEV)" clean_exit 5 else echo "Updating $(cat "./etc/kanotix-version") to $(cat "/etc/kanotix-version")..." fi # create hdmap from fstab function grep_disk() { while IFS=: read dev rest do is_disk $dev && echo "$dev:$rest" done } set_config hd_map "$(while read disk; do unuuid $disk; done < <(awk '{print $1}' < ./etc/fstab) | paste -d\ - ./etc/fstab | awk '/^\/dev/{auto="auto"; if(/noauto/){auto="noauto"}; print $1 ":" $3 "::" auto}' | grep_disk)" check_partitions_for_install if ! grep -q ":1000:1000:" ./etc/passwd; then echo "Could not detect default user with id 1000. Update not possible!" clean_exit 6 fi INSTALL_USER="$(egrep ":1000:1000:" ./etc/passwd | cut -d: -f1)" set_config username "$INSTALL_USER" set_config hostname "$(cat ./etc/hostname)" # mount partitions needed for update-install while IFS=: read device mountpoint filesystem automount do if [ "$automount" = "noauto" ]; then echo "not mounting $device... (it has the 'noauto'-option)" continue fi case "$mountpoint" in /bin|/boot|/dev|/etc|/lib|/sbin|/usr|/root|/home|/var) umount -l "$device" mount "$device" ".$mountpoint" 2>/dev/null echo "mounted $device to /media/hdinstall$mountpoint" ;; *) echo "not mounting $device... (not neccessary for update-install)" ;; esac done < <(get_config hd_map) # add mountpoints to remaining list REMAINING_UNAFFECTED="$REMAINING_UNAFFECTED $(cut -d\ -f2 /proc/mounts | grep "^/media/hdinstall/")" # ask the user if he really wants to proceed with the update-installation echo " You should better have a backup, this routine hasn't been tested yet... IF YOU REALLY WANT TO CONTINUE ENTER 'Yes' now. (case-sensitive) Do you want to continue? " read REALLY if [ "$REALLY" != "Yes" ]; then echo "You didn't enter 'Yes' (case-sensitive), so we exit here." clean_exit 7 else echo "OK, now there's no way back ;-)" fi # prepare the installation prepare_partitions_for_install --nomount #################### Update Groups and Users in ./etc/groups, ./etc/passwd and ./etc/shadow #################### DIFF_GROUPS="$( ( cut -d: -f1 ./etc/group; cut -d: -f1 /etc/group ) | sort | uniq -u | grep -v -e $FLL_LIVE_USER -e $INSTALL_USER)" for GROUP in $DIFF_GROUPS do GROUP_LINE="$(false)"; if GROUP_LINE="$(egrep "^$GROUP:" /etc/group)"; then echo "Adding group '$GROUP' to /etc/group..." echo "$GROUP_LINE" >> ./etc/group fi done DIFF_USERS="$( ( cut -d: -f1 ./etc/passwd; cut -d: -f1 /etc/passwd) | sort | uniq -u | grep -v -e $FLL_LIVE_USER -e $INSTALL_USER)" for USER in $DIFF_USERS do USER_LINE="$(false)"; if USER_LINE="$(egrep "^$USER:" /etc/passwd)"; then echo "Adding user '$USER' to /etc/passwd..." echo "$USER_LINE" >> ./etc/passwd if ! egrep -q "^$USER:" ./etc/shadow; then SHADOW_LINE="$(egrep "^$USER:" /etc/shadow)" if [ "$SHADOW_LINE" ]; then echo "Adding user '$USER' to /etc/shadow..." echo "$SHADOW_LINE" >> ./etc/shadow fi fi fi done DIFF_GROUPMEMBERS="$( ( grep $FLL_LIVE_USER /etc/group | cut -d: -f1; grep $INSTALL_USER ./etc/group | cut -d: -f1 ) | sort | uniq -u | grep -v -e $FLL_LIVE_USER -e $INSTALL_USER )" for GROUP in $DIFF_GROUPMEMBERS do IS_MEMBER="$(false)"; if IS_MEMBER="$(egrep "^$GROUP:" ./etc/group | grep -v $INSTALL_USER)"; then echo "Adding '$INSTALL_USER' to group '$GROUP'..." if egrep -q "^$GROUP.*:$" ./etc/group; then sed -i "s/^$GROUP.*$/\0$INSTALL_USER/g" ./etc/group else sed -i "s/^$GROUP.*$/\0,$INSTALL_USER/g" ./etc/group fi fi done USERS=$(cut -d: -f4 /etc/group | tr ',' '\n' | sort | uniq | sed '/^$/d' | grep -v -e $FLL_LIVE_USER -e $INSTALL_USER) for USER in $USERS do DIFF_GROUPMEMBERS="$( ( grep $USER /etc/group | cut -d: -f1; grep $USER ./etc/group | cut -d: -f1 ) | sort | uniq -u )" for GROUP in $DIFF_GROUPMEMBERS do IS_MEMBER="$(false)"; if IS_MEMBER="$(egrep "^$GROUP:" ./etc/group | grep -v $USER)"; then echo "Adding '$USER' to group '$GROUP'..." if egrep -q "^$GROUP.*:$" ./etc/group; then sed -i "s/^$GROUP.*$/\0$USER/g" ./etc/group else sed -i "s/^$GROUP.*$/\0,$USER/g" ./etc/group fi fi done done #################### Delete the things that have to be deleted #################### for TO_DELETE in $FORCED_DELETION do rm -r ".$TO_DELETE" 2>/dev/null done #################### Search for the files to move #################### # Move the things to save into "$MOUNTPOINT/kanotix-update" DIRS="$(grep $PWD /proc/mounts | awk '{print $2}' | sort -r)" for DIR in $DIRS do MOUNTPOINT="${DIR/*$PWD}" if [ "$MOUNTPOINT" ]; then [ "$DIRS_ALREADY_SAVED" ] && DIRS_ALREADY_SAVED="$DIRS_ALREADY_SAVED|^$MOUNTPOINT" || DIRS_ALREADY_SAVED="^$MOUNTPOINT" for THING in $(echo "$REMAINING_UNAFFECTED" | grep ^$MOUNTPOINT) do [ -e "${DIR}/kanotix-update" ] || mkdir -p "${DIR}/kanotix-update" THING=".$THING" for THING_P in $THING do mp=${THING_P:1} if [ -d "${PWD}${mp}" ]; then mv ${PWD}${mp}/.* ${PWD}${mp}/* ${DIR}/kanotix-update 2>/dev/null elif [ -e "${PWD}${mp}" ] || ls "${PWD}${mp}" 2>/dev/null; then SUBDIR="$(dirname "${mp}")" [ -d "${DIR}/kanotix-update${SUBDIR/*$MOUNTPOINT}" ] || mkdir -p ${DIR}/kanotix-update${SUBDIR/*$MOUNTPOINT} mv ${PWD}${mp} ${DIR}/kanotix-update${SUBDIR/*$MOUNTPOINT} 2>/dev/null fi done done fi done # Move the things to save into "/kanotix-update" [ "$DIRS_ALREADY_SAVED" ] && THINGS_TO_SAVE=$(echo "$REMAINING_UNAFFECTED" | grep -v -E $DIRS_ALREADY_SAVED) || THINGS_TO_SAVE="$REMAINING_UNAFFECTED" for THING in $THINGS_TO_SAVE do [ -e "kanotix-update" ] || mkdir "kanotix-update" THING=".$THING" for THING_P in $THING do if [ -e $THING_P ] || ls "$THING_P" 2>/dev/null; then [ -d "$(dirname "./kanotix-update${THING_P:1}")" ] || mkdir -p "$(dirname "./kanotix-update${THING_P:1}")" mv $THING_P ./kanotix-update${THING_P:1} 2>/dev/null fi done done # Delete everything exept "kanotix-update"-Folders DIRS="$(grep $PWD /proc/mounts | awk '{print $2}' | sort -r)" for DIR in $DIRS do for FOLDER in $DIR/* do if [ "$(basename $FOLDER)" != "kanotix-update" ]; then if ! grep $PWD /proc/mounts | awk '{print $2}' | grep -q "$FOLDER"; then rm -rf $FOLDER fi fi done done echo "debugging enabled" set -x copy_system_to_target update_fstab_on_target copy_etc_to_target configure_target_update_files configure_target_keymap configure_target_kdm configure_target_purge_live_only_stuff configure_target_modules configure_target_services install_bootmanager_to_target set +x echo "debugging disabled" #################### Put the backup back #################### cd /media/hdinstall DIRS="$(grep $PWD /proc/mounts | awk '{print $2}' | sort -r)" ROOTDIR="$PWD" for DIR in $DIRS do MOUNTPOINT="${DIR/*$PWD}" if [ -d "$DIR/kanotix-update" ]; then cd $DIR/kanotix-update find . -type d -exec sh -c 'mv "{}" ".$(dirname "{}")"' \; 2>/dev/null find . ! -type d -exec mv '{}' '.{}' \; 2>/dev/null cd $ROOTDIR rm -rf $DIR/kanotix-update fi done cleanup echo "finished acriupdate... ;-)" exit 0