This repository has been archived by the owner on Aug 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
aa_init.bash
152 lines (121 loc) · 4.24 KB
/
aa_init.bash
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
#!/bin/bash
#
# Copyright (c) 2016 Jeong Han Lee
# Copyright (c) 2016 European Spallation Source ERIC
#
# 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 : han.lee@esss.se
# Date : Monday, November 7 13:10:41 CET 2016
# version : 0.1.4
#
#
# Generic : Global variables - read-only
#
declare -gr SC_SCRIPT="$(realpath "$0")"
declare -gr SC_SCRIPTNAME="$(basename "$SC_SCRIPT")"
declare -gr SC_TOP="$(dirname "$SC_SCRIPT")"
declare -gr SC_LOGDATE="$(date +%Y%b%d-%H%M-%S%Z)"
# Generic : Redefine pushd and popd to reduce their output messages
#
function pushd() { builtin pushd "$@" > /dev/null; }
function popd() { builtin popd "$@" > /dev/null; }
function __ini_func() { printf "\n>>>> You are entering in : %s\n" "${1}"; }
function __end_func() { printf "\n<<<< You are leaving from : %s\n" "${1}"; }
function __checkstr() {
if [ -z "$1" ]; then
printf "%s : input variable is not defined \n" "${FUNCNAME[*]}"
exit 1;
fi
}
declare -gr SUDO_CMD="sudo";
declare -g SUDO_PID="";
# Generic : git_clone
# 1.0.2 Monday, Monday, November 7 15:53:13 CET 2016
#
# Required Global Variable
# - SC_LOGDATE : Input
function git_clone() {
local func_name=${FUNCNAME[*]}; __ini_func ${func_name};
local git_src_dir=$1;
local git_src_url=$2;
local git_src_name=$3;
local tag_name=$4;
__checkstr ${SC_LOGDATE};
if [[ ! -d ${git_src_dir} ]]; then
printf "No git source repository in the expected location %s\n" "${git_src_dir}";
else
printf "Old git source repository in the expected location %s\b" "${git_src_dir}";
printf "The old one is renamed to %s_%s\n" "${git_src_dir}" "${SC_LOGDATE}";
mv ${git_src_dir} ${git_src_dir}_${SC_LOGDATE}
fi
# Always fresh cloning ..... in order to workaround any local
# modification in the repository, which was cloned before.
#
if [ -z "$tag_name" ]; then
git clone "${git_src_url}/${git_src_name}" "${git_src_dir}";
else
git clone -b "${tag_name}" --single-branch --depth 1 "${git_src_url}/${git_src_name}" "${git_src_dir}";
fi
__end_func ${func_name};
}
# Specific : preparation
#
# 1.0.1 Wednesday, November 9 09:56:52 CET 2016
#
# - allow this script to execute yum, and remove PakageKit
#
function preparation() {
local func_name=${FUNCNAME[*]}; __ini_func ${func_name};
__checkstr ${SUDO_CMD};
${SUDO_CMD} systemctl stop packagekit
${SUDO_CMD} systemctl disable packagekit
declare -r yum_pid="/var/run/yum.pid"
# 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
# Remove PackageKit
#
${SUDO_CMD} yum -y remove PackageKit ;
# Install epel-release, git, and tree
#
${SUDO_CMD} yum -y install epel-release git tree;
__end_func ${func_name};
}
${SUDO_CMD} -v
preparation;
git_src_name="epicsarchiverap-sites";
git_src_url="https://github.com/jeonghanlee";
git_src_dir=${SC_TOP}/${git_src_name};
git_clone "${git_src_dir}" "${git_src_url}" "${git_src_name}" ;
printf "\nPlease go %s\n" "${git_src_dir}";
printf "Do bash the following scripts in order\n";
printf "$ bash 00_preAA.bash\n";
printf "$ bash 01_aaBuild.bash\n";
printf "# bash 02_aaSetup.bash\n";
printf "# bash 03_aaDeploy.bash\n";
printf "\n";
printf "# bash aaService.bash start/stop/status\n";
# Remove some directories in ${HOME}
printf "Remove Music, Pictures, Public, Templates, and Videos directories in ${HOME}.... \n";
rm -rf ${HOME}/{Music,Pictures,Public,Templates,Videos};
${SUDO_CMD} -K;
exit;