#!/usr/bin/env bash # $Id$ USAGE="Usage : sbmigrate-site [ site name ]" PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH INSTALLERCONFIG="$HOME/.sbgrid_installer" BACKUPCONFIG="$HOME/.sbgrid_installer_site_migrated" SITENAME_FILE="/programs/share/sitename" echo "Running pre-migration checks" touch "/programs/share/site_migrate_check" 2>/dev/null if [ $? != 0 ]; then echo "This user cannot write to /programs/share" echo "Check that you have permission to write to this" echo "SBGrid software installation. Migration cannot " echo "continue without write access. " exit 1 else echo " - Write check passed." fi if [ ! -e $INSTALLERCONFIG ]; then echo "No installation manager configuration found." echo "Cannot continue migration. Exiting." exit 1 else echo " - $INSTALLERCONFIG config found." fi if [ -f $SITENAME_FILE ]; then SITENAME=$(cat $SITENAME_FILE) DATABASE="/programs/share/packages-${SITENAME}.db" echo " - sitename file found." else echo "No site configuration found." echo "Cannot continue migration. Exiting." exit 1 fi if [ ! -e "${DATABASE}" ]; then echo "No software database found." echo "Cannot continue migration. Exiting." exit 1 else echo " - database file found at: $DATABASE" fi echo "All required installation files found." echo "---------------------------------" echo if [ $1 ]; then install_sitename=$1 else echo "This script will migrate the site configuration" echo "for your SBGrid installation. You will be able to" echo "confirm your settings before the migration happens." echo "You may need the new site name that was sent by email" echo "if your advisor is not listed below." echo "The process will be fast and will not impact running jobs." echo echo "Exit at any time with a CTRL-c." echo unset install_sitename echo "Please select your site name from this list:" echo " PI (site name)" echo "1) Dessen (dessen_a_514i)" echo "2) Nicolet (nicolet_y_359i)" echo "3) Nury (nury_h_512i)" echo "4) Petosa (petosa_c_148i)" echo "5) Schoehn (schoehn_g_408i)" echo "6) Weik (weik_m_513i)" echo "7) Other (enter manually)" echo "---------------------------------" read labvar case $labvar in 1) install_sitename="dessen_a_514i" ;; 2) install_sitename="nicolet_y_359i" ;; 3) install_sitename="nury_h_512i" ;; 4) install_sitename="petosa_c_148i" ;; 5) install_sitename="schoehn_g_408i" ;; 6) install_sitename="weik_m_513i" ;; *) echo "Enter the SBGrid site name:" read install_sitename ;; esac fi echo "Does this site name look correct? Y/n" echo " " echo " $install_sitename" echo " " read confirmation if [ $confirmation == Y ] || [ $confirmation == y ] ; then echo "Great. Migrating this installation." echo " " else echo "No problem, we can start over." echo "No files were changed." exit 0 fi # process old sbgrid_installer im_oldsite_name=$(grep 'site = ' $INSTALLERCONFIG | awk '{print $3}') if [ ! -e "$HOME/.sbgrid_old_sitename" ]; then echo $im_oldsite_name >$HOME/.sbgrid_old_sitename fi # create new .sbgrid_installer file TMPCONFIG="${INSTALLERCONFIG}.tmp" if [ ! -e $BACKUPCONFIG ]; then cp -av $INSTALLERCONFIG $BACKUPCONFIG else echo "Backup config found from previous migration" echo "Will not overwrite $BACKUPCONFIG" fi # do cat $INSTALLERCONFIG > $TMPCONFIG head -n 1 $TMPCONFIG >${INSTALLERCONFIG} echo "site = $install_sitename" >>${INSTALLERCONFIG} grep 'user = ' $TMPCONFIG >>${INSTALLERCONFIG} grep 'key = ' $TMPCONFIG >>${INSTALLERCONFIG} grep 'target = ' $TMPCONFIG >>${INSTALLERCONFIG} echo >>${INSTALLERCONFIG} echo "Configuration update completed." echo "$install_sitename" >${SITENAME_FILE} NEWDATABASE="/programs/share/packages-${install_sitename}.db" if [ ! -e "$DATABASE.backup" ]; then cp -av $DATABASE $DATABASE.backup else echo "Previously database backed-up exists" fi if [ -e $NEWDATABASE ]; then echo "previously migrated database exists:" echo "$NEWDATABASE" echo "This will be overwritten." fi mv -vf $DATABASE $NEWDATABASE if [ $? == 0 ]; then echo "Database move successful" echo "Migration complete!." else echo "error in database move" fi