#!/bin/sh # Installing packages (doing the real dist-upgrade) # gettext domain TEXTDOMAIN="lliurex-up" export TEXTDOMAIN COMMON_LIBRARY="/usr/share/lliurex-up/common-upgrade-vars.sh" if [ -r $COMMON_LIBRARY ] ; then . $COMMON_LIBRARY fi #gettext messages INFO_MESSAGE="$(gettext "Install required packages")" SERVER_ATENTION_MESSAGE="$(gettext "This seems a LliureX Server, caution. ")" SERVER_REMOVE_PACKAGES_MESSAGE="$(gettext "Removing some packages")" SERVER_INSTALL_PACKAGES_MESSAGE="$(gettext "Installed some packages")" APACHE_CRT_FILE="/etc/lliurex-secrets/certs/apache/apache.crt" APACHE_CRT_FILE_NCFG="/usr/share/ca-certificates/lliurex-certs/ncfg-certs/apache.crt" APACHE_CRT_FILE_NCFG_VAR="/var/lib/llxcfg-ncfg-certs/certificates/ncfg-certs/apache.crt" # Methods _commonPreUpgradeActions() { # Cache for APT clean apt-get clean # Some dirty actions if [ -f "$APACHE_CRT_FILE" ] ; then sed "/-----BEGIN RSA PRIVATE KEY-----/,/-----END RSA PRIVATE KEY-----/d" -i "$APACHE_CRT_FILE" fi if [ -f "$APACHE_CRT_FILE_NCFG" ] ; then sed "/-----BEGIN RSA PRIVATE KEY-----/,/-----END RSA PRIVATE KEY-----/d" -i "$APACHE_CRT_FILE_NCFG" fi if [ -f "$APACHE_CRT_FILE_NCFG_VAR" ] ; then sed "/-----BEGIN RSA PRIVATE KEY-----/,/-----END RSA PRIVATE KEY-----/d" -i "$APACHE_CRT_FILE_NCFG_VAR" fi } _cleanhome() { LOCALHOMESFILE=`mktemp` LOCALUSERSFILE=`mktemp` REMOVEHOMEFILE=`mktemp` ls -1 "/home" > $LOCALHOMESFILE cat "/etc/passwd" > $LOCALUSERSFILE diff $LOCALHOMESFILE $LOCALUSERSFILE | grep "^<" | cut -d" " -f2 > $REMOVEHOMEFILE while read line do if [ $line != "" ]; then rm -rf "/home/$line" || true fi done < $REMOVEHOMEFILE rm $LOCALUSERSFILE $LOCALUSERSFILE $REMOVEHOMEFILE _cleanhome } # Pre Upgrade Actions _serverPreUpgradeActions() { echo "$SERVER_ATENTION_MESSAGE" # Remove some packages. echo "$SERVER_REMOVE_PACKAGES_MESSAGE" apt-get purge "$PACKAGES_REMOVED_ON_SERVER" --force-yes -y rm -rf /net/home/students/* || true rm -rf /net/home/teachers/* || true rm -rf /net/home/others/* || true rm -rf /net/groups/* || true _cleanhome } _musicaPreUpgradeActions() { echo "Musica Upgrade" } _infantilPreUpgradeActions() { echo "Infantil Upgrade" } _desktopPreUpgradeActions() { echo "Desktop Upgrade" } _biblioPreUpgradeActions() { echo "Biblioteca Upgrade" _cleanhome } _clientPreUpgradeActions() { echo "Client Upgrade" _cleanhome } _teachersPreUpgradeActions() { echo "Teachers Upgrade" } _pimePreUpgradeActions() { echo "Pime Upgrade" } # Post Upgrade Actions _serverPostUpgradeActions() { echo "$SERVER_ATENTION_MESSAGE" # Install some packages. echo "$SERVER_INSTALL_PACKAGES_MESSAGE" apt-get install -y --force-yes "$PACKAGES_INSTALL_ON_SERVER" } _musicaPostUpgradeActions() { echo "Musica Upgrade" # Install some packages apt-get install -y --force-yes "$PACKAGES_INSTALL_ON_MUSIC" } _infantilPostUpgradeActions() { echo "Infantil Upgrade" # Install some packages apt-get install -y --force-yes "$PACKAGES_INSTALL_ON_INFANTIL" } _desktopPostUpgradeActions() { echo "Desktop Upgrade" # Install some packages apt-get install -y --force-yes "$PACKAGES_INSTALL_ON_DESKTOP" } _biblioPostUpgradeActions() { echo "Biblioteca Upgrade" # Install some packages apt-get install -y --force-yes "$PACKAGES_INSTALL_ON_BIBLIOTECA" } _clientPostUpgradeActions() { echo "Client" # Install some packages apt-get install -y --force-yes "$PACKAGES_INSTALL_ON_CLIENT" } _teachersPostUpgradeActions() { echo "Teachers Upgrade" # Install some packages apt-get install -y --force-yes "$PACKAGES_INSTALL_ON_TEACHERS" } _pimePostUpgradeActions() { echo "Pime Upgrade" # Install some packages apt-get install -y --force-yes "$PACKAGES_INSTALL_ON_PIME" } _info() { echo "$INFO_MESSAGE" } _migrate() { _discoverCddVersion _commonPreUpgradeActions if [ $IS_SERVER -eq 0 ] ; then #_serverPreUpgradeActions echo "PreUpgradeActions" fi if [ $IS_CLIENT -eq 0 ] ; then #_clientPreUpgradeActions echo "PreUpgradeActions" fi apt-get dist-upgrade -y --force-yes apt-get -f install apt-get dist-upgrade -y --force-yes apt-get -f install apt-get update if [ $IS_SERVER -eq 0 ] ; then _serverPostUpgradeActions fi if [ $IS_CLIENT -eq 0 ] ; then _clientPostUpgradeActions fi update-grub } _usage() { echo "# Unknown argument" } _die() { echo "Error: $1" exit 1 } ACTION="$1" case "$ACTION" in migrate) _migrate ;; info) _info ;; *) _usage ;; esac exit 0