#!/bin/bash MY_PATH="`dirname \"$0\"`" # relative MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized [[ -f $MY_PATH/../.profile ]] && source $MY_PATH/../.profile unset err pwdDB=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 42 | head -n 1) args=$@ [[ $args =~ noask ]] && noask=o && askSSL=o IP=$(ifconfig | grep "inet " | grep -v "127.0.0.1" | awk '{ print $2 }') [[ ! $PSMS_DOMAIN ]] && echo -e "${c_yellow}Choisissez un nom de domaine pour PlaySMS (Sinon $IP sera choisi): $c_" && read PSMS_DOMAIN [[ ! $PSMS_DOMAIN ]] && PSMS_DOMAIN=$IP && askSSL=n && noask=o DOMAIN=$PSMS_DOMAIN ## Install PHP + MySQL $MY_PATH/1-install_requirements.sh php ## Create database if [[ $(sudo mysql -e "show databases;" | grep gammu) ]]; then pwdDB=$(cat /etc/gammu-smsdrc | grep "password" | grep -v "# " | awk '{ print $3 }') else sudo mysql -e "CREATE DATABASE gammu" sudo mysql -e "CREATE USER 'gammu'@'localhost' IDENTIFIED BY '$pwdDB';" sudo mysql -e "GRANT ALL PRIVILEGES ON gammu.* TO 'gammu'@'localhost';" sudo mysql -e "FLUSH PRIVILEGES;" fi ## Clone repo playSMS [[ -d $MY_PATH/playsms ]] && sudo rm -rf $MY_PATH/playsms git clone https://github.com/antonraharja/playSMS.git $MY_PATH/playsms cp $MY_PATH/templates/4b/install-playsms.conf $MY_PATH/playsms/install.conf sed -i "s/_pwdDB/$pwdDB/g" $MY_PATH/playsms/install.conf [[ -d /var/www/playsms ]] && sudo rm -rf /var/www/playsms sudo chmod u+x $MY_PATH/playsms/install-playsms.sh cd $MY_PATH/playsms sed -i "s/read /confirm=y; #read /g" install-playsms.sh sudo ./install-playsms.sh sudo sed -i "/ishttps/d" /var/www/playsms/config.php sudo sed -i "/http or https*/a \$core_config['ishttps'] = true;" /var/www/playsms/config.php [[ -d $MY_PATH/playsms ]] && sudo rm -rf $MY_PATH/playsms cd $MY_PATH ## Start playsmsd on boot sudo /usr/local/bin/playsmsd start if [[ -f /etc/rc.local ]]; then [[ ! $(grep playsmsd /etc/rc.local) ]] && sudo sed -i '/^exit 0.*/i /usr/local/bin/playsmsd start' /etc/rc.local else echo "/usr/local/bin/playsmsd start" | sudo tee /etc/rc.local fi ## Tests if [[ $(sudo playsmsd status) =~ "is running" ]]; then echo -e "${c_green}playSMS a été installé correctement et le daemon est démarré =)$c_" else echo -e "${c_red}Une erreur est survenu$c_" err=1 fi ## Config NGINX [[ ! -d /etc/nginx/def_conf ]] && sudo mkdir /etc/nginx/def_conf/ sudo cp $MY_PATH/templates/rproxy/proxypass.conf /etc/nginx/def_conf/ sudo cp $MY_PATH/templates/4b/playsms.conf /etc/nginx/conf.d/ sudo sed -i "s/_DOMAIN/$DOMAIN/" /etc/nginx/conf.d/playsms.conf ## Active SSL echo -e "${c_yellow}playSMS ne fonctionne pas sans certifcat SSL.$c_" [[ ! $noask ]] && printf "${c_yellow}Voulez-vous installer et activer un certificat SSL maintenant pour $DOMAIN ? (o/n) $c_" && read askSSL if [[ $askSSL =~ ^(o|y|yes|oui|Y|O|YES)$ ]]; then $MY_PATH/ssl.sh certif APP=playsms DOMAIN=$DOMAIN if sudo test -f /etc/letsencrypt/live/$DOMAIN/fullchain.pem; then $MY_PATH/ssl.sh on APP=playsms DOMAIN=$DOMAIN else echo -e "${c_red}Une erreur s'est produite, basculement vers le mode non SSL$c_" $MY_PATH/ssl.sh off APP=playsms DOMAIN=$DOMAIN fi http=https else $MY_PATH/ssl.sh off APP=playsms DOMAIN=$DOMAIN http=http fi sudo service nginx restart if [[ $err ]]; then echo -e "${c_red}Installation incomplète$c_" exit 1 else echo -e "${c_green}PlaySMS est accessible via l'URL $http://$DOMAIN$c_" exit 0 fi