diff --git a/test-python-ssh/config/passwords.txt b/test-python-ssh/config/passwords.txt index f56c69a..dfb6ee4 100644 --- a/test-python-ssh/config/passwords.txt +++ b/test-python-ssh/config/passwords.txt @@ -1,2 +1,3 @@ 218-amine=TPA6eMfztS 218-chems=osjMQQ8rXd +test=bRqy6jlnM6 diff --git a/test-python-ssh/config/users.txt b/test-python-ssh/config/users.txt index 1179728..9d662ca 100644 --- a/test-python-ssh/config/users.txt +++ b/test-python-ssh/config/users.txt @@ -1,2 +1,3 @@ 218-amine 218-chems +test diff --git a/test-python-ssh/docker-compose.yml b/test-python-ssh/docker-compose.yml index 387c317..fc7f045 100644 --- a/test-python-ssh/docker-compose.yml +++ b/test-python-ssh/docker-compose.yml @@ -6,3 +6,4 @@ services: - ./config:/app/config - ./production_eleves:/app/python_app/modules network_mode: "host" + restart: "unless-stopped" diff --git a/test-python-ssh/entrypoint.sh b/test-python-ssh/entrypoint.sh index 8c7ba2c..16d6924 100755 --- a/test-python-ssh/entrypoint.sh +++ b/test-python-ssh/entrypoint.sh @@ -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 > $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 "Can’t 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"