-
Notifications
You must be signed in to change notification settings - Fork 27
/
deploy
executable file
·121 lines (102 loc) · 3.39 KB
/
deploy
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Deploys an LDM package to a remote system.
PATH=/bin:/usr/bin:/usr/local/bin
set -e
printUsage()
{
cat 1>&2 <<EOF
Usage: `basename $0` [-i] [-M <make>] [-m] [-n] [-r <root>] [-s] [-u <user>] [-v <version>] <host>
Where:
-i Install only: do not throw runtime link and execute
-M <make> Pathname of make(1) utility
-m Enable multicast support
-n Enable NOAAPort support
-r <root> Use account <root> for root privileges -- including use of
sudo(8) -- instead of "root"
-s Use sudo(1)
-u <user> Use account <user> instead of "ldm"
-v <version> Use LDM version <version> instead of first word in CHANGE_LOG
<host> ssh(1)able remote host (e.g., "node0")
EOF
}
unset installOnly
makePath=make
ldmUser=ldm
version=`awk '{print $1; exit}' CHANGE_LOG`
rootUser=root
sudoUser=ldm
while getopts iM:mnr:su:v: opt; do
case $opt in
i) installOnly=true;;
M) makePath=$OPTARG;;
m) withMulticast=true;;
n) withNoaaport=true;;
r) rootUser=$OPTARG
sudoUser=$OPTARG;;
s) useSudo=true;;
u) ldmUser=$OPTARG;;
v) version=$OPTARG;;
*) printUsage
exit 1;;
esac
done
shift `expr $OPTIND - 1`
host=${1:?Host not specified}
ps -fu $LOGNAME | grep 'ssh upc' | grep -v grep >/dev/null && host=$host-r
pkgId=ldm-$version
tarball=$pkgId.tar.gz
echo "Deploying $pkgId to $ldmUser@$host"
scp $tarball $ldmUser@$host:
# ssh(1) is used thrice because some security policies don't allow
# ssh(1)ing to the remote host and then executing su(1) in a here-document.
ssh -x -T $ldmUser@$host bash --login <<EOF
set -e
echo Unpacking
gunzip -c $tarball | pax -r '-s:/:/src/:'
echo Configuring
cd $pkgId/src/
./configure --disable-root-actions --enable-debug \
${withMulticast+--with-multicast} ${withNoaaport+--with-noaaport} \
>&configure.log
echo Installing
make install >&install.log
EOF
echo -en '\a'
sleep 1
echo -en '\a'
if test "${useSudo}"; then
echo "Making root actions using account \"$sudoUser\" and sudo(8)"
ssh -x $sudoUser@$host bash --login <<EOF
set -e
cd ~$ldmUser/$pkgId/src
# $sudoUser might not be able to create a file in the current directory
sudo $makePath root-actions >& '/tmp/root-actions-$$.log'
sudo mv '/tmp/root-actions-$$.log' root-actions.log
sudo chown $ldmUser root-actions.log
EOF
else
echo "Making root actions using account '$rootUser'"
ssh -x -T $rootUser@$host bash --login <<EOF
set -e
cd ~$ldmUser/$pkgId/src
$makePath root-actions >&root-actions.log
EOF
fi
if test -z "${installOnly}"; then
ssh -x -T $ldmUser@$host bash --login <<EOF
set -e
if test -e runtime && ldmadmin stop; then
echo "Throwing the runtime switch"
rm runtime
ln -s $pkgId runtime
ldmadmin start
else
echo "LDM wasn't previously installed or isn't running. New installation not started."
rm -f runtime
ln -s $pkgId runtime
fi
# Delete previous versions. NB: THIS SHOULD ONLY BE DONE ON NON-PRODUCTION
# SYSEMS!
#find . \( -name 'ldm-*.gz' -o \( -name 'ldm-*' -type d \) \) \
#! -name $pkgId ! -name $pkgId.tar.gz -print -prune | xargs rm -rf
EOF
fi