Files
states/Scripts/bootstrap-ansible.sh
Iwan Clement c0896dffda Ubuntu
2019-05-08 08:32:47 +02:00

58 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit 1
fi
USERID=7531
USERNAME="ansusr"
USERPWD="1J2_r0EgEhGUmG3oLm258jWByvg79I"
USERSSHKEY="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5R2sPScuoetKYjiUi6ngzEsCnnrXX3daMUGAXVFi04xN0zvSno5hNUZM4w7WzoLZZPu/Gnlz+swaHSVyC3tCdIOjAp3ZalTXx4ubCdiBOKyElMurpNG5e2ozW4e6eKOObWaVxx+bBoEPI4SE+3cYfcUKiOxdjwDEALxwa2I50VLNYLYmj6CoMrPZuLQcD2Tk9C2PjHd4j/f+fKFKKACDCfT2Ga+C65ZmaEqxBSntzeKfUlGtz3jvr4tpxMQftvqaY5CwQ5bY6WhAVGyAM4Zl4PIl6rCrBgZOlaqpbtio/RB3ejB381ftrCzXcMHOF6ijOZ2xB46wsYLAKL3u6P5Q1 iwan@CT-deb-ansible"
DEBGROUP="sudo"
CENTGROUP="wheel"
DEBFLAG="/etc/debian_version"
if [ -e $DEBFLAG ]; then
PREREQPWD="sudo python3-minimal python3-apt openssh-server whois"
apt-get -y update && apt-get -y install $PREREQPWD \
&& useradd -m -s /bin/bash -u $USERID -p $(mkpasswd -m sha-512 $USERPWD) -G $DEBGROUP $USERNAME \
|| exit 2
else
PREREQPWD="sudo openssh-server python rpm-python deltarpm"
yum -y update && yum install -y $PREREQPWD \
&& useradd -m -s /bin/bash -u $USERID \
-p $(python -c "import sys; import crypt; print(crypt.crypt(sys.argv[1]))" $USERPWD) \
-G $CENTGROUP $USERNAME \
|| exit 2
fi
if [ ! -d /home/$USERNAME ]; then
mkdir /home/$USERNAME
fi
mkdir /home/$USERNAME/.ssh \
&& echo "$USERSSHKEY">/home/$USERNAME/.ssh/authorized_keys \
&& chmod 700 /home/$USERNAME/.ssh \
&& chmod 600 /home/$USERNAME/.ssh/authorized_keys \
&& chown -R $USERNAME:$USERNAME /home/$USERNAME \
|| exit 3
if [ -e $DEBFLAG ]; then
if [ "$(cat $DEBFLAG)" == "buster/sid" ]; then
if [ -d /var/lib/AccountsService/users ]; then
echo "[User]">/var/lib/AccountsService/users/$USERNAME
echo "SystemAccount=true">>/var/lib/AccountsService/users/$USERNAME
fi
fi
fi
if [ -e $DEBFLAG ]; then
systemctl enable ssh && systemctl restart ssh && exit 0
else
systemctl enable sshd && systemctl restart sshd && exit 0
fi
echo "Erreur"
exit 4