-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart.sh
More file actions
136 lines (118 loc) · 3.4 KB
/
start.sh
File metadata and controls
136 lines (118 loc) · 3.4 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
#
# This is a rather minimal example Argbash potential
# Example taken from http://argbash.readthedocs.io/en/stable/example.html
#
# ARG_OPTIONAL_BOOLEAN([provision],[],[Update vagrant])
# ARG_OPTIONAL_BOOLEAN([pull],[],[Update source code])
# ARG_POSITIONAL_SINGLE([action],[Start : Start vagrant, Halt : Shutdown vagrant],[])
# ARG_HELP([The general script's help msg])
# ARGBASH_GO()
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY Argbash v2.5.1 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, see https://argbash.io for more info
# Generated online by https://argbash.io/generate
die()
{
local _ret=$2
test -n "$_ret" || _ret=1
test "$_PRINT_HELP" = yes && print_help >&2
echo "$1" >&2
exit ${_ret}
}
begins_with_short_option()
{
local first_option all_short_options
all_short_options='h'
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}
# THE DEFAULTS INITIALIZATION - POSITIONALS
_positionals=()
# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_provision=off
_arg_pull=off
print_help ()
{
printf "%s\n" "The general script's help msg"
printf 'Usage: %s [--(no-)provision] [--(no-)pull] [-h|--help] <action>\n' "$0"
printf "\t%s\n" "<action>: start: Start vagrant, stop: Shutdown vagrant, restart: Restart vagrant, destroy: Destroy vagrant"
printf "\t%s\n" "--provision,--no-provision: Update vagrant (off by default)"
printf "\t%s\n" "--pull,--no-pull: Update source code (off by default)"
printf "\t%s\n" "-h,--help: Prints help"
}
parse_commandline ()
{
while test $# -gt 0
do
_key="$1"
case "$_key" in
--no-provision|--provision)
_arg_provision="on"
test "${1:0:5}" = "--no-" && _arg_provision="off"
;;
--no-pull|--pull)
_arg_pull="on"
test "${1:0:5}" = "--no-" && _arg_pull="off"
;;
-h|--help)
print_help
exit 0
;;
-h*)
print_help
exit 0
;;
*)
_positionals+=("$1")
;;
esac
shift
done
}
handle_passed_args_count ()
{
_required_args_string="'action'"
test ${#_positionals[@]} -ge 1 || _PRINT_HELP=yes die "FATAL ERROR: Not enough positional arguments - we require exactly 1 (namely: $_required_args_string), but got only ${#_positionals[@]}." 1
test ${#_positionals[@]} -le 1 || _PRINT_HELP=yes die "FATAL ERROR: There were spurious positional arguments --- we expect exactly 1 (namely: $_required_args_string), but got ${#_positionals[@]} (the last one was: '${_positionals[*]: -1}')." 1
}
assign_positional_args ()
{
_positional_names=('_arg_action' )
for (( ii = 0; ii < ${#_positionals[@]}; ii++))
do
eval "${_positional_names[ii]}=\${_positionals[ii]}" || die "Error during argument parsing, possibly an Argbash bug." 1
done
}
parse_commandline "$@"
handle_passed_args_count
assign_positional_args
# OTHER STUFF GENERATED BY Argbash
### END OF CODE GENERATED BY Argbash (sortof) ### ])
# [ <-- needed because of Argbash
if [ "$_arg_pull" = on ]
then
git pull
fi
if [ "$_arg_provision" = on ]
then
vagrant up
vagrant provision
fi
if [ "$_arg_action" = start ]
then
vagrant up
elif [ "$_arg_action" = stop ]
then
vagrant halt
elif [ "$_arg_action" = restart ]
then
vagrant reload
elif [ "$_arg_action" = destroy ]
then
vagrant destroy
else
echo "Error: Value can only be start, stop, restart or destroy."
fi
# ] <-- needed because of Argbash