Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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"