G1sms/rc.local.sh

72 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
######################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
# This script modify rc.local to start G1sms+ G1Tag, G1Tx and _CopyLaRadio scripts
######################################################################
# INJECT it self into /etc/rc.local
######################################################################
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
######################################################################
#################### INCEPTION / INSERTION ###########################
######################################################################
inserted=$(grep -Rw "rc.local.sh" /etc/rc.local)
if [[ ! $inserted ]]; then
sudo sed -i s/exit\ 0//g /etc/rc.local
sudo echo "include $MY_PATH/rc.local.sh" >> /etc/rc.local
sudo echo "exit 0" >> /etc/rc.local
fi
######################################################################
#### WRITE SYSTEM STARTUP COMMANDS HERE........
######################################################################
# mpd Runs like pi and some rights are bad!!
chown -R pi /var/run/mpd
chown -R pi /run/mpd
# RESET LOG
echo "" > /var/log/mpd/mpd.log
# CREATE EXCHANGE FILEs for pi & www-data
touch /tmp/ytdl.list
chmod 664 /tmp/ytdl.list
chown pi:www-data /tmp/ytdl.list
touch /tmp/youtube-dl.log
chmod 664 /tmp/youtube-dl.log
chown pi:www-data /tmp/youtube-dl.log
# LAUNCH BUTTONS WATCH
su pi -c "$MY_PATH/_CopyLaRadio/watch.sh &"
# LAUNCH COPY SCRIPT
su pi -c "$MY_PATH/_CopyLaRadio/copy.sh &"
# Print the IP address
_IP=$(hostname -I | cut -d " " -f 1) || true
if [ "$_IP" ]; then
printf "IP address is %s\n" "$_IP"
$MY_PATH/shell/parle.sh "Adresse IP: $_IP"
youtube-dl -U
$MY_PATH/shell/parle.sh "Mise à jour de Youtube DL. Terminé!"
#IPFS
YOU=$(ps aux --sort=+utime | grep ipfs | tail -n 1 | cut -d " " -f 1)
if [[ "$YOU" != "" && "$YOU" != "root" ]]; then
$MY_PATH/shell/parle.sh "IPFS OK. Système de fichier interplanétaire activé."
fi
else
$MY_PATH/shell/parle.sh "Connexion Internet Impossible!"
fi
# LANCEMENT G1Tag READ
if [[ -e "/dev/ttyACM0" ]]; then
cd $MY_PATH && ./shell/tag_READ.sh &
$MY_PATH/shell/parle.sh "Lecteur G1 tag"
fi
if [[ -d "$MY_PATH/www/rompr" ]]; then
$MY_PATH/shell/parle.sh "Jukebox interplanétaire accessible"
fi