fixed user creation, some rc files, use hcloud host vars (ipv6)

This commit is contained in:
2024-11-26 18:00:21 +01:00
parent 158048f51d
commit c49dff9ad4
10 changed files with 255 additions and 44 deletions

View File

@@ -1,5 +1,8 @@
#!/bin/sh
# manage FreeBSD jail users
# vars defaults
rootdir=""
user=""
groups=""
@@ -14,11 +17,22 @@ usage() {
exit 1
}
run() {
echo $*
$*
getuid() {
# resolve jail uid
root="$1"
user="$2"
pw $root show user "$user" -7 | cut -d: -f 3
}
run() {
# verbose exec
echo "$@"
"$@"
}
# parse commandline flags
OPTIND=1
while getopts d:u:h:g:s:c:a: opt ; do
case $opt in
@@ -55,6 +69,7 @@ if test -z "$user" -o -z "$action"; then
usage
fi
# setup pw flags
args=""
root=""
@@ -82,20 +97,31 @@ if test -n "$comment"; then
args="$args -c $comment"
fi
# the horse shall work
case "$action" in
present)
if pw $root user show "$user" > /dev/null 2>&1; then
if pw $root user show "$user" | grep -q LOCKED; then
# user is present but locked
run pw unlock "$user"
else
echo "$user exists."
fi
else
# create user
run pw $root user add "$user" $args
fi
if test -e "/usr/local/bastille/keys/$user" -a ! -e "/home/$user/.ssh/authorized_keys"; then
# install ssh key
uid=$(getuid "$root" "$user")
install -m 700 -o "$uid" -g "$uid" -d "/home/$user/.ssh"
install -m 600 -o "$uid" -g "$uid" "/usr/local/bastille/keys/$user" "/home/$user/.ssh/authorized_keys"
fi
;;
absent)
if pw $root user show "$user" > /dev/null 2>&1; then
# get rid
run pw $root user del "$user"
fi
;;
@@ -104,6 +130,7 @@ case "$action" in
if pw $root user show "$user" | grep -q LOCKED; then
echo "$user is already locked."
else
# lock'em out
run pw lock "$user"
fi
fi