-
Notifications
You must be signed in to change notification settings - Fork 4
/
cb.sh
executable file
·105 lines (81 loc) · 2.41 KB
/
cb.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
#!/bin/bash
#########################################################################
# Title: Cloudbox Script #
# Author(s): desimaniac, chazlarson #
# URL: https://github.com/cloudbox/cb #
# -- #
# Part of the Cloudbox project: https://cloudbox.works #
#########################################################################
# GNU General Public License v3.0 #
#########################################################################
# Restart script in SUDO
# https://unix.stackexchange.com/a/28793
if [ $EUID != 0 ]; then
sudo "$0" "$@"
exit $?
fi
# Variables
CLOUDBOX_REPO="/srv/git/cloudbox"
function git_fetch_and_reset () {
git fetch --quiet >/dev/null
git clean --quiet -df >/dev/null
git reset --quiet --hard @{u} >/dev/null
git checkout --quiet develop >/dev/null
git clean --quiet -df >/dev/null
git reset --quiet --hard @{u} >/dev/null
}
function ansible_playbook() {
arg=("$@")
cd "${CLOUDBOX_REPO}"
'/usr/local/bin/ansible-playbook' \
${CLOUDBOX_REPO}/cloudbox.yml \
--become \
--tags ${arg}
cd - >/dev/null
}
function update () {
local OLD_COMMIT
local NEW_COMMIT
echo -e "Updating Cloudbox...\n"
cd "${CLOUDBOX_REPO}"
OLD_COMMIT=$(git rev-parse --short HEAD)
git_fetch_and_reset
NEW_COMMIT=$(git rev-parse --short HEAD)
if [ "$OLD_COMMIT" != "$NEW_COMMIT" ]; then
ansible_playbook "settings"
fi
echo -e "\nUpdating Complete."
}
role="" # Default to empty package
target="" # Default to empty target
# Parse options to the `pip` command
while getopts ":h" opt; do
case ${opt} in
h )
echo "Usage:"
echo " cb -h Display this help message."
echo " cb install <package> Install <package>."
echo " cb update Update local cloudbox files"
exit 0
;;
\? )
echo "Invalid Option: -$OPTARG" 1>&2
exit 1
;;
esac
done
shift $((OPTIND -1))
subcommand=$1; shift # Remove 'cb' from the argument list
case "$subcommand" in
# Parse options to the various sub commands
update)
update
;;
install)
role=${@}
ansible_playbook "${role}"
;;
*)
echo "hello"
;;
esac