Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Siobhan's Setup: A simple python script to configure Rasbian after a clean install.
#!/usr/bin/env python
Siobhan's Setup
A simple python script to configure Rasbian after a clean install (to a specific setup).
Does the following steps
Update system
Install transmission
Overclock & send audio over hdmi
Set OMXPlayer as a desktop app
Create default folders & shortcuts
And definitely not hack into the pentagon.
Run as:
sudo python
But yeah, don't just run this script as-is.
I'm just sharing it out as an example for what you could do to make things a a bit easier
if you're doing a bunch to testing with re-flashing sd cards and such, or if it's easier
to write up what you need to do on your main desktop, then dump a script over to the Pi.
Things to look out for:
There's pretty much no error checking in this.
It's written and tested with Raspbian Feb, 2013 (Debian 7), and likely to break in
newer or older versions.
All files are created as temp files first, then moved into place.
And yeah, the script has gotten a bit copy-and-pastey-messy and I probably should use
dedent to clean up these printed strings, and blab blah blah, but hey it's just a dumb
setup script to avoid a bunch of command line work.
And yeah - it doesn't really matter what your name is, just delete from "if 'yourname'...
to "else:" and dedent the rest.
But hrm - if I have to explain that then you really shouldn't be running this so blindly,
you never know what sort of mischevious doings I might have included in here. mwahahaha.
import optparse
import os
import sys
import json
import base64
def main():
description = """ Siobhan's Setup: Update system, Overclock & send audio over hdmi,
set OMXPlayer as a desktop app, install Transmission client."""
usage = "usage: sudo %prog "
version = "%prog version 0.1"
p = optparse.OptionParser(description=description,
options, arguments = p.parse_args()
if 'yourname' is not 'Siobhan':
print """
BOO! HISS! This script isn't for you!
...or in simpler terms, don't just run an OS-modifying script on your system without
checking what it actually does first.
Read the source/description first:
print '''
1. Do a general system update:
os.system('sudo apt-get -y update')
os.system('sudo apt-get -y upgrade')
# os.system('sudo apt-get -y autoremove') # to clear any dead files
print '''
2a. Install transmission client:
os.system('sudo apt-get -y install transmission')
2b. If you do want the full daemon server:
(from here: )
uncomment this next bunch:
os.system('sudo apt-get -y install transmission transmission-daemon')
os.system('sudo service transmission-daemon start')
os.system('sudo service transmission-daemon stop')
settings_file = '/etc/transmission-daemon/settings.json'
settings = json.load(open(settings_file))
settings["rpc-whitelist-enabled"] = False
settings["rpc-enabled"] = True
settings["rpc-username"] = 'pi'
settings["rpc-password"] = 'raspberry'
json.dump(settings, open(settings_file, 'w'), indent=4, sort_keys=True)
os.system('sudo service transmission-daemon start')
print '''
3. Update boot/config to:
* use hdmi
* allow audio over hdmi
* apply 'mild' overclocking setting
* double the ram for the gpu
tmp_file = '/tmp/boot_config.txt'
dst_file = "/boot/config.txt"
input = open(dst_file)
config_text =
if "#hdmi_drive=2" in config_text:
# force hdmi:
config_text = config_text.replace("#hdmi_drive=2", "hdmi_drive=2")
# mild overclock settings:
config_text = config_text.replace("#arm_freq=800", "arm_freq=800")
config_text = config_text.replace("gpu_mem=64", """gpu_mem=128
# modified by
output = open(tmp_file, "w")
os.system('sudo mv %s %s' % (tmp_file, dst_file))
print '''
4. Create desktop app entry for OMXPlayer:
tmp_file = '/tmp/omxplayer.desktop'
dst_file = "/usr/share/applications/omxplayer.desktop"
output = open(tmp_file, 'w')
output.write("""[Desktop Entry]
Exec=lxterminal --command "omxplayer -o hdmi -t on --align center %f"
os.system('sudo mv %s %s' % (tmp_file, dst_file))
print '''
5. set up standard folders & shortcuts.
adds network & the proper apps link to the sidebar
tmp_file = '/tmp/.gtk-bookmarks'
dst_file = "/home/pi/.gtk-bookmarks"
bkmk_file = """network:/// Network
file:///usr/share/applications Apps"""
dirlist = ['Music','Movies', 'Pictures']
for d in dirlist:
path = '/home/pi/' + d
if not os.path.isdir(path):
bkmk_file = bkmk_file + "\nfile://" + path + " " + d
output = open(tmp_file, 'w')
os.system('sudo mv %s %s' % (tmp_file, dst_file))
# and a few other cleaning up bits:
# create file browser link on desktop:
os.system('cp /usr/share/applications/pcmanfm.desktop /home/pi/Desktop/')
# use a proper browser in the launch bar:
tmp_file = '/tmp/panel'
dst_file = '/home/pi/.config/lxpanel/LXDE/panels/panel'
input = open(dst_file)
config_text =
if "lxde-x-www-browser.desktop" in config_text:
config_text = config_text.replace("lxde-x-www-browser.desktop", "midori.desktop")
output = open(tmp_file, "w")
os.system('sudo mv %s %s' % (tmp_file, dst_file))
# hack into the pentagon
os.system('haxxor the-pentagon')
# and plant a virus:
print base64.b64decode('VGhpcyBpcyB0aGUgQ0lBLCB3ZSd2ZSBnb3QgYWxsIHlvdXIgZGV0YWlscyBub3csIHByZXBhcmUgdG8gYmUgZXh0cmFvcmRpbmFyaWx5IHJlbmRpdGlvbmVkLi4u')
print '''
You probably need to reboot now, but I'll leave that up to you.
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment