2
##########################################################################
4
## attbckshare is automatically generated, ##
5
## please do not modify! ##
7
##########################################################################
9
##########################################################################
11
## Script ID: attbckshare ##
12
## Author: Mark Grant ##
15
## To mount a CIFS or NFS backup share. E.g. ##
16
## \\Ambrosia\charybdisbck or hermes:/srv/backups/charybdis ##
18
## /mnt/charybdisbck ##
20
## Syntax: attbckshare [ -a --adhoc || -h --help || -v --verbose ##
21
## || -V --version || -w --weekly ] ##
23
## Exit Codes: 0 & 64 - 113 as per C/C++ standard ##
25
## 64 - Invalid arguments ##
26
## 65 - Failed mounting backup share ##
27
## 66 - Backup share already mounted ##
28
## 67 - trap received ##
31
## This script mounts a CIFS or NFS share as a target for the backup ##
34
## In order to make the package portable all the necessary parameters ##
35
## are stored in a $PREFIX/etc/lixbackups/backups.conf file. ##
36
## For further information please consult the backups.conf man page. ##
38
##########################################################################
40
##########################################################################
44
## Date Author Version Description ##
46
## 09/04/2010 MG 1.0.1 Created for Linux. ##
47
## 26/08/2010 MG 1.0.2 Major revision completed supporting ##
48
## FreeBSD as well as Linux. Also put all ##
49
## relevant parameters in variables at ##
50
## beginning of script to enhance ##
51
## portability. (e.g. System, backup user ##
53
## 18/11/2010 MG 1.0.3 Changed to emit help and version on ##
54
## input of correct flag as argument. Also ##
55
## stored version in string in Init section##
56
## 28/11/2010 MG 1.0.4 Changed script to read parameters from ##
57
## etclocation/backups.conf and, when ##
58
## necessary (FreeBSD), the ~/.nsmbrc file.##
59
## 10/01/2012 MG 1.0.5 Removed the .sh extension from the ##
61
## 05/11/2012 MG 1.0.6 Reverted to the .sh file extension. ##
62
## 26/02/2013 MG 1.0.7 Changed command line option processing ##
64
## 01/04/2013 MG 1.0.8 Moved config files to new backups ##
65
## directory under sysconfdir. Added ##
66
## exclude files for system, weekly, daily ##
68
## 22/08/2013 MG 1.0.9 Debian best practice documentation ##
69
## requires that programs placed in the ##
70
## PATH should not have extensions as the ##
71
## programs may be rewritten in a ##
72
## different language. This would then ##
73
## require a name change, or, if left ##
74
## as-is would cause confusion. So name ##
75
## changed to remove .sh extension. ##
76
## 06/01/2014 MG 1.1.1 Changed stdout & stderr message output ##
77
## to use a function directing to one or ##
78
## other based on a status. Changed ##
79
## version option to -V. Added verbose ##
81
## 16/11/2014 MG 1.1.2 Switched from getopts to GNU getopt to ##
82
## allow long options. ##
83
## 17/11/2014 MG 1.1.3 Change FreeBSD specifics to *BSD and ##
84
## change Linux to be the default. ##
85
## 22/11/2014 MG 1.1.4 Add overall package version to -V. ##
86
## 02/02/2015 MG 1.1.5 Remove BSD support. ##
87
## 02/02/2015 MG 1.2.1 Add support for NFS shares. Add support ##
88
## for different weekly and ad hoc targets.##
89
## 24/02/2015 MG 1.2.2 Change configuration files directory to ##
90
## lixbackups to limit risk of conflict ##
91
## with other backup packages. ##
92
## 26/02/2015 MG 1.2.3 Use logger to write key messages to ##
95
##########################################################################
101
outputprefix="attbckshare: "
102
version="1.2.3" # set version variable
103
etclocation=@sysconfdir@/lixbackups # Path to etc directory
104
packageversion=@pkgversion@ # Version of the complete package
124
# Output $1 to stdout or stderr depending on $2 and write to syslog if required.
125
# Syntax = output $1 (The message) $2 (0 = stdout, > 0 = stderr) $3 (TRUE = syslog it).
130
if [ "$verbosity" = "-v" ]
132
echo "$outputprefix$1"
135
echo "$outputprefix$1" 1>&2
139
logger "$outputprefix$1"
140
std_cmd_err_handler $?
144
# Standard function to test command error ($1 is $?) and exit if non-zero
145
std_cmd_err_handler()
154
# Standard function to tidy up and return exit code
157
exit $script_exit_code
160
# Standard trap exit function
164
output "Script terminating due to trap received. Code: "$script_exit_code 1 TRUE
169
trap trap_exit SIGHUP SIGINT SIGTERM
174
# Process command line arguments with GNU getopt.
175
GETOPTTEMP=`getopt -o ahvVw --long adhoc,help,verbose,version,weekly -n "$0" -- "$@"`
176
std_cmd_err_handler $?
178
eval set -- "$GETOPTTEMP"
179
std_cmd_err_handler $?
185
if [ $weekly = TRUE ]
188
output "Options a and w are mutually exclusive." 1 FALSE
196
echo "Usage is $0 [options]"
197
echo " -a or --adhoc mount the ad hoc backup target share"
199
echo " -h or --help displays usage information"
201
echo " -v or --verbose verbose output"
203
echo " -V or --version displays version information"
205
echo " -w or --weekly mount the weekly target backup share"
215
echo "$0 Script version "$version
216
echo "$0 Package version "$packageversion
225
output "Options a and w are mutually exclusive." 1 FALSE
235
*) script_exit_code=1
236
output "Internal error." 1 FALSE
242
# Script does not accept other arguments.
246
output "Invalid argument." 1 FALSE
250
# One option has to be selected.
251
if [ $adhoc = FALSE -a $weekly = FALSE ]
254
output "Either a or w must be set." 1 FALSE
258
# Read parameters from $etclocation/backups.conf
261
exec 3<$etclocation/backups.conf
262
while read -u3 -ra input
266
weeklytype=${input[1]}
269
weeklytarget=${input[1]}
272
weeklycredfile=${input[1]}
275
weeklynotifyuser=${input[1]}
278
adhoctype=${input[1]}
281
adhoctarget=${input[1]}
284
adhoccredfile=${input[1]}
287
adhocnotifyuser=${input[1]}
300
credfile=$adhoccredfile
301
notifyuser=$adhocnotifyuser
306
credfile=$weeklycredfile
307
notifyuser=$weeklynotifyuser
314
mountCL=$mountCL"nfs $target $mntdir"
317
mountCL=$mountCL"cifs -o credentials=$credfile $target $mntdir"
319
*) script_exit_code=1
320
output "Invalid share type." 1 TRUE
325
# Check to see if the network backup share is mounted, if not, mount
326
if [ "$(chkbckshare -bt)" = "FALSE" ]
333
output "Failed to mount backup share. Mount error: "$status" Script exit code: "$script_exit_code 1 TRUE
338
output "Backup share already mounted. Script exit code: "$script_exit_code 1 TRUE
343
output "Share $target mounted on $mntdir" 0 TRUE