Tuesday, 21 September 2010

Script for installing SABnzbd on FreeNAS 0.7.1

1. Copy this text into a new text file and save as sabnzbd.sh


Script:

#!/bin/bash

#Define the architeture of the box
arch=`uname -m`
echo "      *******Archeticture of Machine is" $arch "*******"

echo
#Pull latest version number and assign to variable and then display it
stable=($(fetch -q -o - http://sabnzbdplus.sourceforge.net/version/latest | awk '/0/{gsub(/\015/,"");print}'))
beta=($(fetch -q -o - http://sabnzbdplus.sourceforge.net/version/latest | awk '/2/{gsub(/\015/,"");print}'))
echo "         Latest SABnzbd Stable version is: $stable"
echo "         Latest SABnzbd Beta version is: $beta"

#Menu
echo ""
echo "          Which Version do you wish to Install?"
echo "          ----- ------- -- --- ---- -- --------"
echo
echo "[1] Upgrade/Install SABnzbd 0.5.0 (tested good)"
echo "[2] Upgrade/Install latest STABLE SABnzbd $stable"
echo "[3] Upgrade/Install lastest BETA SABnzbd $beta"
echo "[4] Exit"
echo

#Reads the input user puts in assigns to "option"
read option

#Acts upon what user entered
case "$option" in
  "1")
echo 
echo "*******Selected Option 1: SABnzbd 0.5.0 (tested good)*******"
echo
echo "Downloading SABnzbd 0.5.0"
fetch "http://downloads.sourceforge.net/project/sabnzbdplus/sabnzbdplus/sabnzbd-0.5.0/SABnzbd-0.5.0-src.tar.gz"
;;

  "2")
echo 
echo "*******Selected Option 2: Latest STABLE SABnzbd $stable*******"
echo
echo "Downloading latest STABLE SABnzbd $stable"
fetch http://downloads.sourceforge.net/project/sabnzbdplus/sabnzbdplus/sabnzbd-${stable}/SABnzbd-${stable}-src.tar.gz
;;
  
  "3")
echo 
echo "*******Selected Option 2: Latest BETA SABnzbd $beta*******"
echo
echo "Downloading latest BETA SABnzbd ($beta)"
fetch http://downloads.sourceforge.net/project/sabnzbdplus/sabnzbdplus-beta/${beta}/SABnzbd-${beta}-src.tar.gz
;;
 "4")
echo
echo "Exiting"
exit
;;
    * )
echo
echo "Wrong selection nothing selected"
echo "Exiting"
exit
;;
esac

echo
echo
#Continues with script
echo "*******1. Installing the required prerequisites*******"
echo "--Installing SABnzb (0.4.8)--"
pkg_add -r sabnzbdplus
echo "--Installing py25-yenc--"
pkg_add -r py25-yenc
echo "--Installing unzip--"
pkg_add -r unzip
echo "--Installing py25-pysqlite-2.3.5--"
pkg_add -r "ftp://ftp.freebsd.org/pub/FreeBSD/ports/$arch/packages-7.2-release/All/py25-pysqlite-2.3.5.tbz"
echo "--Starting SABnzbd (to generate config file)--"
/usr/local/bin/SABnzbd.py -d -f /root/.sabnzbd/sabnzbd.ini
echo "--Shutting down SABnzb--"
/usr/bin/fetch "http://localhost:8080/sabnzbd/api?mode=shutdown"
echo "*******2. Removing outdated files/folders*******"
rm -rf /usr/local/lib/python2.5/site-packages/cherrypy
rm -rf /usr/local/lib/python2.5/site-packages/sabnzbd
rm -rf /usr/local/share/sabnzbdplus/interfaces
rm -rf /usr/local/share/sabnzbdplus/language
rm -rf /usr/local/bin/SABnzbd.py
echo "--done--"
echo "*******3. Extracting updated version of SABnzbd*******"
cd /root/
echo "--Extracting upgrade--"
tar -xzf SABnzbd*
echo "--Extracted upgrade--"
cd SABnzbd*
echo "--done--"
echo "*******4. Moving/Installing newer version of SABnzbd*******"
mv cherrypy /usr/local/lib/python2.5/site-packages/cherrypy
mv sabnzbd /usr/local/lib/python2.5/site-packages/sabnzbd
mv interfaces /usr/local/share/sabnzbdplus/interfaces
mv language /usr/local/share/sabnzbdplus/language
mv SABnzbd.py /usr/local/bin/SABnzbd.py
chmod 0555 /usr/local/bin/SABnzbd.py
ln -s /usr/local/bin/python2.5 /usr/bin/python
ln -s /usr/local/share/sabnzbdplus/interfaces /usr/local/bin/interfaces
ln -s /usr/local/share/sabnzbdplus/language /usr/local/bin/language
echo "--done--"
echo "*******5. Deleting extra files*******"
cd /root/
rm  SABnzbd*.gz
rm -rf SABnzbd*
echo "--done--"
echo "*******Done - SABnzbd should be installed*******"


Copy the file onto your FreeNAS box on one of the shares you setup.

Run the script from the command line.

Follow my other post on how to create and run scripts on FreeNAS.




How to execute a script in FreeNAS

Using Script in Freenas consists of a few steps:
1. Creating file
2. Apply correct permissions
3. Run script in CLI
4. Run script as a CRON job.

AD.1 How to create the file:
In Advanced|Execute command You type:

CODE: SELECT ALL
touch /mnt/YOUR_MOUNT_NAME/YOUR_SCRIPT_NAME.sh


AD.2 Correct permissions:
In Advanced | Execute command type:

CODE: SELECT ALL
chmod u+x /mnt/YOUR_MOUNT_NAME/YOUR_SCRIPT_NAME.sh


AD.3 Run script from CLI
*********** TO VERIFY ***********

CODE: SELECT ALL
#/bin/sh /mnt/YOUR_MOUNT_NAME/YOUR_SCRIPT_NAME.sh


AD.4 Add script to Cron
In System|Advanced|Cron add new job.
As command put :

CODE: SELECT ALL
/mnt/YOUR_MOUNT_NAME/YOUR_SCRIPT_NAME.sh


UPDATE:
Additionally if Cron failed to run the script you can try;
CODE: SELECT ALL
/bin/bash -x
at the beggining of the script line ie:

CODE: SELECT ALL
/bin/bash -x /mnt/YOUR_MOUNT_NAME/YOUR_SCRIPT_NAME.sh


After running this command You should get: The cron job has been executed successfully.

Thursday, 16 September 2010

How to rotate multiple photos in finder

I have a number of photos that are the wrong orientation. I wanted to rind a way to rotate are large number of photos all at once. Finder doesn't have a rotate button ( not that I could find anyway )

So I Google'd it and found this ..

  1. Create a new folder on your Desktop.
  2. Right click (Control click) to Attach Folder Action.
  3. You'll get the Folder Actions Scripts.
  4. Go down to the Image-Rotate (left or right) and attach
  5. Then just drop the images in that folder.

Tuesday, 14 September 2010

HOWTO install SABnzbd on FreeNAS 0.7.2


Requirements -

Freenas - 0.7.2 Sabanda (revision 5266) embedded running from CF card
Platform - amd64-embedded on AMD Phenom(tm) II X2 555 Processor
4 Drives Raid 5 Array.


THIS IS ONLY FOR FREENAS VERSION 0.7.2!!!!!
There are other post that detail the older versions of freenas.


So I have been doing alot of research trying to install SABnzbd on the lastest version of Freenas which is built on FreeBSD 7.3. This will be a 2 post HOWTO, Post 1 I will show you how to install SABnzbd that is ported to FreeBSD 7.3 (SAB Ver 0.4.12). The issue with this, is that starting from FreeBSD version 7.3, the default python install is 2.6 and SAB 0.4.XXX version doesnt really like that version of python so it runs up the CPU. CPU was running above 50%. SAB recommends ver 0.5 or above for python 2.6. So Post 2 I will show you how i upgraded my version.

NOTE: I am not a developer, well not a unix dev, i do alot of web dev but never OS. I used google to help me though most of this. And this fourm, so you will find that my script is like others listed here.

OK on to it...

***** Pre Prereq *****
Turn on SSH and log on as root.

****** Prereq *****
1. I have the AMD64 version of Freenas (multi core processor), so i am downloading packages for my version, you would have to make the changes to the script. Simple Copy/Paste, replace AMD64 with i386. 
2. Since this is the embedded version, I have freenas running from a CF card (CF to IDE), we would need to install the packages to whatever HDD we mounted. In my case i have a Raid5 Mount. I named my mount "Raid5A1" - Stands for Raid 5 Array 1. Below is the folder structure.
/mnt
Raid5A1/
local/ <--- This is where i have all the packages, only accessable via SSH or SFTP
Media/ <-- This is my SMB share where all my files are.


In the script we need to define 3 different things.
hostname="freenas" <-- Server Name
dest="/mnt/Raid5A1/local" <-- Where the packages live
configuration="/mnt/Raid5A1/Media/sabnzbd" <--- Where SAB Config and downloads live.


Once you have that, you can edit the script, Save as installsab.sh and upload to /mnt/Raid5A1/
Dont worry about creating the Directory as it creates it for you.


CODE: 
#!/bin/sh
# author: Ray Matos
#date: Sept 2th 2010

python_version="2.6"

hostname="freenas"
dest="/mnt/Raid5A1/local"
configuration="/mnt/Raid5A1/Media/sabnzbd"

echo "host: $hostname"
echo "destination path: $dest"
echo "configuration path: $configuration"

mkdir ${dest}
cd ${dest}

#create temporary dummy variables and links that will disappear at either the end of the script or at reboot.
#these environment variables and symbolic links faciliate clean install on alternate directory
#this has to do with the fact that both sabnzbd and cheetah have hardcoded paths (non configurable) in either their installation or executable software
#so these will also be included in init script

echo "@@ creating symlinks and environment variables"
PKG_TMPDIR=$dest; export PKG_TMPDIR
PYTHONPATH=${dest}/lib/python${python_version}/site-packages; export PYTHONPATH
ln -s ${dest}/bin/python /usr/local/bin/python
ln -s ${dest}/bin/python${python_version} /usr/local/bin/python${python_version}
ln -s ${dest}/bin/easy_install /usr/local/bin/easy_install
ln -s ${dest}/bin/easy_install-${python_version} /usr/local/bin/easy_install-${python_version}
ln -s ${dest}/lib/python${python_version}  /usr/local/lib/python${python_version}
ln -s ${dest}/share/sabnzbdplus /usr/local/share/sabnzbdplus 

echo "@@ install sabnzbplus, unrar, unzip, yenc and par2 packages"
pkg_add -r unrar unzip par2cmdline sabnzbdplus ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-7.3-release/Latest/py26-yenc.tbz ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-7.3-release/Latest/py26-pysqlite.tbz -P $dest

echo "--Starting SABnzbd (to generate config file)--"
${dest}/bin/SABnzbd.py -f ${configuration}/sabnzbd.ini
echo "--Shutting down SABnzb--"
/usr/bin/fetch "http://$hostname:8080/sabnzbd/api?mode=shutdown"



echo "*******Done - SABnzbd should be installed*******"

rcscript=${dest}/etc/rc.d/sabnzbplus
echo "@@ creating init script: $rcscript"

echo "#! /bin/sh" > $rcscript
echo "case "\$1" in"  >> $rcscript
echo "start)" >> $rcscript
echo "echo \"Starting SABnzbd."\" >> $rcscript
echo "dest=$dest" >> $rcscript
echo "python_version=$python_version" >> $rcscript
echo "# re-create symlinks as they are placed on ramdisk and get lost on shutdown" >> $rcscript
echo "ln -s \${dest}/bin/python /usr/local/bin/python" >> $rcscript
echo "ln -s \${dest}/bin/python\${python_version} /usr/local/bin/python\${python_version}" >> $rcscript
echo "ln -s \${dest}/lib/python\${python_version}  /usr/local/lib/python\${python_version}" >> $rcscript
echo "ln -s \${dest}/share/sabnzbdplus /usr/local/share/sabnzbdplus" >> $rcscript
echo "ln -s \${dest}/share/sabnzbdplus/interfaces /usr/local/bin/interfaces" >> $rcscript
echo "ln -s \${dest}/share/sabnzbdplus/language /usr/local/bin/language" >> $rcscript
echo "PATH=\$PATH:\${dest}/bin; export PATH" >> $rcscript
echo "\${dest}/bin/SABnzbd.py -d -f ${configuration}/sabnzbd.ini" >> $rcscript
echo ";;"  >> $rcscript
echo "stop)" >> $rcscript
echo "echo \"Shutting down SABnzbd.\"" >> $rcscript
echo "/usr/bin/fetch \"http://$hostname:8080/sabnzbd/api?mode=shutdown\" > /dev/null" >> $rcscript
echo ";;"  >> $rcscript
echo "*)" >> $rcscript
echo "echo \"Usage: \$0 {start|stop}\" "  >> $rcscript
echo "exit 1"  >> $rcscript
echo ";;"  >> $rcscript
echo "esac" >> $rcscript

chmod a+x $rcscript


**** Run the Script *****


CODE: 
cd /mnt/Raid5A1/
./installsab.sh


There will be a point where you see SAB start, you might need to hit CTRL-C for it to proceed to the next steps.

***** After you run the script *****
Go find your sabnzbd.ini file, it should be located where the config location you set earlier.
Find the line that says HOST: localhost, replace localhost with your IP, in my case 192.168.50.40


Once you do that Run the following


CODE: 
/mnt/Raid5A1/local/etc/rc.d/sabnzbplus start 


Now go to http://192.168.50.40:8080/sabnzbd

It should now be installed.

***** Start and Stop on Freenas web UI *****
Go to System -> Advanced -> Command Scripts 

Add


CODE: 
/mnt/Raid5A1/local/etc/rc.d/sabnzbplus start


Type: PostInit


Add


CODE: 
/mnt/Raid5A1/local/etc/rc.d/sabnzbplus stop


Type:Shutdown


Thats it, now go and try it :))

Thursday, 9 September 2010

Completely Remove iTunes from Mac OS X

In some rare instances, it may be required to remove all traces of iTunes from your computer. Use the following steps to remove iTunes from Mac OS X.

Note: If you are having issues with iTunes or other applications, you should first run Disk Utility. iTunes library content such as music, videos, and iPod games are saved in your Music folder by default and are not deleted by removing iTunes or it's associated files and folders. If you are having issues with content of your iTunes library tryre-creating it.
  1. Quit iTunes.
  2. In the Finder, choose Go > Applications.
  3. Locate iTunes and then drag it to the Trash.
  4. Choose Go > Utilities. If Utilities is not available under Go, then choose Go > Go to Folder, type in/Applications/Utilities/, and then click Go.
  5. Open Activity Monitor.
  6. In the process list locate and select iTunes Helper. Click Quit Process. When asked if you really want to quit the process, click Quit. Choose iTunes Helper in Activity Monitor
  7. Quit Activity Monitor.
  8. Open System Preferences (choose Apple > System Preferences).
  9. Choose View > Accounts and then click Login Items.
  10. Look for the iTunesHelper entry and select it, then click the "-" button to remove it from the list.
    iTunesHelper selected
  11. Quit System Preferences.
  12. From the Finder, choose Go > Go to Folder
  13. Enter (without quotes) "/System/Library/Extensions" and then click Go.
  14. Locate the file "AppleMobileDevice.kext" and drag it to the Trash.
  15. Choose Go > Go to Folder.
  16. Enter (without quotes) "/Library/Receipts/" and then click Go.
  17. Locate the file "AppleMobileDeviceSupport.pkg" and drag it to the trash.  Note: This file may not be present in Mac OS X v10.6 or later; skip to the next step if this is the case.
  18. Remove any other file ending with ".pkg" that has iTunes in the title (such as "iTunesX.pkg").
  19. Restart your Mac.
  20. Empty the Trash. This should fully remove iTunes.
Additionally, you may need to remove files and folders associated with iTunes. Use the following steps to remove these files and folders.
  1. In the Finder, choose Go > Go to Folder and type in ~/Library/ and click Go.
  2. Locate the iTunes folder and then drag it to the Trash.
  3. Choose Go > Go to Folder and type in ~/Library/Preferences/ and click Go.
  4. Locate the preference files that have names beginning with com.apple.iTunes and move them to the Trash.
    File Names should be:
    • com.apple.iTunes.eq.plist
    • com.apple.iTunes.plist
    • com.apple.iTunesHelper.plist
  5. Choose Go > Go to Folder and type in /Library and click Go.
  6. Locate the iTunes folder, and then move it to the Trash.
  7. Choose Go > Go to Folder and type in ~/Library/Preferences/ByHost/ and click Go.
  8. Locate the preference files that have names beginning with com.apple.iTunes and move them to the Trash.
  9. Empty the Trash. This should fully remove the files and folders associated with iTunes.
To reinstall iTunes please download and install the latest version.

Saturday, 4 September 2010



HOW TO RESTORE FROM JAILBREAK

To this end, I have constructed a server that duplicates the functionality exposed by Apple's signature server, except using "on file" results rather than live requests.
All we need, then, is to make iTunes use it. Luckily, most operating systems also have the ability to locally define bypasses on specific hostnames through a file calledhosts. Using this, we can redirect requests to Apple's signature server to Cydia.
So, open the file C:\Windows\System32\drivers\etc\hosts (Windows) or/etc/hosts (Mac OS X) and add the following entry to the bottom of the file.
74.208.10.249 gs.apple.com
Now, when iTunes thinks it is talking to Apple, it is talking to Cydia instead. Doing this will allow iTunes to access signatures already stored by Cydia's "on file" feature.
This server will also act as a cache for any SHSH blobs it hasn't seen, acting as an intermediary to Apple's server. This effectively registers your device with the "on file" mechanism, which means you can now enjoy the protections of being able to downgrade your firmware in the future even if you aren't jailbroken.
This point should be stressed: even if you don't jailbreak, and even if you never intend to jailbreak, you should consider using the new "on file" service.
Let's say that Apple releases an OS upgrade in the future, you take it, and they break something important. Maybe they break your e-mail account, or your todo list. Your business is now crippled.
If only you could downgrade, right? Alas, Apple won't let you anymore. That's where the new signature cache server comes in: by doing your restores through this server you secure your ability to not accept upgrades from Apple if the need is dire.

How to edit the hosts file in Mac OS X – Leopard

How to edit the hosts file in Mac OS X – Leopard

Introduction
The hosts file is a text file that maps hostnames to IP addresses.
Upon typing a url address on the browser, the system is checking if there is a relevant entry on the hosts file and gets the corresponding IP address, else it resolves the IP via the active connection’s DNS servers.
The hosts file can be edited to block certain hostnames (like ad-serving/malicious hosts), or used for web development purposes, i.e. to redirect domains to local addresses.
Editing the hosts file
Editing the hosts file in Mac OS X – Leopard, is a pretty easy task, especially if you are familiar with the terminal.
Step 1 – Open the Terminal.app
Either by start typing Terminal on the Spotlight, or by going into Applications -> Utilities -> Terminal.
Step 2 – Open the hosts file
Open the hosts by typing on the Terminal that you have just opened:
1$ sudo nano /private/etc/hosts
Type your user password when prompted.
Step 3 – Edit the hosts file
The hosts file contains some comments (lines starting with the # symbol), as well as some default hostname mappings (e.g. 127.0.0.1 – localhost).
Simply append your new mappings underneath the default ones. Or edit one of the default values if you know what you are doing!
You can navigate the file using the arrow keys.
Step 4 – Save the hosts file
When done editing the hosts file, press control-o to save the file.
Press enter on the filename prompt, and control-x to exit the editor.
Step 5 – Flush the DNS cache
On Leopard you can issue a simple Terminal command to flush the DNS cache, and have your host file changes to take immediate effect:
1$ dscacheutil -flushcache
You can now test your new mapping on the browser!