#!/bin/bash
VERSION=1.1
GITUSR=gitgsb
GITPRJ=gsb
GITPATH=/home/${GITUSR}/${GITPRJ}.git
WEB=/var/www/html

apt install -y lighttpd git-core

if [[ ! -d ${WEB} ]]; then 
  echo "$0: repertoire ${WEB} inexistant "
  exit 1 
fi

getent passwd ${GITUSR} >> /dev/null
if [[ $? != 0 ]]; then
  echo "creation utilisateur ${GITUSR} ..."
  /sbin/useradd -m -d /home/${GITUSR} -s /bin/bash ${GITUSR} 
  echo "${GITUSR}:${GITUSR}" | /sbin/chpasswd 
fi
if [[ -d ${GITPATH} ]]; then 
  rm -rf ${GITPATH} 
fi
su -c "git clone --bare http://sio.lyc-lecastel.fr/${GITPRJ}.git ${GITPATH}" ${GITUSR}

su -c "cd ${GITPATH}/hooks && cp post-update.sample post-update && bash post-update" ${GITUSR}
ln -s ${GITPATH} ${WEB}/${GITPRJ}.git
[[ -d ${WEB}/gsbstore ]]|| mkdir ${WEB}/gsbstore

cd ${WEB} && wget -O gsbbootl http://sio.lyc-lecastel.fr/store/gsbbootl 

(cat <<EOT > ${WEB}/gsbstore/getall
#!/bin/bash
GLPIREL=9.4.5
wget -nc https://github.com/glpi-project/glpi/releases/download/\${GLPIREL}/glpi-\${GLPIREL}.tgz
 
FIREL=9.4+2.3
wget -nc https://github.com/fusioninventory/fusioninventory-for-glpi/releases/download/glpi\${FIREL}/fusioninventory-\${FIREL}.tar.gz
 
FIAGREL=2.5.2 
wget -nc https://github.com/fusioninventory/fusioninventory-agent/releases/download/\${FIAGREL}/fusioninventory-agent_windows-x64_\${FIAGREL}.exe
 
wget -nc https://github.com/fusioninventory/fusioninventory-agent/releases/download/$FIAGREL/fusioninventory-agent_windows-x86_\${FIAGREL}.exe
 
FOGREL=1.5.7
wget -nc https://github.com/FOGProject/fogproject/archive/\${FOGREL}.tar.gz -O fogproject-\${FOGREL}.tar.gz
 
wget -nc https://fr.wordpress.org/wordpress-5.3.2-fr_FR.tar.gz

GOSSVER=v0.3.10
curl -L https://github.com/aelsabbahy/goss/releases/download/\${GOSSVER}/goss-linux-amd64 -o goss
chmod +x goss 
EOT
)
#echo "fichier getall cree ..."
#echo "pour recuperer les archives, lancer :"
#echo "cd ${WEB}/gsbstore ; bash getall"
cd ${WEB}/gsbstore
bash getall
echo "pour installer s-adm : curl localhost/gsbbootl | bash"

 
 

