#!/usr/bin/ksh typeset -i Choice typeset -L10 Device typeset -L256 Filespec typeset -L256 Parent typeset -L256 Target typeset -L1 Option typeset -L40 Line function device_func { Device="" while [[ -z "${Device%% *}" ]] do ls /dev/rmt* |mselect -geometry 300x300 -title "Tape Manager" \ -listlabel "Tape Devices"| read Device done } function tape_check_func { mmessage -title "Tape Manager" -text "Please put tape in ${Device%% *} and set on-line." || return 1 while mt -f ${Device} status|grep -s OFFLINE do sleep 10 done } function write_file_func { mfileselect -title "Tape Manager" | read Filespec [[ -z "${Filespec%% *}" ]] && return if [[ ! -f "${Filespec%% *}" ]] then mmessage -title "Tape Manager" -text "File: ${Filespec%% *} does not exist." return fi mmenu -title "Tape Manager" "Add to existing files" "Create New Archive" \ "Cancel" | read Choice case ${Choice} in 1) Option=r;; 2) Option=c myesno -title "Tape Manager" -text "Are you sure you wish to erase previous files on tape?" || return;; 3) return;; esac Parent=${Filespec%/*} if [[ ! -d "${Parent%% *}" ]] then mmessage -title "Tape Manager" -text "Cannot cd to: ${Parent%% *} does not exist" return fi cd ${Parent%% *} Target=${Filespec##*/} tape_check_func || return tar ${Option}f ${Device} ${Target%% *} >/dev/null mmessage -title "Tape Manager" -text "Tape operation complete." } function write_directory_func { mfileselect -title "Tape Manager"|read Filespec [[ -z "${Filespec%% *}" ]] && return [[ -z "${Filespec%%/*/ *}" ]] && Filespec=${Filespec%/ *} if [[ ! -d "${Filespec%% *}" ]] then mmessage -title "Tape Manager" -text "Directory: ${Filespec%% *} does not exist" return fi Target=${Filespec##*/} mmenu -title "Tape Manager" "Add To Existing Files" "Create New Archive" \ "Cancel" | read Choice case ${Choice} in 1) Option=r;; 2) Option=c myesno -title "Tape Manager" -text "Are you sure you wish to erase previous files on tape?" || return;; 3) return;; esac Parent=${Filespec%/*} if [[ ! -d "${Parent%% *}" ]] then mmessage -title "Tape Manager" -text "Cannot cd to: ${Parent%% *} does not exist" return fi cd "${Parent%% *}" tape_check_func || return tar ${Option}f ${Device} ${Target%% *} >/dev/null mmessage -title "Tape Manager" -text "Tape operation complete." } function read_file_func { mmessage -title "Tape Manager" -text "In the following box, select the directory where you wish to restore the tape files." || return mfileselect -title "Tape Manager"|read Filespec [[ -z "${Filespec%% *}" ]] && return [[ -z "${Filespec%%/*/ *}" ]] && Filespec=${Filespec%/ *} if [[ ! -d "${Filespec%% *}" ]] then mmessage -title "Tape Manager" \ -text "Directory: ${Filespec%% *} does not exist" return fi Parent=${Filespec%% *} if [[ ! -d "${Parent%% *}" ]] then mmessage -title "Tape Manager" -text "Cannot cd to: ${Parent%% *} does not exist" return fi cd ${Parent%% *} tape_check_func || return mmessage -title "Tape Manager" -text "From the following box, select a file or directory which you wish to retrieve from tape." || return mt -f ${Device} rewind tar tf ${Device} | mselect -geometry 300x300 -title "Tape Manager" | read Target myesno -title "Tape Manager" -text "Are you sure that you wish to get ${Target%% *} from tape and place it in ${Parent%% *}?" || return tar xf ${Device%% *} ${Target%% *} >/dev/null mmessage -title "Tape Manager" -text "Tape operation complete." } function read_tape_func { mmessage -title "Tape Manager" -text "In the following box, select the directory where you wish to restore the tape files." || return mfileselect -title "Tape Manager"|read Filespec [[ -z "${Filespec%% *}" ]] && return [[ -z "${Filespec%%/*/ *}" ]] && Filespec=${Filespec%/ *} if [[ ! -d "${Filespec%% *}" ]] then mmessage -title "Tape Manager" \ -text "Directory: ${Filespec%% *} does not exist" return fi Parent=${Filespec%% *} cd ${Parent%% *} myesno -title "Tape Manager" -text "Are you sure that you wish to retrieve the entire contents of the tape and place it in ${Parent%% *}?" || return tar xf ${Device%% *} >/dev/null mmessage -title "Tape Manager" -text "Tape operation complete." } function menu_func { mmenu -title "Tape Manager" "Reset Tape Device" "Write A File To Tape" \ "Write A Directory To Tape" "Read Tape Table of Contents" \ "Read One File/Directory From Tape" "Read Entire Tape" "Exit Tape Manager" | read Choice case ${Choice} in 1) device_func return;; 2) write_file_func return;; 3) write_directory_func return;; 4) tape_check_func || return tar tf ${Device} | mlist -geometry 300x300 -title "Tape Manager" ;; 5) read_file_func return;; 6) read_tape_func return;; 7) exit;; esac } ls /dev/rmt* | read Line if [[ "${Line}" = "/dev/rmt*: No such file or directory" ]] then mmessage -title "Tape Manager" -text "Exiting for lack of tape device /dev/rmt*." exit 1 fi device_func while : do menu_func done