From 20704229c9f8a5d20a966187c88267ad07e5aa1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iwan=20Cl=C3=A9ment?= Date: Fri, 3 May 2019 17:45:22 +0200 Subject: [PATCH] Ajout --- Scripts/bootstrap-ansible.sh | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 Scripts/bootstrap-ansible.sh diff --git a/Scripts/bootstrap-ansible.sh b/Scripts/bootstrap-ansible.sh new file mode 100755 index 0000000..b39e299 --- /dev/null +++ b/Scripts/bootstrap-ansible.sh @@ -0,0 +1,53 @@ +#!/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 [ -d /var/lib/AccountsService/users ]; then + echo "[User]">/var/lib/AccountsService/users/$USERNAME + echo "SystemAccount=true">>/var/lib/AccountsService/users/$USERNAME +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