summaryrefslogtreecommitdiffstats
path: root/shib_secondary/deploy.sh
blob: 536f22116fa76088cee81a5ad0c8217a9759ff0d (plain) (blame)
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
#!/bin/bash

destination=
domain=
master=
secret=

while (( $# > 0 )); do
	case "$1" in
	--dest*)
		destination="$2"
		shift
		;;
	--domain)
		domain="$2"
		shift
		;;
	--master)
		master="$2"
		shift
		;;
	--secret)
		secret="$2"
		shift
		;;
	*)
		echo "WAAAAT? NO MAHNEEY?"
		exit 1
	esac
	shift
done

if ! [[ $destination =~ ^[a-z0-9_]+@[a-z0-9_.-]+$ ]] \
		|| [ -z "$domain" ] \
		|| [ -z "$secret" ] \
		|| ! [[ "$master" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
	echo "Usage: $0 --dest user@4.5.6.7 --domain foo.bar.example.com --master 1.2.3.4 --secret your_master_secret"
	exit 1
fi

if [[ $destination == root@* ]]; then
	sudo=
else
	echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++"
	echo "Using sudo on the remote server to gain root privs..."
	sudo="sudo "
fi

echo

if ! ssh "$destination" "$sudo rm -rf -- /tmp/shib_deploy"; then
	echo "Remote access for preparation failed :-("
	exit 1
fi

if ! scp -r "$( dirname -- "${BASH_SOURCE[0]}" )/remote" "${destination}:/tmp/shib_deploy"; then
	echo "Copying data to $destination failed"
	exit 1
fi

if ! ssh "$destination" "$sudo /tmp/shib_deploy/install.sh --domain '$domain' --master '$master' --secret '$secret'"; then
	echo "Remote install failed :-("
	exit 1
fi

echo "------------------------------------------------------"
echo
echo "Success"
echo
echo
echo "Remember to make sure the new R/O instance's IP address"
echo "is allowed to pull the data from $master, and added to"
echo "the trusted proxy IP addresses."
echo "(RemoteIPInternalProxy)"
echo