You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

55 lines
2.1 KiB

#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
# Version: 2020.03.21
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
########################################################################
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
ME="${0##*/}"
echo '
########################################################################
# \\///
# qo-op
############# '$MY_PATH/$ME'
########################################################################
# Activate / Desactivate ASTROPORT cron_MINUTE.sh job
########################################################################'
# Get crontab
crontab -l > /tmp/mycron
# DOUBLE CHECK (awk = nawk or gawk -i ?)
# Remove any previous line containing "SHELL & PATH"
# awk -i inplace -v rmv="cron_MINUTE" '!index($0,rmv)' /tmp/mycron
awk -i inplace -v rmv="SHELL" '!index($0,rmv)' /tmp/mycron
awk -i inplace -v rmv="PATH" '!index($0,rmv)' /tmp/mycron
crontest=$(cat /tmp/mycron | grep -F 'cron_MINUTE.sh')
if [[ ! $crontest ]]; then
## HEADER
[[ ! $(cat /tmp/mycron | grep -F 'SHELL') ]] && echo "SHELL=/bin/bash" > /tmp/newcron
[[ ! $(cat /tmp/mycron | grep -F 'PATH') ]] && echo "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" >> /tmp/newcron
cat /tmp/mycron >> /tmp/newcron
# ADD cron_MINUTE.sh line
echo "* * * * * /bin/bash $MY_PATH/../cron_MINUTE.sh 2>&1>/dev/null" >> /tmp/newcron
crontab /tmp/newcron
sudo systemctl enable ipfs
sudo systemctl start ipfs
echo "ASTROPORT is ON"
else
## HEADER
[[ ! $(cat /tmp/mycron | grep -F 'SHELL') ]] && echo "SHELL=/bin/bash" > /tmp/newcron
[[ ! $(cat /tmp/mycron | grep -F 'PATH') ]] && echo "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" >> /tmp/newcron
## REMOVE cron_MINUTE.sh line
cat /tmp/mycron | grep -Ev 'cron_MINUTE.sh' >> /tmp/newcron
crontab /tmp/newcron
sudo systemctl stop ipfs
sudo systemctl disable ipfs
echo "ASTROPORT is OFF"
fi
# Clean
rm -f /tmp/mycron /tmp/newcron
exit 0