#!/bin/sh HOME_BASE="/usr/share/app/python_app/modules" USERS_LIST="/usr/share/app/data/users.txt" PASSWD_LIST="/usr/share/app/data/passwords.txt" CUSTOM_SCRIPT="/usr/share/app/data/init.sh" # Must be ascii for cut separator="=" forbidden_chars=". /" # Check we got users if [ ! -f "$USERS_LIST" ] && [ ! -f "$PASSWD_LIST" ] ; then echo "Les fichiers des utilisateurs ou des passwords n’ont pas étés trouvées." exit 1 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 done # Generate passwords if not done yet genPassowrd () { tr -dc A-Za-z0-9 > $PASSWD_LIST done fi # Create users for line in $(cat $PASSWD_LIST) ; do name="$(echo "$line" | cut -d "$separator" -f 1)" pass="$(echo "$line" | cut -d "$separator" -f 2)" home="$HOME_BASE/$name" mkdir -p "$home" #useradd --home-dir "$home" --no-user-group -G eleve --shell /bin/bash --root "$home" "$name" useradd --home-dir "$home" --no-user-group -G eleve --shell /bin/bash "$name" echo "$pass\n$pass" | passwd "$name" &> /dev/null chown "$name":eleve "$home" done echo "PermitRootLogin yes" >> /etc/ssh/sshd_config echo "\nFin de la préparation des utilisateurs.\n" # Custom script if [ -f "$CUSTOM_SCRIPT" ] ; then if [ ! -x "$CUSTOM_SCRIPT" ] ; then chmod +x "$CUSTOM_SCRIPT" fi "$CUSTOM_SCRIPT" fi # Nginx nginx -c '/etc/nginx/nginx.conf' # SSH server /usr/sbin/sshd # Start watever the container should be doing /bin/sh -c "$*"