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.

Own Media


#!/bin/bash
# Filename: own-media
# Version: 090813
# Author: robz
# The purpose of this script is to automate the transfer of TV media files
# from another user account to my standard working account.
# Source and destination directories will need changing to suit.
# You can use this as a Nautilus script or via a launcher. You will need the
# excellent "tvnamer" utility available from the Ubuntu Software Centre.

# Ask for password to obtain administrator privileges.
if [ "$UID" != "0" ]; then
    sudo -k; exec gksudo --message "$(echo\
    'Enter your password please, you need root';\
    echo 'privilages to access another user account.')"\
    "$0"
fi

USE="robz1"                              # This scripts destination user name.
BAK="$IFS"                               # Backup internal field separator.
IFS="\n"                                 # Set internal field separator.
DES="/home/robz1/Torrents/Complete/"     # Save directory minus one level.
ARC="/media/Backup/TV"                   # Backup achive location.

trap 'IFS="$BAK"; exit' INT TERM EXIT    # Restore IFS on exit.

# Select files to be copied.
FIL=$(zenity --file-selection --multiple --separator=$'\n'\
    --filename="/home/transmission/Downloads/Torrents/Complete/"\
    --title="Own-Media - >>SELECT FILE OR FILES<<")
if [ "$?" = 1 ]; then exit $?; fi        # Kill script on cancel.

# File destination, this appends to the "$DES" initial destination variable.
STO=$(zenity --title="Own-Media" --text="Select Destination" --height=170\
    --list --radiolist --column "Select" --column "Send Files To..."\
    TRUE "NewTV" FALSE "Somewhere else") # Change "NewTV" to whatever you want.
if [ "$?" = 1 ]; then exit $?; fi

SAV="$DES""$STO""/"                      # Set initial destination.

# Select alternative file destination, ignore "$DES" and go somewhere else.
if [ "$STO" = "Somewhere else" ]; then
    SAV=$(zenity --file-selection --directory --filename="/home/robz1/"\
    --title="Own-Media - >>SELECT DESTINATION<<")
    if [ "$?" = 1 ]; then exit $?; fi
    SAV="$SAV""/"                        # Reset destination, maybe.
fi

# Copy files to destination.
while read N; do cp -u "$N" "$SAV"; done <<< "$FIL"

# Take possession of files as destination user, change owner.
while read N; do chown "$USE":"$USE" "$SAV""$(basename "$N")"; done <<< "$FIL"

sudo -k                                  # Drop superuser privileges.

# Rename to standard format i.e. [ Show Name - [01x01] - Episode Name ].
zenity --question --title= --text="Do you wish to rename &amp; achive."
if [ "$?" = 1 ]; then exit $?
else
    while read N; do tvnamer --batch "$SAV""$(basename "$N")"; done <<< "$FIL"
fi

cp -aur "$SAV""." "$ARC"                 # Copy new files to a backup achive.



No comments: