-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathipa-plugins-installer.sh
More file actions
executable file
·148 lines (135 loc) · 5.54 KB
/
ipa-plugins-installer.sh
File metadata and controls
executable file
·148 lines (135 loc) · 5.54 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
#!/bin/sh
### FreeIPA extensions: Automatic plugins installer (with ldif).
###
### Copyright 2021 téïcée SARL <https://www.teicee.com>
### Written by Grégory MARIGOT <gmarigot at teicee.com>
###
### This program is free software: you can redistribute it and/or modify
### it under the terms of the GNU Affero General Public License as
### published by the Free Software Foundation, either version 3 of the
### License, or (at your option) any later 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 Affero General Public License for more details.
###
### You should have received a copy of the GNU Affero General Public License
### along with this program. If not, see <https://www.gnu.org/licenses/>.
cd "$(dirname "${0}")"
### Variables
DIR_SRC_PLUGINS="${PWD}"
DIR_IPA_LD="/usr/share/ipa/schema.d"
DIR_IPA_UP="/usr/share/ipa/updates"
DIR_IPA_JS="/usr/share/ipa/ui/js"
DIR_IPA_PY="$(ls -1 -d /usr/lib/python*/*-packages/ipaserver/plugins 2>/dev/null |head -n1)"
ALL_PLUGIN="$(ls -1 "${DIR_SRC_PLUGINS}/"*.js "${DIR_SRC_PLUGINS}/"*.py 2>/dev/null |sed 's|^.*/||' |sed 's/\.\(js\|py\)$//' |sort |uniq |tr '\n' ' ')"
### ANSI Colors
COL_NORM='' COL_HEAD='' COL_INFO='' COL_WARN='' COL_CRIT='' COL_DONE=''
if [ "x${TERM}" != "xdumb" ]; then
COL_NORM='\e[0;00m' # default
COL_HEAD='\e[1;36m' # cyan
COL_INFO='\e[1;34m' # blue
COL_WARN='\e[1;33m' # yellow
COL_CRIT='\e[1;31m' # red
COL_DONE='\e[1;32m' # green
fi
### Functions
usage() {
printf "\nUsage: %s <plugin...|--all> [--reload|--no-reload]\n" "${0}" >&2
printf " -a, --all : Install all available plugins\n"
printf " -r, --reload : Force the FreeIPA services reload\n"
printf " -R, --no-reload : Disable the FreeIPA services reload\n"
printf " -h, --help : Display this help message\n"
printf "\nAvailable plugins: %s\n\n" "${ALL_PLUGIN}"
exit 1
}
p_title() {
printf "\n${COL_HEAD}###\n### %s\n###${COL_NORM}\n" "${1}"
}
p_tellme() {
printf "\n${COL_INFO}=== %s${COL_NORM}\n" "${1}"
}
p_warnme() {
printf "\n${COL_WARN} * %s !${COL_NORM}\n" "${1}" >&2
}
p_error() {
printf "\n${COL_CRIT}*** ERROR: %s!${COL_NORM}\n\n" "${1}" >&2; exit 1
}
p_success() {
printf "\n${COL_DONE} > %s.${COL_NORM}\n" "${1:-Success}"
}
### Arguments
LST_PLUGIN=
OPT_RELOAD='auto'
[ $# -eq 0 ] && usage
while [ $# -gt 0 ]; do
case "${1}" in
-h | --help ) usage ;;
-a | --all ) LST_PLUGIN="${ALL_PLUGIN}" ;;
-r | --reload ) OPT_RELOAD='todo' ;;
-R | --no-reload ) OPT_RELOAD='' ;;
-* ) p_error "Unknown option '${1}'" ;;
* ) LST_PLUGIN="${LST_PLUGIN}${1} " ;;
esac
shift
done
### Verifications
[ -n "${DIR_IPA_LD}" -a -d "${DIR_IPA_LD}" ] || p_error "Unable to detect FreeIPA LD plugins folder"
[ -n "${DIR_IPA_UP}" -a -d "${DIR_IPA_UP}" ] || p_error "Unable to detect FreeIPA UP plugins folder"
[ -n "${DIR_IPA_PY}" -a -d "${DIR_IPA_PY}" ] || p_error "Unable to detect FreeIPA PY plugins folder"
[ -n "${DIR_IPA_JS}" -a -d "${DIR_IPA_JS}" ] || p_error "Unable to detect FreeIPA JS plugins folder"
[ -z "${LST_PLUGIN}" ] && p_error "Plugins list to install is empty"
### Installations
NEW_LD='' NEW_UP='' NEW_PY='' NEW_JS=''
for PLUGIN in ${LST_PLUGIN}; do
p_title "Installing IPA plugin '${PLUGIN}'..."
PLUGIN_LD="${DIR_SRC_PLUGINS}/${PLUGIN}.ldif"
if [ -f "${PLUGIN_LD}" ]; then
p_tellme "Installing schema modifications:"
diff -q -N "${PLUGIN_LD}" "${DIR_IPA_LD}/75-${PLUGIN}.ldif" || NEW_LD=X
cp -v "${PLUGIN_LD}" "${DIR_IPA_LD}/75-${PLUGIN}.ldif"
fi
PLUGIN_UP="${DIR_SRC_PLUGINS}/${PLUGIN}.acl"
if [ -f "${PLUGIN_UP}" ]; then
p_tellme "Installing acls updates:"
diff -q -N "${PLUGIN_UP}" "${DIR_IPA_UP}/75-${PLUGIN}.update" || NEW_UP=X
cp -v "${PLUGIN_UP}" "${DIR_IPA_UP}/75-${PLUGIN}.update"
fi
PLUGIN_PY="${DIR_SRC_PLUGINS}/${PLUGIN}.py"
if [ -f "${PLUGIN_PY}" ]; then
p_tellme "Installing python script:"
diff -q -N "${PLUGIN_PY}" "${DIR_IPA_PY}/${PLUGIN}.py" || NEW_PY=X
cp -v "${PLUGIN_PY}" "${DIR_IPA_PY}/"
cd "${DIR_IPA_PY}/"
p_tellme "Compiling python script:"
python -m compileall "${PLUGIN}"* && \
python -O -m compileall "${PLUGIN}"*
fi
PLUGIN_JS="${DIR_SRC_PLUGINS}/${PLUGIN}.js"
if [ -f "${PLUGIN_JS}" ]; then
p_tellme "Installing javascript script:"
DIR_PLUGIN="${DIR_IPA_JS}/plugins/${PLUGIN}"
[ -d "${DIR_PLUGIN}" ] || mkdir -p "${DIR_PLUGIN}"
diff -q -N "${PLUGIN_JS}" "${DIR_PLUGIN}/${PLUGIN}.js" || NEW_JS=X
cp -v "${PLUGIN_JS}" "${DIR_PLUGIN}/"
fi
done
### Reloading
p_title "Reloading IPA services..."
if [ -z "${OPT_RELOAD}" ]; then
if [ -n "${NEW_LD}" ]; then p_warnme "[reload disabled] You should run the command 'ipa-server-upgrade'"
elif [ -n "${NEW_UP}" ]; then p_warnme "[reload disabled] You should run the command 'ipa-server-upgrade'"
elif [ -n "${NEW_PY}" ]; then p_warnme "[reload disabled] You should run the command 'apachectl graceful'"
fi
elif [ "${OPT_RELOAD}" = 'auto' ]; then
if [ -n "${NEW_LD}" ]; then p_tellme "Upgrade IPA server (reload schema and much more !)..." ; ipa-server-upgrade
elif [ -n "${NEW_UP}" ]; then p_tellme "Upgrade IPA server (apply acls and much more !)..." ; ipa-server-upgrade
elif [ -n "${NEW_PY}" ]; then p_tellme "Reload Apache wsgi child processes for python scripts..." ; apachectl graceful
fi
else ipa-server-upgrade ## force reload
fi
[ -d "${HOME}/.cache/ipa" ] && rm -rf "${HOME}/.cache/ipa"
p_tellme "IPA services status..."
ipactl status || p_error "Some FreeIPA services are not running"
p_success