-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsceptrefun
executable file
·101 lines (84 loc) · 2.42 KB
/
sceptrefun
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
#!/usr/bin/env bash
realpath() {
python -c "import os,sys; print(os.path.realpath(sys.argv[1]))" "$0"
}
BASEDIR="$(dirname "$(dirname "$(realpath "$0")")")"
SCEPTRE_HIJACK=$(which sceptre)
AFPLAY_OPTS=( -v "${VOLUME:-0.2}" )
ARGTOTAL=3
SCEPTRE_ACTION=$1
SCEPTRE_ENV=$2
SCEPTRE_STACK=$3
CHANGE_SET=$4
SCEPTRE_THEME_DEFAULT="orc"
SCEPTRE_THEME=${SCEPTRE_THEME-$SCEPTRE_THEME_DEFAULT}
if [ ! -d "$BASEDIR/assets/$SCEPTRE_THEME" ]; then
echo -e '\033[1;33m'"'$SCEPTRE_THEME' theme does not exist, will use default '$SCEPTRE_THEME_DEFAULT' theme" '\033[0m'
SCEPTRE_THEME=$SCEPTRE_THEME_DEFAULT
fi
SCEPTRE_UPGRADE_STACK="$BASEDIR/assets/$SCEPTRE_THEME/jobupdate.mp3"
SCEPTRE_DELETE_STACK="$BASEDIR/assets/$SCEPTRE_THEME/jobdelete.mp3"
SCEPTRE_SUCCESS="$BASEDIR/assets/$SCEPTRE_THEME/jobdone.mp3"
SCEPTRE_FAIL="$BASEDIR/assets/$SCEPTRE_THEME/jobfail.mp3"
SCEPTRE_INIT="$BASEDIR/assets/$SCEPTRE_THEME/jobinit.mp3"
MISSINGARGS="$BASEDIR/assets/$SCEPTRE_THEME/missingargs.mp3"
TRAPC="$BASEDIR/assets/$SCEPTRE_THEME/trapc.mp3"
trap trapctrlc SIGINT
trapctrlc() {
afplay "${AFPLAY_OPTS[@]}" "$TRAPC"
echo -e '\033[1;33m'"$USER has left the game" '\033[0m'
exit 1
}
REGEX="^.*-env$"
if [[ "$SCEPTRE_ACTION" =~ $REGEX ]]
then
if [[ $SCEPTRE_ACTION == "delete-env" ]]
then
SCEPTRE_INIT=$SCEPTRE_DELETE_STACK
fi
afplay "${AFPLAY_OPTS[@]}" "$SCEPTRE_INIT"
if "$SCEPTRE_HIJACK" "$SCEPTRE_ACTION" "$SCEPTRE_ENV";
then
afplay "${AFPLAY_OPTS[@]}" "$SCEPTRE_SUCCESS"
exit 0
else
afplay "${AFPLAY_OPTS[@]}" "$SCEPTRE_FAIL"
exit 1
fi
fi
if [[ "$SCEPTRE_ACTION" == "create-change-set" || "$SCEPTRE_ACTION" == "describe-change-set" ]]
then
ARGTOTAL=$((ARGTOTAL + 1))
afplay "${AFPLAY_OPTS[@]}" "$SCEPTRE_INIT"
if "$SCEPTRE_HIJACK" "$SCEPTRE_ACTION" "$SCEPTRE_ENV" "$SCEPTRE_STACK" "$CHANGE_SET";
then
afplay "${AFPLAY_OPTS[@]}" "$SCEPTRE_SUCCESS"
exit 0
else
afplay "${AFPLAY_OPTS[@]}" "$SCEPTRE_FAIL"
exit 1
fi
fi
case $SCEPTRE_ACTION in
update-stack|update-stack-cs)
SCEPTRE_SUCCESS=$SCEPTRE_UPGRADE_STACK
CHANGE_SET=""
;;
delete-stack)
SCEPTRE_INIT=$SCEPTRE_DELETE_STACK
;;
esac
if [[ $# -ne "$ARGTOTAL" ]];
then
echo "Missing/too many parameters"
afplay "${AFPLAY_OPTS[@]}" "$MISSINGARGS"
exit 1
fi
afplay "${AFPLAY_OPTS[@]}" "$SCEPTRE_INIT"
if "$SCEPTRE_HIJACK" "$SCEPTRE_ACTION" "$SCEPTRE_ENV" "$SCEPTRE_STACK";
then
afplay "${AFPLAY_OPTS[@]}" "$SCEPTRE_SUCCESS"
else
afplay "${AFPLAY_OPTS[@]}" "$SCEPTRE_FAIL"
exit 1
fi