forked from team/makeuser
64 lines
1.5 KiB
Bash
Executable File
64 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# ---------------------------------------------------------------------------
|
|
# makeuser - tilde new user creation
|
|
# Usage: makeuser [-h|--help] <username> <email> "<pubkey>"
|
|
# ---------------------------------------------------------------------------
|
|
#
|
|
# Forked from tilde.team's make user script (
|
|
PROGNAME=${0##*/}
|
|
VERSION="0.4"
|
|
GEN_TDP="./gen_tdp"
|
|
CONFIG=./setenv
|
|
|
|
. $CONFIG
|
|
|
|
source include/functions
|
|
|
|
[[ $(id -u) == 0 ]] && error_exit "Do not run this script as root."
|
|
|
|
case $1 in
|
|
-h | --help)
|
|
usage; exit ;;
|
|
-* | --*)
|
|
usage; error_exit "unknown option $1" ;;
|
|
*)
|
|
[[ $# -ne 3 ]] && error_exit "not enough args"
|
|
$(sudo grep -qiw $1 $BANNED) && error_exit "$1 is on the ban list!"
|
|
|
|
#adding new user
|
|
makeuser_no_ansible $1 $2
|
|
add_account_recovery $1 $2
|
|
|
|
#Thunix specific section
|
|
currdir=`pwd`
|
|
cd $REPO_LOCATION; git pull; cd $currdir
|
|
echo "---
|
|
- name: Setting up $1
|
|
user:
|
|
name: $1
|
|
groups: tilde
|
|
state: present
|
|
skeleton: /etc/skel
|
|
shell: /bin/bash
|
|
system: no
|
|
createhome: yes
|
|
home: /home/$1
|
|
- authorized_key:
|
|
user: $1
|
|
state: present
|
|
key: \"$3\"" > $REPO_LOCATION/roles/shell/tasks/users/$YAML_FILE
|
|
|
|
echo "- include: users/$YAML_FILE" >> $REPO_LOCATION/roles/shell/tasks/users.yml
|
|
place=`pwd`
|
|
cd $REPO_LOCATION
|
|
git add $REPO_LOCATION/roles/shell/tasks/users/$1.yml
|
|
git commit -am "Adding user $1"
|
|
git push
|
|
cd $place
|
|
$GEN_TDP | sudo tee $TILDE_JSON
|
|
# End Thunix specific section
|
|
;;
|
|
|
|
esac
|
|
|