#!/bin/bash # # Script to upgrade all Slackware-like files # # By Rudson R. Alves # set -e VERSION=1.0 PRGNAME=`basename $0` # Start gpm if [ -x /etc/rc.d/rc.gpm ]; then /etc/rc.d/rc.gpm start 2>- >/dev/null fi # ------------------------------------------ # Functions # ------------------------------------------ # Print help function print_help() { echo "$PRGNAME-$VERSION" echo "Use:" echo " $PRGNAME [option]" echo -e "\nWhere:" echo " options are:" echo " --help|-h - this help" echo " --debug - enable debug mode" echo " --distro|-d " echo " - set a distribution" echo " --path|-p " echo " - set the complete distro files path. Default" echo " is /home/ftp/distro/slackware/slackware-current" echo " --editor|-e " echo " - set an editor program. Default is vim." echo " --cdrom|-c - mount /dev/cdrom in /media/cdrom or /mnt" echo " --skip| -s " echo " - set a file/list with skip packages upgrade" echo " --all|-a " echo " - set a file/list with serie of packages to " echo " upgrade/install" echo "" } # Upgrade a package function upgrade_only() { if check_installed $1; then return fi if ! check_upgrade $1; then return fi OUT=`upgradepkg $1 | egrep '(Error|Upgrading|Skipping)' 2>/dev/null` pkg=`basename $1` status=`echo $OUT | awk '{print $2}'` pkgname=`echo $OUT | awk '{print $3}'` if [ "$status" == "Skipping" ]; then echo -e "\e[33;1mSkipped $pkgname\e[m" elif [ "$status" == "Upgrading" ]; then echo -e "\e[32;1mUpgraded $pkgname to ${pkg//.t?z/}\e[m" #else #echo -e "\e[31;1m$status $pkgname\e[m" fi } # Upgrade or install a package function upgrade_install() { if check_installed $1; then return fi OUT=`upgradepkg --install-new $1 | egrep '(Error|Upgrading|Skipping|Installing)' 2>/dev/null` pkg=`basename $1` status=`echo $OUT | awk '{print $2}'` pkgname=`echo $OUT | awk '{print $3}'` if [ "$status" == "Skipping" ]; then [ $SKIPMSG != "on" ] && echo -e "\e[33;1mSkipped ${pkg//.t?z/}\e[m" elif [ "$status" == "Upgrading" ]; then echo -e "\e[32;1mUpgraded $pkgname using ${pkg//.t?z/}\e[m" elif [ "$status" == "Installing" ]; then echo -e "\e[31;1mInstalled $pkgname\e[m" fi } # Check if a package is installed function check_installed() { pkg=`basename ${1//.t?z/}` if [ -e /var/log/packages/$pkg ]; then return 0 else return 1 fi } # Check if a package is upagrade function check_upgrade() { pkg=`basename ${1//.t?z/}` pkg=`echo $pkg | sed 's/^\(.*\)\-.*\-.*\-.*$/\1/'` if ls /var/log/packages/${pkg}-[0-9]*-*-* >&2 2>/dev/null >/dev/null ; then return 0 else return 1 fi } # Print a error message function input_error() { echo -e "\e[31;mInput error..." if [ "$1" != "" ]; then echo $1 fi echo -e "See '$PRGNAME --help' for help!\e[m" exit 1 } function set_parameters { # Get and set the variables with input parameters # Use: set_parameters $@ # where $@ are the parameters input # # Parameters analyze DEBUG="off" while [ "$1" ]; do case $1 in '--help'|'-h') print_help exit 0 ;; '--debug') DEBUG="on" set -x ;; '--distro'|'-d') if [ "$2" == "slackware" -o "$2" == "32" -o "$2" == "slackware64" -o "$2" == "64" ]; then if [ "$2" == "32" ]; then DISTRO="slackware" elif [ "$2" == "64" ]; then DISTRO="slackware64" else DISTRO="$2" fi else input_error "Distro '$2' no suported..." fi shift ;; '--path'|'-p') if [ "$2" != "" ]; then if [ -d $2 ]; then PATH_DISTRO=$2 else input_error "Directory '$2' not found..." fi else input_error "Empyt directory do path..." fi shift ;; '--editor'|'-e') if [ "$2" != "" ]; then if which $2 >&2 2>/dev/null; then EDITOR=$2 else input_error "Editor '$2' not found..." fi else input_error "Empyt editor..." fi ;; '--cdrom'|'-c') if [ -e /media/cdrom ]; then mount /dev/cdrom /media/cdrom [ $? != 0 ] && input_error "Error im mount /dev/cdrom in /media/cdrom" PATH_DISTRO="/media/cdrom" else mount /dev/cdrom /mnt [ $? != 0 ] && input_error "Error im mount /dev/cdrom in /mnt" PATH_DISTRO="/mnt" fi ;; '--skip'|'-s') if [ "$2" != "" ]; then VEC=( $2 ) if [ ${#VEC[@]} -gt 1 ]; then SKIP_LIST="$2" elif [ -e $2 ]; then SKIP_LIST=`cat $2 | tr '\012' ' '` else SKIP_LIST="$2" fi else input_error "File of skip_list no passed..." fi shift ;; '--all'|'-a') if [ "$2" != "" ]; then VEC=( $2 ) if [ ${#VEC[@]} -gt 1 ]; then ALL_LIST="$2" elif [ -e $2 ]; then ALL_LIST=`cat $2 | tr '\012' ' '` else ALL_LIST="$2" fi else input_error "File of all_seria_install_list no passed..." fi shift ;; *) input_error "Unknow option!" ;; esac shift done } # Check if a file is in a file_list function is_in_list() { LIST=$1 PKG=`basename $2` PKG=`echo ${PKG/.t?z/} | sed 's/^\(.*\)\-.*\-.*\-.*$/\1/'` echo " $LIST " | grep " $PKG " >&2 >/dev/null return $? } # Return upper case of a string function upcase() { echo $1 | tr [a-z] [A-Z] } # ------------------------------------------ # Start variables # ------------------------------------------ set_parameters $@ DISTRO=${DISTRO:='slackware'} if [ "$DISTRO" == "slackware" ]; then PATH_DISTRO=${PATH_DISTRO:='/home/ftp/distro/slackware/slackware-current'} else PATH_DISTRO=${PATH_DISTRO:='/home/ftp/distro/slackware64/slackware64-current'} fi SKIPMSG=${SKIPMSG:="on"} EDITOR=${EDITOR:="vim"} # Check root user if [ "$USER" != "root" ]; then input_error "Use this application as root user only!" fi # Check single-user mode LEVEL=(`runlevel`) if [ ${LEVEL[1]} -ne 1 ]; then input_error "Put yout machine in single-user mode:\ntelinit 1" fi if [ -d $PATH_DISTRO/slackware64 -a $DISTRO != "slackware64" ]; then input_error "Set distro to 'slackware64' or put the 'slackware' CDROM/PATH_DISTRO..." fi # Check install files exist if [ ! -d $PATH_DISTRO/$DISTRO/a ]; then input_error "$PATH_DISTRO/$DISTRO/a no exits. Check you distro copy..." fi # ------------------------------------------ # Upgrade you Slackware # ------------------------------------------ echo -e "\n\n\e[36;1m`upcase $PRGNAME`-$VERSION by alves\n" echo -e "Distro: $DISTRO" echo -e "Source: $PATH_DISTRO" echo -e "Editor: $EDITOR" echo -e "Upgrade/Install series: \"$ALL_LIST\"" echo -e "Skip files: \"$SKIP_LIST\"\e[m" # Upgrade glibc shared libraries echo -e "\e[34;1m\nUpgrade glibc-solibs:\e[m" upgrade_only `ls $PATH_DISTRO/$DISTRO/a/glibc-solibs-*.t?z` # Upgrade package utilities: echo -e "\e[34;1m\nUpgrade pkgtools:\e[m" upgrade_only `ls $PATH_DISTRO/$DISTRO/a/pkgtools-*.t?z` # Upgrade kernel source: echo -e "\e[34;1m\nk series:\e[m" KERNEL_CONF=/boot/config-`uname -r` if [ ! -e $KERNEL_CONF ]; then cp /usr/src/linux/.config $KERNEL_CONF fi # Upgrade normal pakages: for s in l a ap d e f k kde n t tcl x xap y; do if is_in_list "$ALL_LIST" "$s"; then echo -e "\e[34;1m\nUpgrade/Install $s serie:\e[m" LIST=`ls $PATH_DISTRO/$DISTRO/$s/*.t?z` for pkg in $LIST; do if ! is_in_list "$SKIP_LIST" "$pkg"; then upgrade_install $pkg fi done else echo -e "\e[34;1m\nUpgrade $s serie:\e[m" LIST=`ls $PATH_DISTRO/$DISTRO/$s/*.t?z` for pkg in $LIST; do if ! is_in_list "$SKIP_LIST" "$pkg"; then upgrade_only $pkg fi done fi done # Upgrade aspell packages echo -e "\e[34;1m\nUpgrade aspell series:\e[m" LIST=`ls $PATH_DISTRO/extra/aspell-word-lists/*.t?z` for pkg in $LIST; do if ! is_in_list "$SKIP_LIST" "$pkg"; then upgrade_only $pkg fi done # Upgrade others extra packages echo -e "\e[34;1m\nUpgrade extra series:\e[m" LIST=`ls $PATH_DISTRO/extra/*/*.t?z` for pkg in $LIST; do if ! is_in_list "$SKIP_LIST" "$pkg"; then upgrade_only $pkg fi done # ------------------------------------------ # Upgrade you /etc # ------------------------------------------ # Check for news config files LIST=( `find /etc/ -name "*.new"` ) MAX=${#LIST[@]} if [ $MAX -eq 0 ]; then echo -e "\n\e[36;1mUpgrade finished...\e[m\n" exit 0 fi echo -e "\n\n\e[33;1mFind this news config files in /etc:\e[m" for f in ${LIST[@]}; do echo $f done echo -ne "\n\e[33;1mUpgrade yours news config files now (Y/n)? \e[m" read ANS if [ "$ANS" == "n" -o "$ANS" == "N" ]; then echo -e "\n\e[36;1mUpgrade finished...\e[m\n" exit 0 fi index=0 BACKUP="OFF" while [ $index -lt $MAX ]; do NEW=${LIST[index]} OLD=${NEW/.new/} echo -e "\e[33;1m" echo -e "\n\nBackup of old files is \e[32;1m$BACKUP\e[m" echo -e "Select one option to new('$NEW') and old($OLD):" echo -e "1) Replace 3) Edit new file 5) Skip it 7) Exit" echo -e "2) Show diff 4) Edit old file 6) Enable/desable backup" echo -n "Option: " echo -e "\e[m" read ANS case $ANS in 1) [ $BACKUP == "ON" ] && cp $OLD ${OLD}.old mv $NEW $OLD let index++ ;; 2) echo "diff $OLD $NEW:" ( diff $OLD $NEW ) ;; 3) $EDITOR $NEW ;; 4) $EDITOR $OLD ;; 5) let index++ ;; 6) BACKUP=`[ "$BACKUP" == "ON" ] && echo "OFF" || echo "ON"` ;; 7) exit 0 ;; esac done echo -e "\n\e[36;1mUpgrade finished...\e[m\n"