This commit is contained in:
Adrian Amaglio 2021-03-03 16:49:58 +01:00
parent c7cf872d9c
commit 853b0e0a7d
4 changed files with 22 additions and 14 deletions

View File

@ -1,2 +1,3 @@
218-amine=TPA6eMfztS
218-chems=osjMQQ8rXd
test=bRqy6jlnM6

View File

@ -1,2 +1,3 @@
218-amine
218-chems
test

View File

@ -6,3 +6,4 @@ services:
- ./config:/app/config
- ./production_eleves:/app/python_app/modules
network_mode: "host"
restart: "unless-stopped"

View File

@ -6,7 +6,7 @@ PASSWD_LIST="/app/config/passwords.txt"
CUSTOM_SCRIPT="/app/config/init.sh"
separator="=" # Must be ascii for cut
forbidden_chars=". /"
forbidden_chars=". / : # = \ "
# Check we got user list
if [ ! -f "$USERS_LIST" ] && [ ! -f "$PASSWD_LIST" ] ; then
@ -15,24 +15,20 @@ if [ ! -f "$USERS_LIST" ] && [ ! -f "$PASSWD_LIST" ] ; then
fi
for c in $forbidden_chars ; do
for file in "$USERS_LIST" "$PASSWD_LIST" ; do
if [ -n "$(cat "$USERS_LIST" | grep -F $c)" ] ; then
echo "Le fichier « $file » ne doit pas contenir le caractère « $c » !"
exit 1
fi
done
if [ -n "$(cat "$USERS_LIST" | grep -F $c)" ] ; then
echo "Le fichier « $USERS_LIST » ne doit pas contenir le caractère « $c » !"
exit 1
fi
done
# Generate passwords if not done yet
genPassowrd () {
tr -dc A-Za-z0-9 </dev/urandom | head -c $1
}
if [ ! -f $PASSWD_LIST ] ; then
for user in $(cat "$USERS_LIST") ; do
if [ -z "$user" ] ; then continue ; fi
echo "$user$separator$(genPassowrd 10)" >> $PASSWD_LIST
done
fi
for user in $(cat "$USERS_LIST") ; do
if [ -z "$user" ] || [ -n "$(cat $PASSWD_LIST | grep "$user$separator")" ] ; then continue ; fi
echo "$user$separator$(genPassowrd 10)" >> $PASSWD_LIST
done
# Create users, home dirs, change passwords and home owners
for line in $(cat $PASSWD_LIST) ; do
@ -42,6 +38,11 @@ for line in $(cat $PASSWD_LIST) ; do
home="$HOME_BASE/$name"
mkdir -p "$home"
useradd --home-dir "$home" --no-user-group -G eleve --shell /bin/bash "$name"
$ret="$?"
if [ "$ret" -ne 0 ] && [ "$ret" -ne 9 ] ; then
echo "Cant create user '$name'. Error '$ret'."
continue
fi
echo "$pass\n$pass" | passwd "$name" &> /dev/null
chown "$name":eleve "$home"
done
@ -64,4 +65,8 @@ nginx -c '/etc/nginx/nginx.conf'
/usr/sbin/sshd -E /dev/stderr
# Start watever the container should be doing
/bin/sh -c "$*"
/bin/sh -c "$*" &
pid="$!"
trap "kill -INT $pid" INT
trap "kill -TERM $pid" TERM
wait "$pid"