#!/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" 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 "Required installation files found." echo "---------------------------------" echo if [ $1 ]; then install_sitename=$1 else echo "This script will migration your the site configuration" echo "for your SBGrid installation. You will be able to" echo "confirm your settings before the migration happens. You" echo "will need the new site name that was sent ny email." echo "This process should be fast and will not impact running jobs." echo echo "Exit at any time with a CTRL-c." echo unset install_sitename echo "Enter the SBGrid site name:" read install_sitename fi echo "Does this site name look correct? Y/n" echo echo $install_sitename echo read confirmation if [ $confirmation == Y ]; then echo "Great. Migrating installation." else echo "No problem, we can start over. 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 $TMPCONFIG ]; then rm $TMPCONFIG fi if [ ! -e $BACKUPCONFIG ]; then cp -av $INSTALLERCONFIG $BACKUPCONFIG else echo "backup config found from previous migration" echo "Will not overwrite $BACKUPCONFIG" fi cp -av $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 "$install_sitename" >${SITENAME_FILE} NEWDATABASE="/programs/share/packages-${install_sitename}.db" if [ ! -e "$DATABASE.backup" ]; then cp -av $DATABASE $DATABASE.backup else echo "previously backed-up database exists" fi if [ -e $NEWDATABASE ]; then echo "previously migrated database exists:" echo "$NEWDATABASE" echo will be overwritten. fi mv -f $DATABASE $NEWDATABASE if [ $? == 0 ]; then echo "database move successful" echo "Migration complete!." else echo "error in database move" fi