X-Git-Url: http://git.grml.org/?p=grml-autoconfig.git;a=blobdiff_plain;f=bin%2Fsave-config;h=63e41c77cdfe5a6288b64058d49ccbba82ce2fa3;hp=e2f985457cf2c959d81c44fdae0b6946b33e6161;hb=4c0e0818e388ef9791e79614267a5684fb7dc8b4;hpb=044d67ae243554c35bf3832f51bbac4570b04e77 diff --git a/bin/save-config b/bin/save-config index e2f9854..63e41c7 100755 --- a/bin/save-config +++ b/bin/save-config @@ -4,7 +4,6 @@ # Authors: grml-team (grml.org), (c) Michael Prokop # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. -# Latest change: Son Mai 13 11:46:44 CEST 2007 [mika] ################################################################################ # some zsh-stuff {{{ @@ -15,18 +14,30 @@ # }}} # set variables {{{ - - # old linuxrc version: - [ -d /cdrom ] && OLDLAYOUT=1 || OLDLAYOUT='' - # new initramfs layout: - [ -d /live/image ] && NEWLAYOUT=1 || NEWLAYOUT='' - LANG=C LC_ALL=C [[ $UID != 0 ]] && runas='sudo' # important for /etc - check4progs mutt || echo "Warning, mutt not available for mail handling.">&2 - check4progs findchanged tar || { echo "Sorry, can't continue. Exiting.">&2 ; exit 1 } + if [ -d /run/live/overlay/rw ] ; then # since Dec 2018 + CHANGE_DIR='/run/live/overlay/rw' + elif [ -d /lib/live/mount/overlay/rw ] ; then # 2012 until Dec 2018, backwards compatibility + CHANGE_DIR='/lib/live/mount/overlay/rw' + else + echo "Error: no overlay directories found (like /lib/live/mount/overlay or /live/overlay)." >&2 + bailout; exit 1 + fi + + if [ -d /run/live/rootfs ] ; then + ORIG_DIR="$(find /run/live/rootfs/ -maxdepth 1 -name \*.squashfs | head -1)" + elif [ -d /lib/live/mount/rootfs ] ; then + ORIG_DIR="$(find /lib/live/mount/rootfs/ -maxdepth 1 -name \*.squashfs | head -1)" + else + echo "Error: no rootfs directories found in '/run/live/rootfs' or '/lib/live/mount/rootfs'." >&2 + bailout; exit 1 + fi + + check4progs mutt &>/dev/null || echo "Warning, mutt not available for mail handling.">&2 + check4progs tar || { echo "Sorry, can't continue. Exiting.">&2 ; bailout ; exit 1 } CONFIG=/etc/grml/saveconfig [ -r "$CONFIG" ] && . $CONFIG @@ -37,10 +48,11 @@ GRML_VERSION=$(awk '{print $1}' /etc/grml_version 2>/dev/null || print "not a grml system") KERNEL=$(uname -a) - TMPDIR=/tmp - MAILFILE="$TMPDIR/mail.txt" + TMPDIR='/tmp' + MAILFILE="${TMPDIR}/mail.txt" [ -n "$FILELIST" ] || FILELIST=$(mktemp $TMPDIR/filelist.XXXXXX) +# }}} # functions {{{ debug(){ @@ -57,6 +69,16 @@ bailout(){ } trap bailout 1 2 3 15 + +findchanged() { + if [ -d "$1" ]; then + for i in `(cd "$1"; find . -type f 2>/dev/null | sed 's,^\./,,g' | grep -v ' ' )`; do + cmp -s "$1/$i" "$2/$i" || echo "$1/$i" + done + elif [ -e "$1" ]; then + cmp -s "$1" "$2" || echo "$1" + fi +} # }}} # usage information {{{ @@ -122,32 +144,37 @@ save_grmlhome(){ save_etc(){ debug "save etc" if [ -n "$NEWLAYOUT" ] ; then - $runas find /live/cow/etc | sed -e 's#/live/cow## ; /etc$/d' >> $FILELIST + $runas find "${CHANGE_DIR}/etc" | sed -e "s#${CHANGE_DIR}## ; /etc$/d" >> $FILELIST else - $runas findchanged /etc /GRML/etc >> $FILELIST + $runas findchanged /etc "${ORIG_DIR}/etc" >> $FILELIST fi } save_configdir(){ debug "save configdir" if [ -d $HOME/config ] ; then - ls $HOME/config/* >> $FILELIST 2>/dev/null + ls $HOME/config/* >> $FILELIST 2>/dev/null ls $HOME/config/.* >> $FILELIST 2>/dev/null fi } +# }}} # create configuration file {{{ create_config(){ if ! [ -r "$FILELIST" ]; then - echo "Sorry, filelist $FILELIST could not be read." >&2 - echo "Error when generating $FILENAME." >&2 + echo "Filelist $FILELIST could not be read." >&2 + echo "Error when generating $FILENAME." >&2 + bailout ; exit 1 else - # GNU tar sucks so much, really. Avoid the "file changed as we read it": - tar cf /dev/null /etc - # now really execute the according tar command: - BZIP2=-9 $runas tar -T - -cpPjf "$FILENAME" <"$FILELIST" && \ - echo "Successfully stored configuration in file $FILENAME" || \ - echo "Error when generating $FILENAME." >&2 + # GNU tar sucks so much, really. Avoid the "file changed as we read it": + tar cf /dev/null /etc + # now really execute the according tar command: + if BZIP2=-9 $runas tar -T - -cpPjf "$FILENAME" <"$FILELIST" ; then + echo "Successfully stored configuration in file $FILENAME" + else + echo "Error when generating $FILENAME." >&2 + bailout ; exit 1 + fi fi } # }}} @@ -213,6 +240,7 @@ parse_options() parse_options $* # }}} +# execution wrapper {{{ runit(){ if [[ $SAVE_HOME == "yes" ]]; then debug "running save_home" @@ -235,9 +263,11 @@ runit(){ SETSAVE=1 fi if [ -z $SETSAVE ] ; then - echo "Sorry, you did not select any configuration which should be saved. Exiting." ; exit 1 + echo "Sorry, you did not select any configuration which should be saved. Exiting." + bailout ; exit 1 fi } +# }}} # now run it runit