-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinstall.sh.in
More file actions
59 lines (40 loc) · 1.72 KB
/
install.sh.in
File metadata and controls
59 lines (40 loc) · 1.72 KB
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
#!/bin/bash
uuencode=0
binary=1
function untar_payload()
{
match=$(grep --text --line-number '^PAYLOAD:$' $0 | cut -d ':' -f 1)
payload_start=$((match + 1))
if [[ $binary -ne 0 ]]; then
tail -n +$payload_start $0 | tar -C $HOME -xzvf -
fi
if [[ $uuencode -ne 0 ]]; then
tail -n +$payload_start $0 | uudecode | tar -C $HOME -xzvf -
fi
}
function start_cmd {
ruby -ryaml -e 'puts YAML.load(File.read(ARGV[0])).select{ |k,v| k=="start_command" }.collect {|k,v| v }' "$@"
}
untar_payload
# give tmate +x permissions
chmod +x $HOME/bin/tmate
# add lib folder to LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/lib
# generate ssh keys
echo -e 'y\n'|ssh-keygen -q -t rsa -N "" -f /home/vcap/.ssh/id_rsa
$HOME/bin/tmate -S /tmp/tmate.sock new-session -d # Launch tmate in a detached state
$HOME/bin/tmate -S /tmp/tmate.sock wait tmate-ready # Blocks until the SSH connection is established
$HOME/bin/tmate -S /tmp/tmate.sock split-window -v
main_pane=${window}.0
command_pane=${window}.1
sshcmd=`$HOME/bin/tmate -S /tmp/tmate.sock display -p '#{tmate_ssh}'`
sshcmd=${sshcmd:4}
$HOME/bin/tmate -S /tmp/tmate.sock selectp -t 0
start_command=$(start_cmd /home/vcap/staging_info.yml)
$HOME/bin/tmate -S /tmp/tmate.sock send-keys -t "$main_pane" 'stty -echo; ps_orig=`echo $PS1`; PS1=""' Enter
$HOME/bin/tmate -S /tmp/tmate.sock send-keys -t "$main_pane" 'cat $HOME/banner.txt' Enter
$HOME/bin/tmate -S /tmp/tmate.sock send-keys -t "$main_pane" "printf \"$sshcmd\\n\\n\"" Enter
$HOME/bin/tmate -S /tmp/tmate.sock send-keys -t "$main_pane" 'stty echo; PS1="$ps_orig "' Enter
$HOME/bin/tmate -S /tmp/tmate.sock send-keys -t "$command_pane" "$start_command" Enter
printf "%s\n" "$sshcmd"
exit 0