-
Notifications
You must be signed in to change notification settings - Fork 0
/
interactive-install.sh
executable file
·160 lines (126 loc) · 4.55 KB
/
interactive-install.sh
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
#
# Runs deeplearn-server-setup.sh interactively
set -e
if ! [ -d $HOME/aws-instances ]; then
echo "expecting ~/aws-instances to exist"
exit 1
fi
instances=$(find $HOME/aws-instances -maxdepth 1 -mindepth 1 -type d -not -name .deleted -printf '%f,')
if [ -z "$instances" ]; then
echo "no instances in ~/aws-instances available"
exit 1
fi
instances="${instances::-1}"
read -p "choose instance among {$instances}: " instance
if ! [ -d $HOME/aws-instances/$instance ] || [ -z "$instance" ] ; then
echo "invalid choice $instance"
exit 1
fi
if [ $($HOME/aws-instances/$instance/state) != "running" ]; then
echo "instance $instance not running"
exit 1
fi
read -p "git token file location [~/aws-git-token]: " tokenloc
tokenloc=${tokenloc:-$HOME/aws-git-token}
gittoken=$(cat $tokenloc)
if [ -z "$gittoken" ]; then
echo "git token invalid"
exit 1
fi
read -p "twilio token file location [~/.twilio.env]: " tokenloc
twiliotokenloc=${twiliotokenloc:-$HOME/.twilio.env}
twiliotoken=$(cat $twiliotokenloc)
if [ -z "$twiliotoken" ]; then
echo "twilio token invalid"
exit 1
fi
read -p "git pub key name [aws-$instance]: " keyname
keyname=${keyname:-aws-$instance}
read -p "install deep learning deps over regular deps (y/N)?" yn
case "$yn" in
[Yy]* ) INSTALL_DEEP="true" ;;
* ) INSTALL_DEEP="false" ;;
esac
if $INSTALL_DEEP ; then
echo "jupyter server password"
passhash=$(python -c "from notebook.auth import passwd; print(passwd())")
script_for_server=$(dirname $(readlink -f "$0"))/server/server-install-deeplearn.sh
server_invok="~/server-install-deeplearn.sh $passhash $gittoken $keyname $twiliotoken"
else
read -p "pre-kubernetes install script [~/bin/pre-kubernetes.sh]: " prek
prek=${prek:-$HOME/bin/pre-kubernetes.sh}
scp -q -oStrictHostKeyChecking=no -i "$HOME/.ssh/aws-key-$instance.pem" "$prek" ubuntu@$($HOME/aws-instances/$instance/ip):"~/pre-kubernetes.sh"
echo 'copying ~/.aws to server'
scp -r -q -oStrictHostKeyChecking=no -i "$HOME/.ssh/aws-key-$instance.pem" "$HOME/.aws" ubuntu@$($HOME/aws-instances/$instance/ip):~
script_for_server=$(dirname $(readlink -f "$0"))/server/server-install-dev.sh
server_invok="~/server-install-dev.sh $gittoken $keyname"
fi
echo "initiating install (this may take ~5 minutes):"
# TODO wait for ssh here
scp -q -oStrictHostKeyChecking=no -i "$HOME/.ssh/aws-key-$instance.pem" $script_for_server ubuntu@$($HOME/aws-instances/$instance/ip):~
# https://serverfault.com/questions/414341
# https://unix.stackexchange.com/questions/45941
CMD_DIR="$HOME/aws-instances/$instance"
echo '#!/bin/bash
set -e
if [ -z "$1" ]; then
echo missing src "(location copying from docker)"
exit 1
fi
if [ -z "$2" ]; then
echo missing dst "(location copying to on pc)"
exit 1
fi
tempdir=$('"$CMD_DIR/ssh"' mktemp -d)
'"$CMD_DIR/ssh"' sudo docker cp '"'"'$(~/current-image.sh)'"'"'":$1" $tempdir
scp -r -oStrictHostKeyChecking=no -i '"$HOME/.ssh/aws-key-$instance.pem ubuntu@$($HOME/aws-instances/$instance/ip)"':"$tempdir/*" $2
'"$CMD_DIR/ssh"' -t sudo rm -rf $tempdir
' > "$CMD_DIR/dockercp"
chmod +x "$CMD_DIR/dockercp"
echo '#!/bin/bash
set -e
if [ -z "$1" ]; then
echo missing src "(location copying from pc)"
exit 1
fi
if [ -z "$2" ]; then
echo missing dst "(location copying to docker)"
exit 1
fi
tempdir=$('"$CMD_DIR/ssh"' mktemp -d)
scp -r -q -oStrictHostKeyChecking=no -i '"$HOME/.ssh/aws-key-$instance.pem"' "$1" '"ubuntu@$($HOME/aws-instances/$instance/ip)"':"$tempdir"
'"$CMD_DIR/ssh"' sudo docker cp "$tempdir/*" '"'"'$(~/current-image.sh)'"'"'":$2"
'"$CMD_DIR/ssh"' -t sudo rm -rf $tempdir
' > "$CMD_DIR/cpdocker"
chmod +x "$CMD_DIR/cpdocker"
echo '#!/bin/bash
set -e
if [ -z "$1" ]; then
echo missing src "(location copying from aws)"
exit 1
fi
if [ -z "$2" ]; then
echo missing dst "(location copying to on pc)"
exit 1
fi
scp -r -oStrictHostKeyChecking=no -i '"$HOME/.ssh/aws-key-$instance.pem ubuntu@$($HOME/aws-instances/$instance/ip)"':"$1" "$2"
'"$CMD_DIR/ssh"' -t sudo rm -rf $tempdir
' > "$CMD_DIR/cpfrom"
chmod +x "$CMD_DIR/cpfrom"
echo '#!/bin/bash
set -e
if [ -z "$1" ]; then
echo missing src "(location copying from aws)"
exit 1
fi
if [ -z "$2" ]; then
echo missing dst "(location copying to on pc)"
exit 1
fi
scp -r -oStrictHostKeyChecking=no -i '"$HOME/.ssh/aws-key-$instance.pem"' "$1" '"ubuntu@$($HOME/aws-instances/$instance/ip)"':"$2"
'"$CMD_DIR/ssh"' -t sudo rm -rf $tempdir
' > "$CMD_DIR/cpto"
chmod +x "$CMD_DIR/cpto"
$CMD_DIR/ssh -t "bash $server_invok 2>&1 | tee /tmp/install-out"
# TODO wait for ssh here