File: sync-oci-code

package info (click to toggle)
openstack-cluster-installer 43.0.18
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,484 kB
  • sloc: php: 19,127; sh: 18,142; ruby: 75; makefile: 31; xml: 8
file content (84 lines) | stat: -rwxr-xr-x 2,954 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh

set -e
#set -x

if [ -z "${1}" ] ; then
	echo "Missing destination host"
	exit 1
elif [ "${1}" = "-h" ] || [ "${1}" = "--help" ]; then
	echo "${0} <puppet-master>"
	exit 0
fi

DEST_OCI=${1}
shift

MY_NAME=$(basename $0)

echo "===> Checking remote last SHA"
ssh root@${DEST_OCI} "mkdir -p /root/oci-last-sha"
REMOTE_LAST_SHA=$(ssh root@${DEST_OCI} "ls -rt /root/oci-last-sha | tail -n 1")
LOCAL_LAST_SHA=$(git log | head -n 1 | cut -d' ' -f2)

if [ -n "${REMOTE_LAST_SHA}" ] ; then
	if [ "${REMOTE_LAST_SHA}" != "${LOCAL_LAST_SHA}" ] ; then
		echo "*** Display the diff between local code and remote OCI (y/N)?"
		read DISPLAY_DIFF
		if [ "${DISPLAY_DIFF}" = "y" ] || [ "${DISPLAY_DIFF}" = "Y" ] ; then
			git diff -u -r "${REMOTE_LAST_SHA}" -r "${LOCAL_LAST_SHA}"
		fi
	fi
fi

echo "*** WARNING: THIS WILL REPLACE FILES IN $DEST_OCI ***"
echo -n "Are you sure $DEST_OCI is the correct hostname (y/N)?"
read CONFIRM
if [ "${CONFIRM}" != "y" ] && [ "${CONFIRM}" != "Y" ] ; then
	echo "Did not confirm: exiting"
	exit 1
fi

# Adding the new SHA
ssh root@${DEST_OCI} "touch /root/oci-last-sha/${LOCAL_LAST_SHA}"

echo "===========> Syncing PHP code <==========="
cd src
tar -czf php.tar.gz *.php *.json inc
echo "===> Copying PHP to ${DEST_OCI}"
scp php.tar.gz root@${DEST_OCI}:
rm php.tar.gz
cd ..
echo "===> Extracting PHP in OCI"
ssh -A root@${DEST_OCI} "cd /usr/share/openstack-cluster-installer ; tar -xzf /root/php.tar.gz ; rm /root/php.tar.gz"

echo "===> Synching db"
ssh -A root@${DEST_OCI} "php /usr/share/openstack-cluster-installer/db_sync.php"

echo "===========> Syncing Puppet code <==========="
echo "===> Making Puppet manifests tarball"
cd puppet
tar -czf puppet.tar.gz files manifests lib templates
echo "===> Copying Puppet code to ${DEST_OCI}"
scp puppet.tar.gz root@${DEST_OCI}:
rm puppet.tar.gz
echo "===> Extracting Puppet code in OCI"
ssh -A root@${DEST_OCI} "cd /usr/share/puppet/modules/oci ; tar -xzf /root/puppet.tar.gz ; rm /root/puppet.tar.gz"
echo "===> Restarting puppet-master / puppetserver"
ssh -A root@${DEST_OCI} "if [ -e /etc/init.d/puppet-master ] ; then /etc/init.d/puppet-master restart ; elif [ -e /lib/systemd/system/puppetserver.service ] ; then systemctl restart puppetserver ; fi"
cd ..

echo "===========> Syncing shell scripts <==========="
echo "===> Making bin shell scripts tarball"
tar -czf bin.tar.gz bin
echo "===> Copying bin shell scripts to ${DEST_OCI}"
scp bin.tar.gz root@${DEST_OCI}:
rm bin.tar.gz
echo "===> Extracting bin shell scripts in OCI"
ssh -A root@${DEST_OCI} "tar -xzf bin.tar.gz ; cd bin ; chown -R root:root . ; chmod -R 755 . ; cp ./* /usr/bin ; cd ~ ; rm -r bin bin.tar.gz ;"

echo "===========> Syncing ocicli and auto-complete <==========="
scp ocicli/ocicli root@${DEST_OCI}:/usr/bin
scp ocicli/completions/ocicli root@${DEST_OCI}:/usr/share/bash-completion/completions
ssh root@${DEST_OCI} "mkdir -p /etc/ocicli"
scp src/variables.json root@${DEST_OCI}:/etc/ocicli/