2010-12-15

How to run a Python script from Mac OS X Finder

Here is how to run a Python script from the Finder:

  • Make this the first line of your Python script "#!/usr/bin/env python"
  • Change the extension of the script file to ".command" i.e. my_python_script.command
  • In Terminal make the Python script file executable by running "chmod +x my_python_script.command"
  • Now when you double click the Python script in Finder it will open a terminal window and run.

2010-12-08

Checklist for making a home file, print and web server using Ubuntu and an old laptop

A couple years ago I did a detailed set of posts on turning an old laptop into a Ubuntu file, print, and web server. That laptop started having hardware problems so I decided to decommission it and replace it with another recently retired Dell Inspiron 1521 laptop. Here is a checklist of all the steps I did to convert the Windows Dell Inspiron 1521 laptop into a home file, print, and web server. If you are new to Linux you should read my original posts since this checklist assumes you have done stuff like this before.

  • Downloaded and burned CD for Ubuntu LTS 10.04 standard desktop
  • Installed Ubuntu standard desktop 10.04 on Inspiron 1521. I followed the prompts and used the default options.
  • Wrote over existing Windows file system rather than doing dual boot.
  • After Ubuntu was installed I started Synaptic and updated packages
  • Installed openssh-server and samba using Synaptic
  • Opened terminal and ran sudo tasksel to start program that offers a number of options for installing groups of packages for different functions.
  • Selected install LAMP server and followed prompts to install.
  • Using Firefox on new server I went to truecrypt website, downloaded latest Linux version (7a) to the Desktop, extracted file, double clicked it, and followed the prompts to install Truecrypt.
  • Edited /etc/network/interfaces (sudo nano /etc/network/interfaces) to make computer use fixed IP address by adding:
auto eth0
iface eth0 inet static
address 10.10.10.123
netmask 255.255.255.0
gateway 10.10.10.1
  • Rebooted new server to put new static IP address in effect
  • sudo aptitude install ntp (ntpdate was already installed)
  • Set up mount points for encrypted external hard drives:
  • sudo mkdir /media/encrypted1
  • sudo mkdir /media/encrypted2
  • Changed owner of mount points to match what smb.conf will use for them
  • sudo chown nobody:nogroup /media/encrypted1
  • sudo chown nobody:nogroup /media/encrypted2
  • Created directory for my custom scripts for new server: sudo mkdir /home/andy/scripts
  • Mounted new server as volume on remote MacBook using MacFusion (SSHFS)
  • Copied backup of custom scripts over to new server from MacBook
  • Checked ownership and permissions of custom scripts and changed them as needed.
  • Ran my custom script to mount truecrypt volumes (/media/encrypted1 etc)
  • Made these changes to /etc/samba/smb.conf (sudo nano /etc/samba/smb.conf)
  • workgroup = MYWORKGROUP
  • removed semi-colon before interfaces = 127.0.0.0/8 eth0
  • removed # before security = user
  • Added these under Share Definitions
[public]
comment = Public Share
path = /media/encrypted1
read only = No
force create mode = 777
force directory mode = 777
force user = nobody

[backup]
comment = Public Share
path = /media/encrypted2
read only = No
force create mode = 777
force directory mode = 777
force user = nobody

[pictures]
comment = Public Share
path = "/media/encrypted1/Documents/My Pictures"
read only = Yes
guest only = Yes
guest ok = Yes
  • sudo adduser spouse
  • sudo smbpasswd -a andy
  • sudo smbpasswd -a spouse
  • Rebooted new server
  • Ran custom script for mounting truecrypt volumes
  • Mounted samba share from remote MacBook and opened file to make sure everything was working properly.
  • sudo aptitude install phpmyadmin
  • From remote MacBook browsed to http://10.10.10.123/phpmyadmin and logged in as user root
  • Using phpmyadmin created a new user and gave this user all possible privileges on the MySQL database.
  • sudo adduser www
  • sudo nano /etc/apache2/sites-available/default
  • Changed the DocumentRoot value to /home/www/public and saved the file
  • Restarted Apache: sudo services apache2 restart
  • From remote MacBook did SSHFS mount as user www using MacFusion
  • Copied all html/php files from backup to /home/www
  • Used phpMyAdmin to create new user web_app_user with all data (but not structure or database administration) privileges. This is the MySQL user used by the web apps.
  • Used phpmyadmin to create new MySQL databases with same names as were used on the old server (including wordpress).
  • Used phpmyadmin to go into each database and then import the SQL file backup of that database.
  • Edited /etc/php5/apache2/php.ini to change session.gc_maxlifetime = 1440 to 1814400 (this prevents web app users from being logged out of web app shortly after they sign in)
  • Edited blank /etc/apache2/httpd.conf to add "ServerName myserversname". This prevents the annoying "Could not reliably determine the server's fully qualified domain name" message when you start apache2.
  • Restarted apache: sudo service apache2 restart
  • Tested that web applications work.
  • Got crontab setups from old server by doing contab -e as all users that had crontabs and writing down what was there.
  • Changed permissions on custom scripts that would be run by different users via crontab: chmod a+rwx scriptname.sh
  • Created logs directory in /home/andy: chmod -R a+rwx logs
  • Tested all backup scripts on new server.
  • Setup crontabs on new server using crontab -e
  • Configured CUPS for printer (not sure all of this is necessary)
  • sudo nano /etc/cups/cupsd.conf
  • In , and and
  • add:
  • Allow all
  • Commented out "Require user @OWNER @SYSTEM" where ever it appeared except for administrative tasks.
  • Changed:
  • Listen localhost:631
  • to:
  • Listen 631
  • Added the line: DefaultEncryption Never
  • sudo service cups restart
  • Browsed to 10.10.10.120:631 from remote machine
  • Add printer
  • Select HP LaserJet 1012 (HP LaserJet 1012), not the 1012 printer with USB in the name.
  • Name: HP_Shed
  • Description: HP LaserJet 1012
  • Location: Shed
  • Select Model: HP LaserJet 1012 - CUPS+Gutenprint v5.2.5(en)
  • Select default default options
  • Select modify printer just created
  • Click Select Another Make/Manufacturer
  • Select Make: Raw