forked from Rhoban/workspace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-env
executable file
·79 lines (69 loc) · 2.11 KB
/
deploy-env
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
#!/bin/bash
MAX_OLD_ENVS=5
CONFIRMATION_SIZE=50000 #Confirmation required to suppress environments larger than this (unit: KB)
FORMAT_RED="\e[31m"
FORMAT_NONE="\e[m"
confirm() {
# call with a prompt string or use a default
read -r -p "${1:-Are you sure? [y/N]} " response
case "$response" in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}
remote="10.0.0.1"
if [ $# -gt 0 ]
then
remote=$1
fi
# Killing server on host
echo "Killing KidSize on $remote"
`ssh rhoban@$remote ./env/stop.sh`
DIR="env"
if [ ! -d $DIR ]; then
echo "! Environments is not installed"
else
cd env
# Cleaning old environents
ROBOT=`ssh rhoban@$remote hostname`
ENVS=`ssh rhoban@$remote ls -Ahdc ./backup_env/* | sort -r`
K=0
if [ "$ENVS" == "" ]
then
ssh rhoban@$remote mkdir backup_env
fi;
for E in $ENVS; do
K=$[$K+1]
if [ $K -gt $MAX_OLD_ENVS ]; then
E_SIZE=( $(ssh rhoban@$remote du -s $E) )
E_SIZE=${E_SIZE[0]}
if [ $E_SIZE -gt $CONFIRMATION_SIZE ]; then
HUMAN_SIZE=( $(ssh rhoban@$remote du -sh $E) )
HUMAN_SIZE=${HUMAN_SIZE[0]}
echo -e "${FORMAT_RED}WARNING: $E contains $HUMAN_SIZE of data, not removing it${FORMAT_NONE}"
continue
fi
echo "* Removing old environment $E with size ${E_SIZE}"
ssh rhoban@$remote rm -rf $E
fi
done
# Archiving current environment
echo "* Retrieving current env date"
CHG=`ssh rhoban@$remote stat -c %y ./env/`
if [ "$CHG" != "" ]; then
DATE=`date -d "$CHG" "+%Y_%m_%d__%H_%M_%S"`
OLDNAME="backup_env/$DATE"
echo "* Backuping old env to $OLDNAME"
`ssh rhoban@$remote mv env $OLDNAME`
fi
# Sending current environment
echo "* Sending environment files"
TO_COPY=(./strategies ./$ROBOT ./common ./boot.sh ./stop.sh ./out.sh ./post_mortem.sh ./rhio_cmd.sh ./demo_scripts)
ssh rhoban@$remote rm -rf env
ssh rhoban@$remote mkdir env
rsync -l -r ${TO_COPY[@]} rhoban@$remote:env/
fi