-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·59 lines (50 loc) · 1.66 KB
/
setup.sh
File metadata and controls
executable file
·59 lines (50 loc) · 1.66 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
declare -A REQUIRED_KEYS=(
[APP_ALIAS]=$(cat .env | grep "^APP_ALIAS=.*" | cut -d= -f2)
[APP_CONTAINER_NAME]=$(cat .env | grep "^APP_CONTAINER_NAME=.*" | cut -d= -f2)
)
for key in ${!REQUIRED_KEYS[@]}; do
value=${REQUIRED_KEYS[$key]}
if [[ -z $value ]]; then
echo "Missing $key" >> /dev/stderr
exit 1
fi
done
declare -r DESTINATION_FILE=/usr/local/bin/${REQUIRED_KEYS[APP_ALIAS]}
case $1 in
--purge|--remove)
if [[ -e $DESTINATION_FILE ]]; then
rm $DESTINATION_FILE
echo "File $DESTINATION_FILE has been removed"
fi
exit
;;
--reload)
$0 --purge >> /dev/null
$0 >> /dev/null
echo "File $DESTINATION_FILE has been reloaded"
exit
;;
esac
if [[ -e $DESTINATION_FILE ]]; then
echo "File $DESTINATION_FILE already exists, Do you want to overwrite it? [Yes/No]"
read answer
case $answer in
y|Y|yes|Yes|YES)
rm $DESTINATION_FILE
echo "File $DESTINATION_FILE has been removed"
;;
*)
echo "File $DESTINATION_FILE already exists, remove the file first then run this script again" >> /dev/stderr
exit 2;
;;
esac
fi
STUB=$(cat stub.sh | sed "s/APP_CONTAINER_NAME/${REQUIRED_KEYS[APP_CONTAINER_NAME]}/g")
echo "$STUB" >> $DESTINATION_FILE
chmod a+x $DESTINATION_FILE
echo "File $DESTINATION_FILE has been created"
completion="complete -W \"$(./stub.sh --commands)\" ${REQUIRED_KEYS[APP_ALIAS]}"
completion_file=~/.${REQUIRED_KEYS[APP_ALIAS]}.sh
echo $completion > $completion_file
grep -q "^. $completion_file$" ~/.zshrc || echo -e ". $completion_file\n" >> ~/.zshrc