Merge branch 'master' of tildegit.org:breadpunk/scripts

This commit is contained in:
Case Duckworth 2020-04-11 14:57:09 -05:00
commit 64ba612dcf
2 changed files with 16 additions and 6 deletions

View File

@ -1,4 +1,4 @@
MIT License Copyright (c) <year> <copyright holders>
MIT License Copyright (c) 2020 breadpunk.org developers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

20
baker/bin/baker Normal file → Executable file
View File

@ -31,7 +31,7 @@ die()
{
ec="$1"; shift
echo "!! ${FUNCNAME[1]}: $*" >&2
return "$ec"
exit "$ec"
}
log() { printf '%s...' "$*" >&2; }
@ -76,8 +76,10 @@ bakeradd()
log "Setting up ~/.ssh for $user"
{
sudo --user="$user" mkdir "/home/$user/.ssh"
sudo --user="$user" \
cp "$keyfile" "/home/$user/.ssh/authorized_keys2";
cat "$keyfile" >> "/home/$user/.ssh/authorized_keys2"
chown "$user:$user" "/home/$user/.ssh/authorized_keys2"
chmod 700 "/home/$user/.ssh"
chmod 644 "/home/$user/.ssh/authorized_keys2"
} && ok
echo "$user added."
@ -129,15 +131,23 @@ bakerdemote()
done
groups="$(getent group|grep "$user"|cut -d: -f1|"${_sed[@]}"|tr '\n' ',')"
log "Applying changes"
usermod -G "${groups%,}" && ok
usermod -G "${groups%,}" "$user" && ok
}
main()
{ # entry point
(( $(id -u) == 0 )) || die "Script must be run as root"
(( $# == 0 )) && usage 1
cmd="$1"; shift || die "Not enough arguments for \"$cmd\""
case "$cmd" in
help|h)
help|h|usage|-h|--help)
(( $# == 0 )) && usage 0
grep -q "baker$1" "$0" && {
echo "baker $1"
awk "BEGIN{FS=\"\\n\";RS=\"\";}/baker$1/{print}" "$0" |
sed -n 's/# //p'
exit
} || die "No command \"$1\""
;;
add|hire)
cmd=add ;;