├── README.md └── raspi_runner.sh /README.md: -------------------------------------------------------------------------------- 1 | Raspi Runner 2 | ============ 3 | Raspi Runner is a BASH script which will run all your scripts delivered by e-mail. I created this script for my Raspberry Pi, because it is always up and online waiting for commands. But this script can be of course used by any Unix based system with bash shell. 4 | 5 | Requirements 6 | ============ 7 | 1. Account on IFTTT.com - wicked sevice, for automatization! 8 | 2. Setup Dropbox Uploader - script for communication with Dropbox. Make sure, that Raspi Runner will be installed in a same folder like Dropbox Uploader! 9 | 3. Dropbox account 10 | 4. Pushover or free Pushbullet account (optional) - if you wanna use notifications delivered to your smartphone 11 | 12 | Getting started 13 | ============ 14 | 15 |
For quick configuration of Raspi Runner, please make script executable
35 | 36 | ```bash 37 | chmod +x raspi_runner.sh 38 | ``` 39 |and start it with command
40 | 41 | ```bash 42 | ./raspi_runner.sh 43 | ``` 44 |Raspi Runner will ask you few questions during initial setup.
45 |After this, Raspi Runner will create raspi_runner.cfg file with configuration.
46 | 47 | ```bash 48 | ./raspi_runner.sh 49 | You started Raspi Runner for the first time. 50 | Please answer few questions, which will be used for creation of config file. 51 | 52 | What is name of Dropbox folder, for Raspi Runner commands? (i.e. Raspi_Commands): Raspi_Commands 53 | what is the full path to your Dropbox Uploader? (i.e. /home/pi/Dropbox_Uploader): /home/pi/Dropbox_Uploader 54 | 55 | 56 | Please check, if displayed information are correct. 57 | *************************************************** 58 | Name of Dropbox folder: Raspi_Commands 59 | Full path to Dropbox Uploader installation: /home/pi/Dropbox_Uploader 60 | 61 | Are these values correct? [y/n]: y 62 | 63 | Raspi Runner setup is finished! 64 | *************************************** 65 | Please continue with setup of crontab according to README. 66 | If you are planning to use Pushover notifications on your smartfone, 67 | please follow instructions in README too. Little changes in Raspi Runner 68 | script will be necessary. 69 | 70 | Enjoy! 71 | ``` 72 |Usage of Raspi Runner is very simple. You just have to send e-mail with your BASH commands to e-mail address trigger@recipe.ifttt.com. from your e-mail account, which you used for setup of IFTTT.com.
93 | 94 |All commands delivered by e-mail to IFTTT.com will be converted to TXT files, which will be stored in folder e.i. Raspi_Commands on Dropbox. This folder is checked every 5 minutes by Raspi Runner and if any new file with commands is found, Raspi Runner will execute it. Thats it. Enjoy! ;)
95 | -------------------------------------------------------------------------------- /raspi_runner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Raspi Runner 4 | # 5 | # Author: Pavol Salgari 6 | # Twitter: @enkydu 7 | # Version: 1.06 8 | # 9 | # Copyright (c) 2013 enkydu 10 | # 11 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 12 | # this software and associated documentation files (the "Software"), to deal in 13 | # the Software without restriction, including without limitation the rights to 14 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 15 | # the Software, and to permit persons to whom the Software is furnished to do so, 16 | # subject to the following conditions: 17 | # 18 | # The above copyright notice and this permission notice shall be included in all 19 | # copies or substantial portions of the Software. 20 | # 21 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 23 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 24 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 25 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 26 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | 29 | 30 | # Check location of Raspi Runner 31 | script_path="$(readlink -f ${BASH_SOURCE[0]})" 32 | rr_home="$(dirname $script_path)" 33 | 34 | cd $rr_home 35 | 36 | # Check if there is any configuration file (raspi_runner.cfg) for Raspi Runner avaliable 37 | cfg=`ls . | grep raspi_runner.cfg | wc -l` 38 | 39 | # If NOT, then create new configuration file 40 | if [[ $cfg -eq 0 ]]; then 41 | echo "You started Raspi Runner for the first time." 42 | echo "Please answer few questions, which will be used for creation of config file." 43 | echo 44 | while (true); do 45 | echo -n "What is name of Dropbox folder, for Raspi Runner commands? (i.e. Raspi_Commands): " 46 | read rr_dboxstorage 47 | echo -n "what is the full path to your Dropbox Uploader? (i.e. /home/pi/Dropbox_Uploader): " 48 | read rr_dbuploader 49 | echo 50 | echo 51 | echo "Please check, if displayed information are correct." 52 | echo "***************************************************" 53 | echo "Name of Dropbox folder: $rr_dboxstorage" 54 | echo "Full path to Dropbox Uploader installation: $rr_dbuploader" 55 | echo 56 | echo -n "Are these values correct? [y/n]: " 57 | read answer 58 | if [[ $answer == y ]]; then 59 | break; 60 | fi 61 | done 62 | echo 63 | echo "Raspi Runner setup is finished!" 64 | echo "***************************************" 65 | echo "Please continue with setup of crontab according to README." 66 | echo "If you are planning to use Pushover notifications on your smartfone," 67 | echo "please follow instructions in README too. Little changes in Raspi Runner" 68 | echo "script will be necessary." 69 | echo 70 | echo "Enjoy!" 71 | echo 72 | mkdir $rr_dboxstorage 73 | echo "rr_dboxstorage=$rr_dboxstorage" > raspi_runner.cfg 74 | echo "rr_storage=$rr_home/$rr_dboxstorage" >> raspi_runner.cfg 75 | echo "rr_dbuploader=$rr_dbuploader" >> raspi_runner.cfg 76 | fi 77 | 78 | # Load configuration file for Raspi Runner 79 | . raspi_runner.cfg 80 | 81 | # Download new scripts delivered by mail from Dropbox to Raspberry Pi folder /home/pi/Raspi_Runner/Raspi_Commands 82 | $rr_dbuploader/dropbox_uploader.sh -q download /$rr_dboxstorage 83 | 84 | # Check for new files on Raspberry Pi 85 | check=`ls $rr_storage | wc -l` 86 | 87 | if [[ $check -eq 0 ]]; 88 | then exit 0 89 | fi 90 | 91 | files=`ls $rr_storage` 92 | 93 | # Grant rights for executing of delivered scripts 94 | for i in $files 95 | do 96 | chmod +x $rr_storage/$i 97 | done 98 | 99 | # Run all delivered scripts 100 | for i in $files 101 | do 102 | $rr_storage/$i > /dev/null 2>&1 103 | done 104 | 105 | # Push notification by Pushover 106 | 107 | # If you are using Pushover, you can recieve push notifications, with information, that scripts were executed. 108 | # Remove hash symbols (#) from following 6 rows, and fill in information regarding APP_TOKEN & USER_KEY, which you recieved from Pushover.com 109 | 110 | #time=`date` 111 | #curl -s \ 112 | # -F "token=APP_TOKEN" \ 113 | # -F "user=USER_KEY" \ 114 | # -F "message=$check script/s executed at $time." \ 115 | # https://api.pushover.net/1/messages.json > /dev/null 2>&1 116 | 117 | # Remove all scripts, which were already executed from Dropbox 118 | for i in $files 119 | do 120 | $rr_dbuploader/dropbox_uploader.sh -q remove /$rr_dboxstorage/$i 121 | done 122 | 123 | # Remove all scripts, which were already executed from Raspberry Pi 124 | rm $rr_storage/* 125 | --------------------------------------------------------------------------------