Skip to content

Instantly share code, notes, and snippets.

@bonetechnologies
Created May 14, 2012 23:33
Show Gist options
  • Save bonetechnologies/2698080 to your computer and use it in GitHub Desktop.
Save bonetechnologies/2698080 to your computer and use it in GitHub Desktop.
#!/bin/bash
timestamp=$(date +%s)
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
###############################################################################
# Configuration - Here is where you configure all of the things. #
###############################################################################
# Script Settings
compression='bzip2'
uncompression='bunzip2'
customerEmailDomains='acmebusinessconsulting.com'
#
# EC2 Remote Settings
ec2RemoteVM='km-acmebc.jiveSBS.com'
ec2RemoteDB='sbs'
ec2RemoteUser='root'
ec2RemotePgDump='/usr/local/jive/postgres/bin/pg_dump --no-owner --no-acl -U postgres'
#
# Local Settings
workingDir="/mnt/jive_persist/ec2_migration_${timestamp}"
jiveStartup="/usr/local/jive/applications/sbs/home/jive_startup.xml"
localAppName="sbs"
#
# Remote Settings
saveJivePropertiesURL='http://ktwit.net/ec2migrations/saveJiveProperties.sh'
upgradeJshURL='http://ktwit.net/ec2migrations/upgradeJsh.js'
###############################################################################
# #
###############################################################################
#Create some stuff
mkdir ${workingDir}
chmod a+rwx ${workingDir}
if [ "$TERM" == "screen" ]; then
echo "In a screen session, continuing..."
else
echo "You need to run this script from within a screen session."
yum install screen
exit 1
fi
marburgKey='-----BEGIN RSA PRIVATE KEY-----
NOPE
-----END RSA PRIVATE KEY-----'
function writeLocalMarburgKey() {
mkdir -p ~/.ssh/
echo "${marburgKey}" > ~/.ssh/id_rsa_marburg
chmod 0600 ~/.ssh/id_rsa_marburg
}
function saveJiveProperties() {
sudo rm ${workingDir}/saveJiveProperties.sh
wget -O ${workingDir}/saveJiveProperties.sh ${saveJivePropertiesURL}
chmod a+x ${workingDir}/saveJiveProperties.sh
}
function determineLocalDatabase() {
cat ${jiveStartup} | grep serverURL | sed -e 's/.*5432\///' -e 's/<.*$//g'
}
function populateSaveJiveProperties() {
localDatabase=$(determineLocalDatabase)
sed -i "s/\*DATABASE_NAME\*/${localDatabase}/" ${workingDir}/saveJiveProperties.sh
sed -i "s|\*MIGRATION_DIRECTORY\*|${workingDir}|" ${workingDir}/saveJiveProperties.sh
sed -i "s/\*OUTPUT_FILENAME\*/preservedProperties.sql/" ${workingDir}/saveJiveProperties.sh
}
function runSaveJiveProperties() {
saveJiveProperties
populateSaveJiveProperties
chmod +x ${workingDir}/saveJiveProperties.sh
${workingDir}/saveJiveProperties.sh
}
function dropExistingDatabase() {
localDatabase=$(determineLocalDatabase)
psql -U postgres -c "drop database ${localDatabase}"
}
function reCreateExistingDatabase() {
localDatabase=$(determineLocalDatabase)
psql -U postgres -c "create database ${localDatabase}"
psql -U postgres -c "ALTER DATABASE ${localDatabase} OWNER to ${localDatabase}"
psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE ${localDatabase} to ${localDatabase}"
psql -U postgres ${localDatabase} -c "DROP LANGUAGE plpgsql CASCADE"
}
function shutdownJive() {
/etc/init.d/jive-application stop
/etc/init.d/jive-eae-service stop
}
function restoreJiveProperties() {
localDatabase=$(determineLocalDatabase)
psql -U postgres ${localDatabase} < ${workingDir}/preservedProperties.sql
}
function cleanLocalCache() {
rm -rf /usr/local/jive/var/work/${localAppName}
rm -f /usr/local/jive/applications/${localAppName}/home/attachments/*.txt
rm -f /usr/local/jive/applications/${localAppName}/home/attachments/cache/*
rm -f /usr/local/jive/applications/${localAppName}/home/images/*.bin
rm -f /usr/local/jive/applications/${localAppName}/home/images/cache/*
rm -f /usr/local/jive/applications/${localAppName}/home/documents/*
rm -f /usr/local/jive/applications/${localAppName}/home/documents/cache/*
rm -f /usr/local/jive/applications/${localAppName}/home/cache/jiveSBS/*
rm -rf /usr/local/jive/applications/${localAppName}/home/jms/*
}
function configureRegistrationDomains() {
localDatabase=$(determineLocalDatabase)
psql -U postgres ${localDatabase} -c"select jive_setProperty('registration.domainRestriction.domains', '${customerEmailDomains}');"
}
function configureSkyHook() {
localDatabase=$(determineLocalDatabase)
psql -U postgres ${localDatabase} -c"select jive_setProperty('services.skyhook.host', 'directory-service.s1phx1.jivehosted.com');"
psql -U postgres ${localDatabase} -c"select jive_setProperty('services.skyhook.port','20000' );"
}
function cloneDatabase() {
localDatabase=$(determineLocalDatabase)
ssh -oServerAliveInterval=300 -i ~/.ssh/id_rsa_marburg ${ec2RemoteUser}@${ec2RemoteVM} "${ec2RemotePgDump} ${ec2RemoteDB} | ${compression}" | ${uncompression} | psql -U ${localDatabase} ${localDatabase}
}
function deletePlugins() {
localDatabase=$(determineLocalDatabase)
psql -U postgres ${localDatabase} -c "delete from jiveplugin;"
}
function saveUpgradeJsh() {
wget -O ${workingDir}/upgrade.sh ${upgradeJshURL}
}
function resetCrypto() {
localDatabase=$(determineLocalDatabase)
psql -U postgres ${localDatabase} -c "delete from jiveproperty where name='jive.master.encryption.key.node';"
psql -U postgres ${localDatabase} -c "delete from jiveproperty where name='jive.master.eae.key.node';"
rm -f /usr/local/jive/applications/${localAppName}/home/crypto/*
}
function runJshUpgradeTasks() {
saveUpgradeJsh
echo "load('${workingDir}/upgrade.sh');" | sudo -u jive /usr/local/jive/bin/jsh/jsh --no-copy --java /usr/local/jive/java --webapp /usr/local/jive/applications/sbs/application --jive-home /usr/local/jive/applications/sbs/home --tomcatlib /usr/local/jive/tomcat/lib
}
function resetAdminPassword() {
localDatabase=$(determineLocalDatabase)
psql -U postgres ${localDatabase} -c "UPDATE jiveUser SET passwordhash='88495fc3f8a256fcacf5403224d45cb57b0a5a6b966af25d68e5011527933b73', creationdate=1222816186405 where userid=1;"
psql -U postgres ${localDatabase} -c "update jiveuser set status=6,userenabled=1 where userid=1;"
psql -U postgres ${localDatabase} -c "UPDATE jiveGrantedPermLvl SET permlevelid = 7 WHERE permlevelId = 99 ;"
psql -U postgres ${localDatabase} -c "select jive_setProperty('jive.entitlement.sync.completed', 'false') ;"
psql -U postgres ${localDatabase} -c "INSERT INTO jiveEntitlement (entitlementID, objectType, objectID, contentType, userID, groupID, entitlementMask, creationDate, modificationDate) VALUES ((SELECT id+1 FROM jiveID WHERE idtype=360), -2, -6, 6000, (SELECT userid FROM jiveUser WHERE username='admin'), -1, 11, 0, 0);"
psql -U postgres ${localDatabase} -c "INSERT INTO jiveEntitlement (entitlementID, objectType, objectID, contentType, userID, groupID, entitlementMask, creationDate, modificationDate) VALUES ((SELECT id+1 FROM jiveID WHERE idtype=360), -2, -6, 6000, (SELECT userid FROM jiveUser WHERE username='jive-admin'), -1, 11, 0, 0);"
psql -U postgres ${localDatabase} -c "UPDATE jiveId SET id=id+2 WHERE idtype=360"
}
shutdownJive
runSaveJiveProperties
dropExistingDatabase
reCreateExistingDatabase
writeLocalMarburgKey
cloneDatabase
restoreJiveProperties
deletePlugins
resetCrypto
resetAdminPassword
cleanLocalCache
configureRegistrationDomains
configureSkyHook
runJshUpgradeTasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment