You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
802 B

#!/usr/bin/env bash
set -eu
DESC="Ajoute, si nécessaire un utilisateur toto sur bigboss et tit sur tiny."
getRandomPasswd() {
local k
while :; do
k=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom 2> /dev/null | head -c${1:-32} )
if [ $(echo -n $k | wc -c) = 32 ]; then
break
fi
echo "Wait for entropy avail : $(cat /proc/sys/kernel/random/entropy_avail)" >&2
sleep 1
done
echo -n $k
}
repairUser() {
k=$(getRandomPasswd)
vdn-ssh root@$1 "
id $2 2> /dev/null && exit 0
adduser --disabled-password --gecos \"\" --home /home/$2 --shell /bin/bash $2
echo $2:$k| chpasswd
"
}
run() {
setErrorHandler
echoStart
startAndWaitSsh bigboss tiny
repairUser bigboss toto
repairUser tiny titi
unsetErrorHandler
echoDone
}