-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpackage_tool
executable file
·136 lines (121 loc) · 2.47 KB
/
package_tool
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
usage()
{
echo ${0}:
echo " --no_packages: value 0 install packages, value 1 do not. Check is here"
echo " so the test wrappers do not have to constantly do the check."
echo " --packages: comma separated list of packages to install"
echo " --update: Update the system."
echo " --usage: This usage message."
exit 1
}
exit_out()
{
echo $1
exit $2
}
update=0
install_cmd=""
is_installed=""
packages=""
remove_packages=""
ARGUMENT_LIST=(
"is_installed"
"no_packages"
"packages"
"remove_packages"
)
NO_ARGUMENTS=(
"update"
"usage"
)
# read arguments
opts=$(getopt \
--longoptions "$(printf "%s:," "${ARGUMENT_LIST[@]}")" \
--longoptions "$(printf "%s," "${NO_ARGUMENTS[@]}")" \
--name "$(basename "$0")" \
--options "h" \
-- "$@"
)
eval set --$opts
while [[ $# -gt 0 ]]; do
case "$1" in
--is_installed)
is_installed=$2
shift 2
;;
--no_packages)
if [[ $2 == "1" ]]; then
exit 0
fi
shift 2
;;
--packages)
packages=$2
shift 2
;;
--remove_packages)
remove_packages=$2
shift 2
;;
--update)
update=1
shift 1
;;
--usage)
usage $0
;;
-h)
usage $0
;;
--)
break
;;
*)
echo option not found $1
usage $0
;;
esac
done
install_cmd=""
case "`test_tools/detect_os`" in
"ubuntu")
install_cmd="/bin/apt"
;;
*)
if [[ -f "/bin/dnf" ]]; then
install_cmd="/bin/dnf"
elif [[ -f "/bin/yum" ]]; then
install_cmd="/bin/yum"
fi
;;
esac
if [[ $install_cmd == "" ]]; then
exit_out "package_install: Do not know what to use to install packages with" 1
fi
if [[ $is_installed != "" ]]; then
$install_cmd list installed | grep -q php-cli.x86_64
exit $?
fi
if [[ $remove_packages != "" ]]; then
pkgs_rm=`echo $remove_packages | sed "s/,/ /g"`
$install_cmd remove -y $remove_packages
if [ $? -ne 0 ]; then
exit_out "Failed to remove $packages" 1
fi
fi
if [ $update -ne 0 ]; then
$install_cmd update -y
if [ $? -ne 0 ]; then
exit_out "$install_cmd update failed" 1
fi
fi
if [[ $packages != "" ]]; then
package_list=`echo ${packages} | sed "s/,/ /g"`
for package in $package_list; do
$install_cmd install -y $package
if [ $? -ne 0 ]; then
exit_out "$install_cmd install of $package failed" 1
fi
done
fi