-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·115 lines (93 loc) · 3.55 KB
/
install
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
#!/usr/bin/env bash
#===================================================================================
# LABADMIN INSTALLATION
# FILE: install
#
# DESCRIPTION: Install and check labadmin dependencies for admin and host
#
# AUTHOR: Leonardo Marco ([email protected])
# LICENSE: GNU General Public License v3.0
# VERSION: 2019.04
# CREATED: 16.02.2017
#===================================================================================
#===============================================================================
# LOAD LIBS
#===============================================================================
source "$(dirname "$(readlink -f "$0")")/lib/labadmin_lib-admin" # LABADMIN ADMIN VARIABLES AND FUNCTIONS
source "${lib_path}/labadmin_lib" # LABADMIN GLOBAL VARIABLES AND FUNCTIONS
source "${lib_path}/labadmin_script" # LABADMIN SCRIPT MODULE
source "${lib_path}/labadmin_install" # LABADMIN INSTALL MODULE
#=== FUNCTION ==================================================================
# NAME: help
# DESCRIPTION: Show help and exit
# PARAMETERS:
# $1 exit code
#===============================================================================
function help() {
echo -e 'Install, uninstall and check labadmin dependencies for admin and host.
HOST INSTALL
\e[1m'$(basename $0)'\e[0m -H -l \e[4mid_lab\e[0m Install host and no insert MAC in lab file
\e[1m'$(basename $0)'\e[0m -H -l \e[4mid_lab\e[0m -n \e[4mnhost\e[0m Install host and insert in \e[4mid_lab\e[0m: macs[\e[4mnhost\e[0m]=<host MAC>
ADMIN INSTALL
\e[1m'$(basename $0)'\e[0m -A -l \e[4mid_lab_def\e[0m Install admin and set \e[4mid_lab_def\e[0m as default lab
CHECK DEPENDENCIES
\e[1m'$(basename $0)'\e[0m -H -D ask|autoinstall|noinstall Check host dependencies
\e[1m'$(basename $0)'\e[0m -A -D ask|autoinstall|noinstall Check admin dependencies'
exit $1
}
#### READ PARAMETERS
[ $# -eq 0 ] && help
while getopts ":D:n:Hl:A" o
do
case $o in
l) # -l:LAB
lparam=1
lab_id="$OPTARG"
if [ "${lab_id:0:1}" = "-" ]; then
echo "Param -l needs a lab ID" 1>&2
echo "Available lab IDs: $(ls $"labs_path" | sed -z 's/\n/, /g' | sed 's/, $//g')" 1>&2
exit 1
fi
;;
D) # -d:dependencies
Dparam=1
Daction="$OPTARG"
[[ "$Daction" != @(ask|autoinstall|noinstall) ]] && labadmin_error "Incorrect check dependence action $daction\nSupported actions: ask, autoinstall and noinstall" 1
;;
H) # -h:nhost
Hparam=1
;;
n) # -n:nhost
nparam=1
nhost="$OPTARG"
[ "$nhost" -ne "$nhost" ] && labadmin_error "Host number must be a number" 1
;;
A) # -a:admin
Aparam=1
;;
\?)
help
;;
esac
done
#### ACTION: INSTALL/UNINSTALL/CHECK
## DEPENDENCIES HOST
if [ "$Dparam" ] && [ "$Hparam" ]; then
load_scripts "$scripts_path"
check_dependencies "$Daction" "scripts_hostdeps"
## DEPENDENCIES ADMIN
elif [ "$Dparam" ] && [ "$Aparam" ]; then
load_scripts "$scripts_path"
check_dependencies "$Daction" "scripts_admindeps"
## INSTALL ADMIN
elif [ "$Aparam" ] && [ "$lparam" ]; then
load_scripts "$scripts_path"
install_admin "$lab_id"
## INSTALL HOST
elif [ "$Hparam" ] && [ "$lparam" ]; then
load_scripts "$scripts_path"
install_host "$nhost" "$lab_id"
## OTHER CASE
else
help 1
fi