Improve user script prompts
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# Add a user to the Hartman Lab server
|
||||
# Copyright 2021 Bryan C. Roessler
|
||||
# Copyright Bryan C. Roessler
|
||||
|
||||
parent="${BASH_SOURCE[0]}"
|
||||
parent=${parent%/*}
|
||||
@@ -9,17 +9,26 @@ parent=${parent%/*}
|
||||
|
||||
is_root
|
||||
|
||||
echo "$@"
|
||||
echo "This script supports two optional arguments, a username and password"
|
||||
|
||||
[[ $# -eq 0 ]] && echo "No username provided!" && exit 1
|
||||
[[ $# -eq 1 ]] && username="$1" && password="$username"
|
||||
[[ $# -eq 2 ]] && username="$1" && password="$2"
|
||||
[[ $# -gt 2 ]] && echo "Too many arguments provided" && exit 1
|
||||
if [[ $# -eq 0 ]]; then
|
||||
prompt username
|
||||
prompt password
|
||||
elif [[ $# -eq 1 ]]; then
|
||||
username="$1"
|
||||
prompt password
|
||||
elif [[ $# -eq 2 ]]; then
|
||||
username="$1"
|
||||
password="$2"
|
||||
elif [[ $# -gt 2 ]]; then
|
||||
echo "Too many arguments provided"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
useradd_cmd=("useradd" "-m" "-U")
|
||||
useradd_cmd=(useradd -m -U)
|
||||
|
||||
if id -u "$username"; then
|
||||
ask_ok "User $username exists. Run script-user-remove?" || exit $?
|
||||
if id -u "$username" &>/dev/null; then
|
||||
ask_ok "User $username exists. Run script-user-remove first?" || exit $?
|
||||
"$parent"/script-user-remove "$username" || exit $?
|
||||
fi
|
||||
|
||||
@@ -33,7 +42,7 @@ fi
|
||||
samba="no"
|
||||
ask_ok "Enable shared file access for user $username?" && group_str="smbgrp" && samba="yes"
|
||||
|
||||
ask_ok "Make user $username an admin?" && \
|
||||
ask_ok "Make $username an admin?" && \
|
||||
group_str+=",wheel"
|
||||
|
||||
useradd_cmd+=("-G" "$group_str")
|
||||
@@ -54,15 +63,16 @@ if [[ "$samba" == "yes" ]]; then
|
||||
(echo "$password"; echo "$password") | smbpasswd -a -s "$username"
|
||||
fi
|
||||
|
||||
# TODO check if centos 9 does by default
|
||||
# Add subuids & subgids for container namespace
|
||||
id_offset=100000
|
||||
id_num=65536
|
||||
last_uid=$(tail -1 /etc/subuid | cut -d':' -f2)
|
||||
last_gid=$(tail -1 /etc/subgid | cut -d':' -f2)
|
||||
start_uid=$(( last_uid + id_offset ))
|
||||
start_gid=$(( last_gid + id_offset ))
|
||||
echo "$username:$start_uid:$id_num" >> /etc/subuid
|
||||
echo "$username:$start_gid:$id_num" >> /etc/subgid
|
||||
# id_offset=100000
|
||||
# id_num=65536
|
||||
# last_uid=$(tail -1 /etc/subuid | cut -d':' -f2)
|
||||
# last_gid=$(tail -1 /etc/subgid | cut -d':' -f2)
|
||||
# start_uid=$(( last_uid + id_offset ))
|
||||
# start_gid=$(( last_gid + id_offset ))
|
||||
# echo "$username:$start_uid:$id_num" >> /etc/subuid
|
||||
# echo "$username:$start_gid:$id_num" >> /etc/subgid
|
||||
|
||||
# Copy manual to user desktop
|
||||
mkdir -p /home/"$username"/Desktop/
|
||||
|
||||
Reference in New Issue
Block a user