|
From: <bl...@us...> - 2003-11-05 16:07:30
|
Update of /cvsroot/devil-linux/build/scripts/scripts
In directory sc8-pr-cvs1:/tmp/cvs-serv3994/scripts/scripts
Added Files:
Tag: rel-1-0-patches
upgrade-config
Log Message:
Check in of upgrade-config script to 1.0 release.
--- NEW FILE: upgrade-config ---
#!/bin/sh
# $Id: upgrade-config,v 1.6.2.1 2003/11/05 15:57:44 blubdog Exp $
#
# $Source: /cvsroot/devil-linux/build/scripts/scripts/upgrade-config,v $
# $Revision: 1.6.2.1 $
# $Date: 2003/11/05 15:57:44 $
#
# http://www.devil-linux.org
#
# Written by: Bruce Smith <dev...@re...>
TMPC=/shm/var/tmp/upd-config.$$
TMPD=/shm/var/tmp/upd-etc.$$
TMPF=/shm/var/tmp/upd-tmp.$$
RESULT=/shm/var/tmp/upd-res.$$
RAMDISKDIR="/shm"
LOGF="newconfig/etc/sysconfig/upgrade.log"
#DIALOG="dialog --clear --aspect 76 --no-shadow"
DIALOG="dialog --clear --no-shadow"
BACKTITLE="Devil-Linux configuration upgrade"
# Display a Yes-No dialog box and return result
askyesno() {
[ "${3}" = "no" ] && DEFNO="--defaultno" || DEFNO=""
$DIALOG $BACKLAB --title "$1" --backtitle "$BACKTITLE" $DEFNO --yesno "$2" 0 0
return $?
}
# Display a message dialog box
msgbox() {
$DIALOG --title "$1" --backtitle "$BACKTITLE" --msgbox "$2" 0 0
}
# Modify values in a system configuration file
mod_config() {
if [ $(grep -c "^${2}=" ${1}) -eq 1 ]; then
eval bs=$(grep "^${2}=" ${1} | sed "s/^${2}=//")
if [ "$bs" = "$3" ]; then
# printf '%-30s no changed needed\n' "$2"
return
fi
else
printf '%-30s not found in new config\n' "$2" | tee -a $LOGF
return
fi
rm -f $TMPC
cp -f $1 $TMPC
if [ "$3" = "yes" -o "$3" = "no" ]; then
sed "s^${2}=.*$${2}=${3}" $TMPC > $1
else
sed "s^${2}=.*$${2}=\"${3}\"" $TMPC > $1
fi
rm -f $TMPC
printf '%-30s changed to: "%s"\n' "$2" "$3" | tee -a $LOGF
}
pause() {
echo
read -n 1 -p "Press any key to continue ..."
echo
}
setmenuheight () {
let width=$(stty size|cut -f2 -d' ')
let height2=$(stty size|cut -f1 -d' ')-1
let height=$height2-10
linecount=$(cat $TMPD|wc -l)
[ $height -gt $linecount ] && height=$linecount
}
echo
if [ -e $RAMDISKDIR/newconfig ]; then
echo /shm/newconfig exists, please remove.
exit 1
fi
if [ ! -f /config/etc.tar.bz2 ]; then
echo Cannot find file: /config/etc.tar.bz2
exit 1
fi
for d in $RAMDISKDIR/etc $RAMDISKDIR/root
do
if [ ! -e "$d" ]; then
echo Cannot find directory: $d
exit 1
fi
done
rm -f $TMPD
cd $RAMDISKDIR
mkdir newconfig || exit 1
tar -xjf /config/etc.tar.bz2 -C newconfig
for f in $(find etc root -type f -print)
do
echo -n "."
[ $f = "etc/Devil-release" ] && continue
[ $f = "etc/issue" ] && continue
[ $f = "etc/issue.net" ] && continue
[ $f = "etc/sysconfig/config" ] && continue
[ $f = "etc/sysconfig/config.default" ] && continue
[ $f = "etc/sysconfig/config.old" ] && continue
[ $f = "etc/sysconfig/upgrade.log" ] && continue
[ $f = "etc/sysconfig/software" ] && continue
[ $f = "etc/mtab" ] && continue
[ $f = "etc/.pwd.lock" ] && continue
cmp -s $f newconfig/$f || echo $f \"\" off \"$f\" >> $TMPD
done
msgbox "Please read:" "The next screen will let you select which of your old config files you want to copy to your new configuration \n\nBe VERY CAREFUL to only copy files you have customized. Copying other files could cause severe problems.\n\nNote: Selecting \"Help\" will display info about the current file, but upon return you will lose all selections made."
while true
do
setmenuheight
eval $DIALOG --title \"Select files to be copied to the new config\" --backtitle \"$BACKTITLE\" \
--item-help --help-button \
--checklist \"[un]select files to be kept with the SPACE BAR\" 0 $width $height \
$(sort $TMPD) 2> $RESULT
RETURN=$?
if [ $RETURN -eq 0 ]; then
if [ "$(head -n1 $RESULT|cut -c1-4)" = "HELP" ]; then
# Help button pressed
for f in $(cat $RESULT|cut -c5-)
do
if [ -f "newconfig/$f" ]; then
echo > $TMPF
ls -l "$f" "newconfig/$f" >> $TMPF
eval $DIALOG --title \"the files:\" \
--backtitle \"$BACKTITLE\" \
--item-help --help-button \
--textbox "$TMPF" $height2 $width
echo > $TMPF
diff -u "$f" "newconfig/$f" >> $TMPF
eval $DIALOG --title \"running diff on the files:\" \
--backtitle \"$BACKTITLE\" \
--item-help --help-button \
--textbox "$TMPF" $height2 $width
rm -f $TMPF
eval $DIALOG --title \"the old/original file:\" \
--backtitle \"$BACKTITLE\" \
--item-help --help-button \
--textbox "$f" $height2 $width
eval $DIALOG --title \"the NEW file:\" \
--backtitle \"$BACKTITLE\" \
--item-help --help-button \
--textbox "newconfig/$f" $height2 $width
else
echo > $TMPF
ls -l "$f" >> $TMPF
eval $DIALOG --title \"the old/original file:\" \
--backtitle \"$BACKTITLE\" \
--item-help --help-button \
--textbox "$TMPF" $height2 $width
rm -f $TMPF
eval $DIALOG --title \"the old/original file\" \
--backtitle \"$BACKTITLE\" \
--item-help --help-button \
--textbox "$f" $height2 $width
fi
done
else
# OK button pressed
echo >> $LOGF
echo "************************************************************" >> $LOGF
date >> $LOGF
echo >> $LOGF
echo "Files saved from old config:" >> $LOGF
echo "----------------------------" >> $LOGF
echo >> $LOGF
for f in $(cat $RESULT)
do
eval p=$f
d="$(dirname newconfig/$p)"
[ ! -d $d ] && mkdir -p $d
# echo cp -af $p newconfig/$p
echo "keeping file: $p" | tee -a $LOGF
cp -af $p newconfig/$p
done
break
fi
else
# Cancel button pressed
break
fi
done
echo
if askyesno "/etc/sysconfig/config migration" "Do you want to migrate old values to your new /etc/sysconfig/config ?" yes
then
echo >> $LOGF
echo >> $LOGF
echo "/etc/sysconfig/config migration:" >> $LOGF
echo "--------------------------------" >> $LOGF
echo >> $LOGF
cp -f etc/sysconfig/config newconfig/etc/sysconfig/config.old
cp -f newconfig/etc/sysconfig/config newconfig/etc/sysconfig/config.default
. etc/sysconfig/config
echo "Migrating /etc/sysconfig/config values "
echo
for bs in $(grep -v -e '^ *#' -e '^ *$' etc/sysconfig/config|cut -f1 -d'=')
do
eval mod_config newconfig/etc/sysconfig/config ${bs} \"\$${bs}\"
done
fi
rm -fr $TMPD $RESULT
|