Standardize function import
This commit is contained in:
@@ -5,20 +5,20 @@
|
||||
parent="${BASH_SOURCE[0]}"
|
||||
parent=${parent%/*}
|
||||
|
||||
[[ -f "$parent"/script-functions ]] && . "$parent"/script-functions || exit 1
|
||||
[[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
|
||||
|
||||
is_root
|
||||
|
||||
echo "This script supports two optional arguments, a username and password"
|
||||
|
||||
if [[ $# -eq 0 ]]; then
|
||||
prompt username
|
||||
prompt user
|
||||
prompt password
|
||||
elif [[ $# -eq 1 ]]; then
|
||||
username="$1"
|
||||
user="$1"
|
||||
prompt password
|
||||
elif [[ $# -eq 2 ]]; then
|
||||
username="$1"
|
||||
user="$1"
|
||||
password="$2"
|
||||
elif [[ $# -gt 2 ]]; then
|
||||
echo "Too many arguments provided"
|
||||
@@ -27,45 +27,45 @@ fi
|
||||
|
||||
useradd_cmd=(useradd -m -U)
|
||||
|
||||
if id -u "$username" &>/dev/null; then
|
||||
ask_ok "User $username exists. Run script-user-remove first?" || exit $?
|
||||
"$parent"/script-user-remove "$username" || exit $?
|
||||
if id -u "$user" &>/dev/null; then
|
||||
ask_ok "User $user exists. Run script-user-remove first?" || exit $?
|
||||
"$parent"/script-user-remove "$user" || exit $?
|
||||
fi
|
||||
|
||||
ask_ok "Create user $username with password $password?" || exit $?
|
||||
ask_ok "Create user $user with password $password?" || exit $?
|
||||
|
||||
restore="no"
|
||||
if [[ -d /mnt/array/home-retired/$username ]]; then
|
||||
ask_ok "Restore user $username's files from /mnt/array/home-retired/$user?" && restore="yes"
|
||||
if [[ -d /mnt/array/home-retired/$user ]]; then
|
||||
ask_ok "Restore user $user's files from /mnt/array/home-retired/$user?" && restore="yes"
|
||||
fi
|
||||
|
||||
samba="no"
|
||||
ask_ok "Enable shared file access for user $username?" && group_str="smbgrp," && samba="yes"
|
||||
ask_ok "Enable shared file access for user $user?" && group_str="smbgrp," && samba="yes"
|
||||
|
||||
ask_ok "Make $username an admin?" && \
|
||||
ask_ok "Make $user an admin?" && \
|
||||
group_str+="wheel"
|
||||
|
||||
useradd_cmd+=("-G" "$group_str")
|
||||
useradd_cmd+=("$username")
|
||||
useradd_cmd+=("$user")
|
||||
|
||||
if [[ "$restore" == "yes" ]]; then
|
||||
if rsync -av --progress=info2 /mnt/array/home-retired/"$username" /home/"$username"; then
|
||||
ask_ok "User $username's files successfully restored, remove backup at /mnt/array/home-retired/$username?" && \
|
||||
rm -rf /mnt/array/home-retired/"$username"
|
||||
if rsync -av --progress=info2 /mnt/array/home-retired/"$user" /home/"$user"; then
|
||||
ask_ok "User $user's files successfully restored, remove backup at /mnt/array/home-retired/$user?" && \
|
||||
rm -rf /mnt/array/home-retired/"$user"
|
||||
fi
|
||||
fi
|
||||
|
||||
# echo "Running: ${useradd_cmd[*]}"
|
||||
"${useradd_cmd[@]}"
|
||||
echo "$username":"$password" | chpasswd
|
||||
echo "$user":"$password" | chpasswd
|
||||
|
||||
|
||||
if [[ "$samba" == "yes" ]]; then
|
||||
(echo "$password"; echo "$password") | smbpasswd -a -s "$username"
|
||||
(echo "$password"; echo "$password") | smbpasswd -a -s "$user"
|
||||
fi
|
||||
|
||||
ask_ok "Prompt user to reset password on next login?" &&
|
||||
sudo passwd --expire "$username"
|
||||
sudo passwd --expire "$user"
|
||||
|
||||
# TODO check if centos 9 does by default
|
||||
# Add subuids & subgids for container namespace
|
||||
@@ -75,12 +75,12 @@ sudo passwd --expire "$username"
|
||||
# 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
|
||||
# echo "$user:$start_uid:$id_num" >> /etc/subuid
|
||||
# echo "$user:$start_gid:$id_num" >> /etc/subgid
|
||||
|
||||
# Copy manual to user desktop
|
||||
mkdir -p /home/"$username"/Desktop/
|
||||
ln -fs "$parent"/README.html /home/"$username"/Desktop/
|
||||
chown "$username":"$username" -R /home/"$username"/Desktop
|
||||
mkdir -p /home/"$user"/Desktop/
|
||||
ln -fs "$parent"/README.html /home/"$user"/Desktop/
|
||||
chown "$user":"$user" -R /home/"$user"/Desktop
|
||||
|
||||
exit $?
|
||||
|
||||
Reference in New Issue
Block a user