#!/usr/bin/env bash 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 "SBGrid site migration script" echo "----------------------------" echo "Running pre-migration checks:" if [ $(uname) == "Darwin" ]; then echo "Running on macOS." if [ ! -e '/etc/synthetic.conf' ]; then echo " No /etc/synthetic.conf file found." echo " This file is required for macOS to create" echo " the SBGrid /programs path. See " echo " https://sbgrid.org/wiki/macos" echo " for more information." echo " " echo " Cannot continue migration. Exiting." exit 1 else echo " - /etc/synthetic.conf config found." fi elif [ $(uname) == "Linux" ]; then echo "Running on Linux." else echo "Unknown OS." fi 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 to confirm site name by email if your" echo "advisor is not listed below. Email accounts@sbgrid.org." echo echo "The migration process will not impact running jobs or" echo "prevent software from functioning normally." echo "Exit at any time with a CTRL-c." echo unset install_sitename echo "Please select your site from this list by number:" 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 site 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" else echo "error in database move, exiting" exit 1 fi if [ $(uname) == "Darwin" ]; then sbgridcmd="/programs/i386-mac/sbgrid_installer/latest/sbgrid-cli info sbgrid-installer" elif [ $(uname) == "Linux" ]; then sbgridcmd="/programs/x86_64-linux/sbgrid_installer/latest/sbgrid-cli info sbgrid-installer" else echo "unknown OS. No validation run." fi echo "Checking post migration configuration ..." $sbgridcmd sbgrid_exit=$? echo " " echo "------------------------------" if [ $sbgrid_exit == 0 ]; then echo " " echo " " echo "Test appears to have succeeded!" echo "Migration complete!" else echo "Migration is complete but a post install test failed." echo "It is possible the site configuration is invalid. " echo "Please send the output of the sbinfo command and " echo "any errors you see above to bugs@sbgrid.org and we'll help" fi