2019-12-03 12:25:11 +01:00
#!/bin/bash
################################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
################################################################################
2019-12-06 16:14:08 +01:00
MY_PATH = " `dirname \" $0 \"` " # relative
MY_PATH = " `( cd \" $MY_PATH \" && pwd )` " # absolutized and normalized
init_loc = " $MY_PATH /shell/init.sh "
2019-12-06 19:24:50 +01:00
now = $( date +%Y-%m-%d)
2019-12-15 02:55:15 +01:00
unset err
2019-12-13 19:55:02 +01:00
## Récupère les données du profile
2019-12-10 20:24:20 +01:00
[ [ -f $MY_PATH /.profile ] ] && source $MY_PATH /.profile
2019-12-06 16:14:08 +01:00
2019-12-13 19:55:02 +01:00
## Récupère les arguments
2019-12-10 04:56:02 +01:00
args = " $@ "
[ [ $args = ~ all ] ] && repOption = o
[ [ $args = ~ noptions ] ] && repOption = n
[ [ $args = ~ force ] ] && force_req = o
[ [ $args = ~ noask ] ] && noask = o
2019-12-06 18:34:06 +01:00
2019-12-13 19:55:02 +01:00
## Vérifie le type de système
[ [ $( uname -a | grep arm) ] ] && isARM = YES || unset isARM
2019-12-14 21:45:36 +01:00
if [ [ $( grep -E 'stretch|18.|19.' /etc/os-release) ] ] ; then OS = stretch;
2019-12-13 19:55:02 +01:00
elif [ [ $( grep buster /etc/os-release) ] ] ; then OS = buster;
else echo " ${ c_red } Votre OS n'est pas supporté $c_ " ; exit 1; fi
echo -e " $OS \n $isARM " > .install/.OS
2019-12-10 04:56:02 +01:00
unset err
2019-12-06 16:14:08 +01:00
2019-12-13 19:55:02 +01:00
## Vérifie si le script est en lancé par root
2019-12-06 16:14:08 +01:00
if [ " $EUID " -eq 0 ]
2019-12-06 19:24:50 +01:00
then echo -e " ${ c_red } Veuillez ne pas executez ce script en root. Choisissez un utilisateur pour votre serveur G1sms+ (nous recommandons l'utilisateur pi) $c_ "
2019-12-06 16:14:08 +01:00
exit 1
fi
2019-12-03 12:25:11 +01:00
2019-12-10 04:56:02 +01:00
## Update G1sms+ code
2019-12-15 02:55:15 +01:00
git pull || err += 1
2019-12-10 04:56:02 +01:00
chmod u+x $MY_PATH /.install/*.sh
2019-12-06 19:24:50 +01:00
$MY_PATH /.install/export_colors.sh
2019-12-06 19:37:55 +01:00
[ [ -f ~/.bash_aliases ] ] && source ~/.bash_aliases
2019-12-06 16:14:08 +01:00
2019-12-06 19:24:50 +01:00
## Vérifie si IPFS est installé
2019-12-06 20:54:13 +01:00
if [ [ $force_req = = "o" || -z $( which ipfs) || -z $( which gammu) ] ] ; then
2019-12-06 19:48:55 +01:00
echo -e " ${ c_yellow } IPFS ou gammu n'ont pas été détectés sur votre machine, nous allons installer tous les prérequis... $c_ "
2019-12-15 02:55:15 +01:00
$MY_PATH /.install/1-install_requirements.sh silkaj ipfs gammu || err += 1
$MY_PATH /.install/2-configure_ipfs_layer.sh || err += 1
2019-12-06 19:24:50 +01:00
else
2019-12-06 19:48:55 +01:00
echo -e " ${ c_green } IPFS et gammu sont déjà installé ! $c_ "
2019-12-06 19:24:50 +01:00
fi
echo -e " ${ c_yellow } Ce script va désormais configurer votre noeud G1sms+ $c_ "
2019-12-03 12:25:11 +01:00
2019-12-06 16:14:08 +01:00
if [ [ -f $MY_PATH /.install/templates/init.sh ] ] ; then
2019-12-10 04:56:02 +01:00
[ [ ! $ADMINPSEUDO ] ] && echo -e " ${ c_light } Votre PSEUDO? (celui de votre Compte membre Duniter) $c_ " && read ADMINPSEUDO
[ [ " $ADMINPSEUDO " = = "" ] ] && echo -e " ${ c_red } IMPOSSIBLE DE CONTINUER $c_ " && exit 1
2019-12-03 12:25:11 +01:00
2019-12-10 04:56:02 +01:00
[ [ ! $ADMINPHONE ] ] && echo -e " ${ c_light } Le Numéro de téléphone SMS Admin? (Support de ce noeud) (ex +33611223344) $c_ " && read ADMINPHONE
[ [ " $ADMINPHONE " = = "" ] ] && echo -e " ${ c_red } IMPOSSIBLE DE CONTINUER $c_ " && exit 1
2019-12-03 12:25:11 +01:00
2019-12-10 04:56:02 +01:00
[ [ ! $MASTERPHONE ] ] && echo -e " ${ c_light } Le numéro de la carte SIM, du module SMS. AUCUNE liaison SMS? Laissez vide (défaut: +33600000000) $c_ " && read MASTERPHONE
[ [ " $MASTERPHONE " = = "" ] ] && MASTERPHONE = "+33600000000"
2019-12-03 12:25:11 +01:00
2019-12-10 04:56:02 +01:00
[ [ ! $ADRESSE ] ] && echo -e " ${ c_light } L'adresse où se trouve votre G1Node pour indiquer où venir chercher ses G1Tag (ex: au G1FabLab de Toulouse) $c_ " && read ADRESSE
2019-12-04 20:12:39 +01:00
2019-12-10 04:56:02 +01:00
echo -e " ADMINPSEUDO: $ADMINPSEUDO \nADMINPHONE: $ADMINPHONE \nMASTERPHONE: $MASTERPHONE \nADRESSE: $ADRESSE "
2019-12-18 02:47:10 +01:00
[ [ $noask != "o" ] ] && echo -e " ${ c_light } ${ c_blue } LES PARAMETRES SONT BONS? Appliquer? ENTER ou CTRL-C ? (Editez le fichier .profile si incorrect) $c_ " && read
2019-12-03 12:25:11 +01:00
2019-12-06 15:51:51 +01:00
[ [ -f shell/init.sh ] ] && mv shell/init.sh shell/init.sh.old
2019-12-15 02:55:15 +01:00
cp $MY_PATH /.install/templates/init.sh shell/init.sh || err += 1
2019-12-03 12:25:11 +01:00
2019-12-18 02:47:10 +01:00
sed -i s/_MASTERPHONE/$MASTERPHONE /g $init_loc
sed -i s/_ADRESSE/$ADRESSE /g $init_loc
sed -i s/_ADMINPHONE/$ADMINPHONE /g $init_loc
sed -i s/_ADMINPSEUDO/$ADMINPSEUDO /g $init_loc
if [ [ ! -f $MY_PATH /.profile ] ] ; then
cp $MY_PATH /.install/templates/.profile $MY_PATH /
sed -i s/_MASTERPHONE/$MASTERPHONE /g $MY_PATH /.profile
sed -i s/_ADRESSE/$ADRESSE /g $MY_PATH /.profile
sed -i s/_ADMINPHONE/$ADMINPHONE /g $MY_PATH /.profile
sed -i s/_ADMINPSEUDO/$ADMINPSEUDO /g $MY_PATH /.profile
fi
2019-12-06 15:51:51 +01:00
else
2019-12-06 19:24:50 +01:00
echo -e " ${ c_red } init.sh introuvable... $c_ "
2019-12-15 02:55:15 +01:00
err += 1
2019-12-06 18:06:18 +01:00
exit 1
2019-12-03 12:25:11 +01:00
fi
2019-12-06 18:06:18 +01:00
2019-12-10 04:56:02 +01:00
## Installations optionnels
2019-12-06 19:24:50 +01:00
2019-12-10 04:56:02 +01:00
repOld = $repOption
2019-12-06 19:24:50 +01:00
[ [ -z $repOption ] ] && echo -e " ${ c_yellow } Voulez-vous installer les modules complémentaires de copylaradio ? (o/n) $c_ " && read repOption
2019-12-15 02:55:15 +01:00
if [ [ $repOption = ~ ^( o| 1| yes| options| a| all) $ ] ] ; then $MY_PATH /.install/3-install_copylaradio.sh || err += 1; fi ; repOption = $repOld
2019-12-14 21:45:36 +01:00
[ [ -z $repOption ] ] && echo -e " ${ c_yellow } Voulez-vous installer l'interface web Kalkun ? (o/n) $c_ " && read repOption
2019-12-15 02:55:15 +01:00
if [ [ $repOption = ~ ^( o| 1| yes| options| a| all) $ ] ] ; then isKalkun = 1; $MY_PATH /.install/4a-install_kalkun.sh || err += 1; fi ; repOption = $repOld
2019-12-14 21:45:36 +01:00
[ [ -z $repOption && -z $isKalkun ] ] && echo -e " ${ c_yellow } Voulez-vous installer l'interface web playSMS ? (o/n) $c_ " && read repOption
2019-12-15 02:55:15 +01:00
if [ [ $repOption = ~ ^( o| 1| yes| options| a| all) $ ] ] ; then $MY_PATH /.install/4b-install_playsms.sh || err += 1; fi ; repOption = $repOld
2019-12-10 04:56:02 +01:00
if [ [ $err ] ] ; then
2019-12-14 21:45:36 +01:00
echo -e " ---\n ${ c_red } L'installation générale n'est mal déroulé =( $c_ "
2019-12-10 04:56:02 +01:00
else
2019-12-14 21:45:36 +01:00
echo -e " ---\n ${ c_green } Félécitation ! L'installation de votre noeud G1SMS s'est terminé avec succès !\nBienvenue à bord =) $c_ "
2019-12-10 04:56:02 +01:00
fi
exit 0