Git Switch

Robert Delfs
Aug 7, 2017 · 4 min read

Do you ever occasionally check if you have acquired superpowers due to some kind of causality dilemma that you can not make dialectical heads-or-tails of without contemplating the linear cause-and-effect of the origins of your existence, and thus try to move things with your mind or shoot spaghetti out of your hands when no one is around just for the hell of it?

Well, I do.

Maybe it was a gas station burrito or my excessive caffeine consumption that tricked my DNA into developing a random mutation based on the perceived radioactivity brewing inside of me, so it’s always worth a shot.

Either way, my latest foray into telekinesis happened out of sheer laziness. One night I found myself repeating the unholy trinity of git commands:

  • git add .
  • git commit -m “<message>”
  • git push

I stressed and strained to push my code with my mind and in a moment of desperation, even attempted to invoke the spirit of Linus Torvalds, but to no avail.

While I could create an alias for said commands in my .bash_profile, I was long overdue for another Franken-Pi project, so I created a button that adds, commits, and pushes my code for me.

Here is how I chose to approach it…


Materials

  • Raspberry Pi
  • Breadboard
  • Jumper Wires (with Ribbon Cable since I only had male to male)
  • Tactile push switch
  • Blank SD card loaded with NOOBS
  • WiFi dongle or ethernet cable
  • HDMI cable to connect to external display

Once Raspbian was installed and booted, I configured my keyboard and WiFi and did the following from LXTerminal…


Installed and configured SSMTP

Made sure my repositories were up to date

  • apt-get update

Installed SSMTP and mail utilities

  • apt-get install ssmtp
  • apt-get install mailutils

Edited the SSMTP configuration file

  • vim /etc/ssmtp/ssmtp.conf
  • edited the following information…

Then I edited the SSMTP aliases file to include the email address I wanted to send emails from

  • vim /etc/ssmtp/revaliases

The format is: local_account:outgoing_address:mailhub[:port]

  • pi@raspberrypi:smtp.gmail.com:587 will work in most cases

Set the permissions of the SSMTP configuration file

  • chmod 774 /etc/ssmtp/ssmtp.conf

Set-up PHP and wrote script to send email

Edited the PHP ini file

  • vim /etc/php5/apache2/php.ini
  • changed the line which contained sendmail_path to sendmail_path = /usr/sbin/sendmail -t -i

Tested if PHP was configured to send email

  • created a file named mailtest.php in /home/pi

To monitor all code changes, I initialized a repository in the root folder where I keep all my other git repositories.

You may notice that the email is sending to trigger@recipe.ifttt.com. I will touch on that in a moment.

Tested the script by calling it from LXTerminal

  • PHP mailtest.php

To get this to work, I had to log into my google email account and follow the steps outlined HERE and HERE (must login to see page).


Created the push switch

This is the very simple example from the book “Raspberry Pi Cookbook” which simply connects pin 18 to GND as an input.

By connecting a switch to a GPIO pin, we can write a Python script that uses the RPi.GPIO library to detect button presses.

Once these steps were completed, I switched over to my Mac for the remainder of the setup.


Use an IFTTT recipe to create a text file from the delivered email and automagically put it in a Dropbox folder

IFTTT is a very awesome site that lets you create conditional statements which are triggered based on changes to various web services.

You can check it out at HERE (and I highly recommend you do so).

This is where the code gets fun! The shell script below runs the text file that we sent to Dropbox earlier as commands in the OS X terminal.


Run the above script when a file is put into Dropbox

My first thought was to write a Cron job to do this work but I later opted to use OS X’s built-in Automator.

I set up Automator to run the script when changes were made to my Dropbox folder, as shown below. I could achieve this easily because Dropbox was already integrated into my file system…

* Lightning strikes. Sparks fly. Franken-Pi descends from the ceiling on a platform suspended by cold clanking chains. *

Cackling, I fully actuate the switch which creates a short that allows current to flow unimpeded through the rest of the system. The Python script calls the PHP subprocess which sends an email of commands to be uploaded to Dropbox and run with a Bash script which, god willing, decides to push my code to Github instead of reversing entropy.

What a truly useless and multifarious creation I have enabled.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade