-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpkg_automation.bash
More file actions
226 lines (186 loc) · 5.31 KB
/
pkg_automation.bash
File metadata and controls
226 lines (186 loc) · 5.31 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/bash
#
# Copyright (c) 2014 - 2017 Jeong Han Lee
#
# The program is free software: you can redistribute
# it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 2 of the
# License, or any newer version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see https://www.gnu.org/licenses/gpl-2.0.txt
#
#
# Author : Jeong Han Lee
# email : jeonghan.lee@gmail.com
# Date : Sunday, November 19 19:38:09 CET 2017
# version : 0.9.6
#
# - 0.0.1 December 1 00:01 KST 2014, jhlee
# * created
# - 0.9.0 Monday, September 25 22:28:18 CEST 2017, jhlee
# * completely rewrite...
# - 0.9.1 Tuesday, September 26 09:49:56 CEST 2017, jhlee
# * first release
# - 0.9.2
# * added Development tools for CentOS
# - 0.9.3
# * add tclx for require
# - 0.9.4
# * Debian 9 support
# - 0.9.5
# * tune CentOS pkgs - first epel-release
# - 0.9.6
# * add Ubuntu 16/17 supports
#
declare -gr SC_SCRIPT="$(realpath "$0")"
declare -gr SC_SCRIPTNAME=${0##*/}
declare -gr SC_TOP="$(dirname "$SC_SCRIPT")"
declare -gr SUDO_CMD="sudo"
. ${SC_TOP}/functions
function find_dist() {
local dist_id dist_cn dist_rs PRETTY_NAME
if [[ -f /usr/bin/lsb_release ]] ; then
dist_id=$(lsb_release -is)
dist_cn=$(lsb_release -cs)
dist_rs=$(lsb_release -rs)
echo $dist_id ${dist_cn} ${dist_rs}
else
eval $(cat /etc/os-release | grep -E "^(PRETTY_NAME)=")
echo ${PRETTY_NAME}
fi
}
function pkg_list()
{
local i
let i=0
while IFS= read -r line_data; do
if [ "$line_data" ]; then
# Skip command #
[[ "$line_data" =~ ^#.*$ ]] && continue
packagelist[i]="${line_data}"
((++i))
fi
done < $1
echo ${packagelist[@]}
}
function install_pkg_deb()
{
declare -a pkg_list=${1}
printf "\n\n";
printf "$pkg_list\n";
printf "\n\n"
${SUDO_CMD} apt-get update
${SUDO_CMD} apt-get -y install ${pkg_list};
}
function install_pkg_rpm()
{
declare -a pkg_list=${1}
printf "\n";
printf "$pkg_list\n";
printf "\n\n\n"
declare -r yum_pid="/var/run/yum.pid"
${SUDO_CMD} systemctl stop packagekit
${SUDO_CMD} systemctl disable packagekit
# Somehow, yum is running due to PackageKit, so if so, kill it
#
if [[ -e ${yum_pid} ]]; then
${SUDO_CMD} kill -9 $(cat ${yum_pid})
if [ $? -ne 0 ]; then
printf "Remove the orphan yum pid\n";
${SUDO_CMD} rm -rf ${yum_pid}
fi
fi
${SUDO_CMD} yum -y remove PackageKit motif-devel;
${SUDO_CMD} yum update;
${SUDO_CMD} yum -y groupinstall "Development tools"
${SUDO_CMD} yum -y install "epel-release"
${SUDO_CMD} yum update;
${SUDO_CMD} yum -y install ${1};
}
function yes_or_no_to_go() {
printf "\n";
printf ">>>> $1\n";
read -p ">>>> Do you want to continue (y/n)? " answer
case ${answer:0:1} in
y|Y )
printf ">>>> The following pakcages will be installed ...... ";
;;
* )
printf "Stop here.\n";
exit;
;;
esac
}
declare -a PKG_DEB_ARRAY
declare -a PKG_DEB9_ARRAY
declare -a PKG_UBU16_ARRAY
declare -a PKG_RPM_ARRAY
declare -g COM_PATH=${SC_TOP}/pkg-common
declare -g DEB_PATH=${SC_TOP}/pkg-deb
declare -g DEB9_PATH=${SC_TOP}/pkg-deb9
declare -g UBU16_PATH=${SC_TOP}/pkg-ubu16
declare -g RPM_PATH=${SC_TOP}/pkg-rpm
declare -ga pkg_deb_list
declare -ga pkg_deb9_list
declare -ga pkg_ubu16_list
declare -ga pkg_rpm_list
pkg_deb_list=("epics" "ess")
pkg_deb9_list=("epics" "ess")
pkg_ubu16_list=("epics" "ess")
pkg_rpm_list=("epics" "ess")
PKG_DEB_ARRAY=$(pkg_list ${COM_PATH}/common)
for deb_file in ${pkg_deb_list[@]}; do
PKG_DEB_ARRAY+=" ";
PKG_DEB_ARRAY+=$(pkg_list "${DEB_PATH}/${deb_file}");
done
PKG_DEB9_ARRAY=$(pkg_list ${COM_PATH}/common)
for deb_file in ${pkg_deb9_list[@]}; do
PKG_DEB9_ARRAY+=" ";
PKG_DEB9_ARRAY+=$(pkg_list "${DEB9_PATH}/${deb_file}");
done
PKG_UBU16_ARRAY=$(pkg_list ${COM_PATH}/common)
for deb_file in ${pkg_ubu16_list[@]}; do
PKG_UBU16_ARRAY+=" ";
PKG_UBU16_ARRAY+=$(pkg_list "${UBU16_PATH}/${deb_file}");
done
PKG_RPM_ARRAY=$(pkg_list ${COM_PATH}/common)
for rpm_file in ${pkg_rpm_list[@]}; do
PKG_RPM_ARRAY+=" ";
PKG_RPM_ARRAY+=$(pkg_list "${RPM_PATH}/${rpm_file}");
done
dist=$(find_dist)
case "$dist" in
*jessie*)
yes_or_no_to_go "Debian jessie is detected as $dist"
install_pkg_deb "${PKG_DEB_ARRAY[@]}"
;;
*stretch*)
yes_or_no_to_go "Debian stretch is detected as $dist"
install_pkg_deb "${PKG_DEB9_ARRAY[@]}"
;;
*CentOS*)
yes_or_no_to_go "CentOS is detected as $dist";
install_pkg_rpm "${PKG_RPM_ARRAY[@]}"
;;
*xenial*)
yes_or_no_to_go "Ubuntu xenial is detected as $dist";
install_pkg_deb "${PKG_UBU16_ARRAY[@]}"
;;
*artful*)
yes_or_no_to_go "Ubuntu artful is detected as $dist";
install_pkg_deb "${PKG_UBU16_ARRAY[@]}"
;;
*)
printf "\n";
printf "Doesn't support the detected $dist\n";
printf "Please contact jeonghan.lee@gmail.com\n";
printf "\n";
;;
esac
exit 0;