Mint Serena 64 bit using the Mate desktop environment. Most of the following scripts will run on this machine, although some have only been tested with the Gnome desktop. Extra software requirements can be met by the Ubuntu and safe PPA repositories. Scripts may be re-written or added to from time to time, the date serves as the version number. Syntax highlighting on these pages is provided by GVim's "Convert to HTML" option.

File Transfer


#!/bin/bash
# Filename: ssh-transfer
# Version: 140713
# Author: robz
#
# This little script automates the transfer of media files from my PC to my XBMC
# media centre, which runs on the embedded Openelec operating system installed
# on a Raspberry Pi credit-card computer.
# First install the rsync utility on your XBMC media centre via "ADD-ONS".
# Use this excellent link to setup an ssh key for rsync to login automagicly.  
# http://www.thegeekstuff.com/2011/07/rsync-over-ssh-without-password/
# Put this script in your "nautilus-scripts" directory select file/s to
# transfer then right click and select this script from the Scripts menu.
# Don't forget "chmod u+x /home/<user>/.gnome2/nautilus-scripts/ssh-transfer"
# to make it executable.

# Path to the "rsync" utility on Openelec.
RSYNC="/storage/.xbmc/addons/network.backup.rsync/bin/rsync"
IPADD="192.168.1.67"                    # IP address of your Openelec box.
OELEC="/media/USBMEDIA/"                # Destination directory on XBMC.

# Create newline delimited selected files list, handling spaces in file names.
FILES=$(echo -e "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" |\
    awk 'BEGIN { FS = "\n" } { printf "\"%s\" ", $1 }' | sed -e s#\"\"##)

# Select destination for file transfer.
LOCTN=$(zenity\
    --title "SSH File Transfer"\
    --height=230\
    --text "Transfer Files To XBMC Media Centre."\
    --list --radiolist\
    --column "Select" --column "Send Files To..."\
    TRUE New FALSE TV FALSE Movies FALSE Music FALSE Concerts)
if [ "$?" = 1 ]; then exit $?; fi       # Cancel/close? then exit script.

# File count, how many files.
IFS=$(echo -en "\n\b")                  # Loop handles names with spaces now.
for N in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS; do ((NOFLS+=1)); done

# Open a terminal to run rsync and view file transfer progress.
gnome-terminal --geometry 70x30+48+0 --title="SSH File Transfer" -x bash -c\
    "echo 'Sending $NOFLS files to $OELEC$LOCTN'; echo; tput civis;\
    rsync -avP --rsync-path=$RSYNC -e ssh $FILES root@$IPADD:$OELEC$LOCTN;\
    tput bold; tput setaf 3; echo;\
    echo -e 'Done, hit a key to exit this shell, auto exit in 30s...';\
    read -n1 -t30"

# Update XBMC ibrary.
ssh -l root $IPADD 'xbmc-send --action="XBMC.updatelibrary(video)"' && \
ssh -l root $IPADD 'xbmc-send --action="XBMC.updatelibrary(music)"'


No comments: