-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-modules.sh
executable file
·98 lines (86 loc) · 2.79 KB
/
install-modules.sh
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
#!/bin/bash
prompt_yes_no () {
local message=$1
local OK_TO_CONTINUE="no"
#>&2 echo " ------------ YES / NO --------------"
while :; do
>&2 echo -en "$message (yes/no) "
read OK_TO_CONTINUE </dev/tty
if [[ "${OK_TO_CONTINUE}" == "no" ]]; then
return 1
elif [[ "${OK_TO_CONTINUE}" == "yes" ]]; then
return 0
fi
>&2 echo "Please type 'yes' or 'no' (you said: $OK_TO_CONTINUE)"
sleep 1
done
}
DIR=$(dirname "$(readlink -f "$0")")
PREFERENCES="dcs-modules.txt"
conf_path=${1}
if [[ -f $conf_path ]]; then
conf_file="$conf_path"
elif [[ -d $conf_path ]]; then
conf_file="${conf_path}/$PREFERENCES"
else
echo "Configuration file path is required. Example:"
echo
echo "$0 ./"
exit 5
fi
if [ ! -f "$conf_file" ]; then
echo
echo "Select Modules to Install"
echo "-----------------------------------"
declare -a modules_enabled
declare -a modules_disabled
while IFS= read -r module; do
module_dir="$(realpath $(dirname $module))/"
module_path_name=".${module_dir#$DIR}"
if [[ "$module_path_name" == "./" ]]; then
#modules="$modules\n$module_dir"
echo " -> scada.js dependencies: [REQUIRED]"
modules_enabled+=("$module_path_name")
elif [[ "$module_path_name" == "./lib/dcs/" ]]; then
#modules="$modules\n$module_path_name"
echo " -> aktos-dcs dependencies: [REQUIRED]"
modules_enabled+=("$module_path_name")
else
if prompt_yes_no " -> $module_path_name dependencies? "; then
#echo "+++ $module_path_name"
modules_enabled+=("$module_path_name")
else
modules_disabled+=("$module_path_name")
fi
fi
done < <(find . -name "node_modules" -prune -a ! -name "node_modules" -o -name "package.json" | tac )
echo
echo "Saving Preferences to $conf_file"
echo "----------------------------------------------"
for i in "${modules_enabled[@]}"; do
echo -e "yes\t$i" >> $conf_file
done
for i in "${modules_disabled[@]}"; do
echo -e "no\t$i" >> $conf_file
done
else
echo
echo "Using $conf_file file..."
echo "-----------------------------------"
cat "$conf_file"
fi
echo
echo "Installing Modules"
echo "-----------------------------------"
while IFS='' read -r module || [[ -n "$module" ]]; do
status=$(echo $module | awk -F' ' '{print $1}')
module=$(echo $module | awk -F' ' '{print $2}')
if [[ "$status" = "no" ]]; then
echo " --- Skipping disabled module: \"$module\""
else
echo " *** Installing dependencies for: \"$module\"";
echo
cd "$DIR/$module"
npm install
fi
done < "$conf_file"