summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-06-19 12:46:39 +0200
committerErich Eckner <git@eckner.net>2019-06-19 12:46:39 +0200
commit3c1fae0f07b6162f4f2c3669145899fa85e01269 (patch)
tree67e27946a529f4d53b114de63ada95efeb1de7d8 /bin
parent977161b95a2adcb5a06adb9d76f42f7ad792dfc7 (diff)
downloadbuilder-3c1fae0f07b6162f4f2c3669145899fa85e01269.tar.xz
bin/manage-slaves: enable|disable implemented
Diffstat (limited to 'bin')
-rwxr-xr-xbin/manage-slaves69
1 files changed, 66 insertions, 3 deletions
diff --git a/bin/manage-slaves b/bin/manage-slaves
index cfa8c4d..cddda84 100755
--- a/bin/manage-slaves
+++ b/bin/manage-slaves
@@ -105,7 +105,7 @@ case "$1" in
~/".ssh/authorized_keys"
;;
'disable'|'enable')
- action="$1"
+ action="${1}"
shift
if [ $# -ne 1 ]; then
>&2 printf '"%s" expects one parameter, %s were given\n' \
@@ -113,8 +113,71 @@ case "$1" in
"$#"
usage
fi
- >&2 echo 'not yet implemented'
- exit 1
+ infos=$(
+ # shellcheck disable=SC2016
+ {
+ printf 'SELECT'
+ printf ' `build_slaves`.`id`,'
+ printf 'CONCAT('
+ printf '"command=\\\"%s/bin/slave-build-connect ",' \
+ "${base_dir}"
+ printf '`build_slaves`.`name`,'
+ printf '"\\\" ssh-rsa ",'
+ printf '`ssh_keys`.`fingerprint`,'
+ printf '" ",'
+ printf '`persons`.`name`,'
+ printf '"@",'
+ printf '`build_slaves`.`name`'
+ printf ')'
+ printf ' FROM `build_slaves`'
+ mysql_join_build_slaves_ssh_keys
+ mysql_join_ssh_keys_persons
+ printf ' WHERE `build_slaves`.`name`="%s"' \
+ "${1}"
+ printf ' AND `build_slaves`.`access_allowed`='
+ if [ "${action}" = 'disable' ]; then
+ printf 1
+ else
+ printf 0
+ fi
+ printf ';\n'
+ } | \
+ mysql_run_query | \
+ tr '\t' ' '
+ )
+ if [ -z "${infos}" ]; then
+ >&2 printf 'Cannot find build slave "%s" in the database to %s.\n' \
+ "${1}" \
+ "${action}"
+ usage
+ fi
+ if [ "${action}" = 'disable' ]; then
+ grep -vF "$(
+ printf '%s\n' "${infos}" | \
+ sed '
+ s/^\S\+ //
+ s/\s\+\S\+$//
+ '
+ )" ~/".ssh/authorized_keys" | \
+ sponge ~/".ssh/authorized_keys"
+ else
+ printf '%s\n' "${infos}" | \
+ sed 's/^\S\+ //' >> \
+ ~/".ssh/authorized_keys"
+ fi
+ # shellcheck disable=SC2016
+ {
+ printf 'UPDATE `build_slaves`'
+ printf ' SET `build_slaves`.`access_allowed`='
+ if [ "${action}" = 'disable' ]; then
+ printf 0
+ else
+ printf 1
+ fi
+ printf ' WHERE `build_slaves`.`id`=%s;\n' \
+ "${infos%% *}"
+ } | \
+ mysql_run_query
;;
*)
>&2 printf 'unknown action "%s"\n' "$1"