Author

Topic: Bitcoin Scripts for using USB w/ Linux Live CD (Read 1546 times)

hero member
Activity: 672
Merit: 500
BitLotto - best odds + best payouts + cheat-proof
Ubuntu comes with utility to format the USB and create an ext2 partition: System->Administration->Disk Utility
hero member
Activity: 672
Merit: 500
BitLotto - best odds + best payouts + cheat-proof
What it does:

It is a script that loads Bitcoin and uses the USB stick as the data directory for storing the blockchain. That way the user can use the Live CD over and over without having to start over and re-download the blockchain. It also "tricks" bitcoin into not storing the wallet on the USB stick. When it is unencrypted it only resides in RAM along with the whole Live CD. When Bitcoin is closed, it is encrypted and put on the USB stick. When done, the computer is rebooted and no trace of the unencrypted wallet will exist.

It creates an easy solution so people can use a Live CD all the time for when they want to use Bitcoin. This eliminates A LOT of risk with regards to viruses, spyware, and internet risks. The Live CD makes sure they are using Bitcoin in a clean and safe environment every time. They don't have to re-download the blockchain every time or deal with encrypting stuff themselves. It also makes sure that the wallet.dat file is NEVER stored on the USB stick unencrypted! It uses GPG to encrypt the wallet.dat after use and puts it on the USB stick.

To create the USB stick:

-format USB stick with a Linux partition (probably the only hard part but gparted is an easy tool for the job)
-create a folder on the USB stick eg. "bitlive"
-copy a linux Bitcoin binary into the "bitlive" folder
-create two text files named openwallet.sh and makewallet.sh and insert the code at the end of the post
-save the scripts in the "bitlive" folder and right click them and set the permissions to allow executing as a program
-THAT'S IT

Reboot using a modern Live CD and when it has loaded, insert the usb stick. Double click the script to run Bitcoin!

This comes with two scripts:

makewallet.sh (used rarely)
-used to create a brand new secure wallet in a Live CD setting
-if a wallet.dat file exists in .bitcoin already it will encrypt it and put it on the USB stick. This is useful if you have an existing wallet.dat file you want to continue using
-if no wallet.dat exists it will make a new one and encrypt it

openwallet.sh (main script to load Bitcoin)
-this will ask for the encrypted file to load off of the USB stick and decrypt it then load Bitcoin
-at the end it will ask to create another backup of the wallet.dat file.

Because the data is on a Linux partition it can be hard to see on a Windows computer. To backup you could either use a web browser on the Live CD and upload the encrypted file somewhere or use a tool to duplicate your usb stick. Uploading is probably the easiest but remember your file should have a good password. You could also use a web based email and send yourself the encrypted the wallet. Another way to backup your stuff is to load the hard drive while in the Live CD. It won't store anything on it other than what you copy. Just right click the encrypted file, select copy, and open your computers hard drive and paste it somewhere. Since it's encrypted, any viruses on your computer won't be able to open it if they find it.

makewallet.sh
Code:
#!/bin/bash

DIR="$( cd "$( dirname "$0" )" && pwd )"

echo "This script runs Bitcoin to create a new secure wallet."
echo "The new wallet will then be encrypted and stored in the"
echo "'bitlive' folder."
echo " "
echo "After the Bitcoin GUI loads please close Bitcoin."
echo " "
echo "If there is a wallet.dat already in the '.bitcoin' folder"
echo "it will be used and encrypted instead of a brand new wallet."
echo "This is useful if you want to keep an old wallet and use"
echo "it with these scripts. Just create a .bitcoin folder in the"
echo "home directory and copy your wallet.dat file there."
echo " "
echo "To improve the security of the encryption algorithms it is"
echo "recommended you either move the mouse around for a while or"
echo "type a bunch of random letters right here."
echo " "
echo "When done hit ENTER."

read random

if [ ! -f $HOME/.bitcoin/wallet.dat ];
then
     echo " "
echo "Now loading Bitcoin.........."
echo "......close Bitcoin when it is done loading........"
echo "When you close Bitcoin you may have to wait a few minutes"
echo "for the rest of the script to run. Do not close this script."
echo " "
     $DIR/bitcoin  
fi

if [ ! -f $HOME/.bitcoin/wallet.dat ];
then
echo "There seems to be a problem making the wallet.dat file."
echo "Hit ENTER to exit"
exit 1
fi

echo " "
echo " "
echo " "
echo "Now this script will encrypt the wallet.dat into"
echo "a filename you choose and it will ask for a password."
echo "The better the password the more secure your Bitcoins!"
echo "The encrypted wallet will be stored in your 'bitlive' folder."
echo " "
echo "What do you want to name the file that stores your wallet?"
echo "Type a unique name for the file then hit ENTER."

read filename

gpg -o $DIR/$filename -c --cipher-algo=AES256 $HOME/.bitcoin/wallet.dat

while [ $? -ne 0 ]; do
    gpg -o $DIR/$filename -c --cipher-algo=AES256 $HOME/.bitcoin/wallet.dat
done

echo "All Done. Your wallet is stored in: $filename "
echo "Hit ENTER to exit"
read random
exit 0

openwallet.sh
Code:
#!/bin/bash
DIR="$( cd "$( dirname "$0" )" && pwd )"

echo "This will load your encrypted wallet in the 'bitlive'"
echo "folder and load Bitcoin."
echo " "
echo "To improve the security of the encryption algorithms it is"
echo "recommended you either move the mouse around for a while or"
echo "type a bunch of random letters right here."
echo " "
echo "When done hit ENTER."

read random

echo " "
echo " "
echo "What is the name of the encrypted file you want to open?"
read filename

if [ ! -f $DIR/$filename ];
then
    echo "File not found! Hit ENTER to exit."
    read random
    exit 1
fi

echo "Creating a link if there isn't one already......"
ln -s $HOME/wallet.dat $DIR/wallet.dat

echo " "
echo "Enter the password to open the file. Bitcoin will load after"
echo "it is unencrypted. When done just close Bitcoin and wait for"
echo "the script to finish......."
echo " "

cp $DIR/$filename $HOME && gpg -o $HOME/wallet.dat -d $HOME/$filename && $DIR/bitcoin -datadir=$DIR -rescan


if [ ! -f $HOME/wallet.dat ];
then
    echo "Password failed! Hit ENTER to exit."
    read random
    exit 1
fi

echo " "
echo " "
echo "The wallet will now be encrypted again and put"
echo "in the 'bitlive' folder. Pick a new name for"
echo "the file. (adding the date makes it easy to keep"
echo "track of your backups. eg. 'file070411')"
echo "Hitting CTRL-C will close the script without"
echo "making a backup of your wallet.dat file!!!"
echo " "
echo "Always copy the files from your 'bitlive' folder"
echo "to other storage media in case your USB stick fails"
echo "or is lost/stolen. The wallet is never stored on your"
echo "USB stick unencrypted."
echo " "
echo "Enter the name for backup and hit ENTER"

read backup

gpg -o $DIR/$backup -c --cipher-algo=AES256 $HOME/wallet.dat

while [ $? -ne 0 ]; do
    gpg -o $DIR/$backup -c --cipher-algo=AES256 $HOME/wallet.dat
done


echo "All done. Hit ENTER to exit"
read random
exit 0

If you like it, feel free to tip me so I can pay my many bills: 1PoorwZ3jwjhSrjmz94Kx3m7VzQGqvnNUw
Jump to: