]> git.pld-linux.org Git - packages/amanda.git/blob - convert-zd-mtx-to-robot.sh
perl 5.38.0 rebuild
[packages/amanda.git] / convert-zd-mtx-to-robot.sh
1 #! /bin/sh
2
3 if test $# -ne 1; then
4     echo "USAGE: $0 <CONFIG>"
5     exit 1
6 fi
7
8 CONFIG=$1
9 CFGDIR=`amgetconf build.CONFIG_DIR`
10 if test -z "$CFGDIR"; then
11     echo "could not get CONFIG_DIR - is Amanda set up correctly?"
12     exit 1;
13 fi
14
15 # cd into config dir so relative paths work
16 cd "$CFGDIR/$CONFIG"
17
18 ##
19 # get the configuration (this is copied directly from chg-zd-mtx)
20
21 die() {
22     echo "$*"
23     exit 1
24 }
25
26 changerfile=`amgetconf $CONFIG changerfile 2>/dev/null`
27 if [ -z "$changerfile" ]; then
28      die "changerfile must be specified in amanda.conf"
29 fi
30 conf_match=`expr "$changerfile" : .\*\.conf\$`
31 if [ $conf_match -ge 6 ]; then
32         configfile=$changerfile
33         changerfile=`echo $changerfile | sed 's/.conf$//g'`
34 else
35         configfile=$changerfile.conf
36 fi
37 if [ ! -e $configfile ]; then
38     die "configuration file \"$configfile\" doesn't exist"
39 fi
40 if [ ! -f $configfile ]; then
41     die "configuration file \"$configfile\" is not a file"
42 fi
43 cleanfile=$changerfile-clean
44 accessfile=$changerfile-access
45 slotfile=$changerfile-slot
46 labelfile=$changerfile-barcodes
47
48 varlist=
49 varlist="$varlist firstslot"
50 varlist="$varlist lastslot"
51 varlist="$varlist cleanslot"
52 varlist="$varlist cleancycle"
53 varlist="$varlist OFFLINE_BEFORE_UNLOAD"        # old name
54 varlist="$varlist offline_before_unload"
55 varlist="$varlist unloadpause"
56 varlist="$varlist AUTOCLEAN"                    # old name
57 varlist="$varlist autoclean"
58 varlist="$varlist autocleancount"
59 varlist="$varlist havereader"
60 varlist="$varlist driveslot"
61 varlist="$varlist poll_drive_ready"
62 varlist="$varlist initial_poll_delay"
63 varlist="$varlist max_drive_wait"
64 varlist="$varlist slotinfofile"
65
66 for var in $varlist
67 do
68         val="`cat $configfile 2>/dev/null | sed -n '
69 # Ignore comment lines (anything starting with a #).
70 /^[     ]*#/d
71 # Find the first var=val line in the file, print the value and quit.
72 /^[     ]*'$var'[       ]*=[    ]*\([^  ][^     ]*\).*/ {
73         s/^[    ]*'$var'[       ]*=[    ]*\([^  ][^     ]*\).*/\1/p
74         q
75 }
76 '`"
77         eval $var=\"$val\"
78 done
79
80 firstslot=${firstslot:-'-1'}                            # default: mtx status
81 lastslot=${lastslot:-'-1'}                              # default: mtx status
82 driveslot=${driveslot:-'0'}                             # default: 0
83 cleanslot=${cleanslot:-'-1'}                            # default: -1
84 cleancycle=${cleancycle:-'120'}                         # default: two minutes
85 if [ -z "$offline_before_unload" -a -n "$OFFLINE_BEFORE_UNLOAD" ]; then
86         offline_before_unload=$OFFLINE_BEFORE_UNLOAD    # (old name)
87 fi
88 offline_before_unload=${offline_before_unload:-'0'}     # default: 0
89 unloadpause=${unloadpause:-'0'}                         # default: 0
90 if [ -z "$autoclean" -a -n "$AUTOCLEAN" ]; then
91         autoclean=$AUTOCLEAN                            # (old name)
92 fi
93 autoclean=${autoclean:-'0'}                             # default: 0
94 autocleancount=${autocleancount:-'99'}                  # default: 99
95 havereader=${havereader:-'0'}                           # default: 0
96 poll_drive_ready=${poll_drive_ready:-'3'}               # default: three seconds
97 initial_poll_delay=${initial_poll_delay:-'0'}           # default: zero zeconds
98 max_drive_wait=${max_drive_wait:-'120'}                 # default: two minutes
99
100 tapedev=`amgetconf $CONFIG tapedev 2>/dev/null`
101 if [ -z "$tapedev" ]; then
102     die "tapedev may not be empty"
103 fi
104
105 changerdev=`amgetconf $CONFIG changerdev 2>/dev/null`
106 if [ -z "$changerdev" ]; then
107     die "changerdev may not be empty"
108 elif [ $changerdev = "/dev/null" ]; then
109     die "changerdev ($changerdev) may not be the null device"
110 fi
111
112 ####
113 # Create the chg-robot config
114
115 # note that cleaning is not supported by chg-robot, so the cleaning parameters are
116 # not converted.
117
118 showbool() {
119     if test "$1" -ne 0; then
120         echo 'yes'
121     else
122         echo 'no'
123     fi
124 }
125
126 echo "Remove the following parameters, if present, from your amanda.conf:"
127 echo "   tpchanger changerfile changerdev tapedev"
128 echo ""
129 echo "Add the following to amanda.conf (you may want to use a more descriptive name for the changer):"
130 echo ""
131 echo "tapedev \"converted-from-chg-zd-mtx\""
132 echo "define changer \"converted-from-chg-zd-mtx\" {"
133 echo "  tpchanger \"chg-robot:$changerdev\""
134 echo "  changerfile \"$changerfile-state\""
135 echo "  property \"tape-device\" \"$driveslot=$tapedev\""
136 echo "  property \"eject-before-unload\" \""`showbool $offline_before_unload`"\""
137 if test $firstslot -ge 0 && test $lastslot -ge 0; then
138     echo "  property \"use-slots\" \"$firstslot-$lastslot\""
139 elif test $firstslot -ge 0 || test $lastslot -ge 0; then
140     echo "  # you may want to set the USE-SLOTS property appropriately"
141 fi
142 if test "${unloadpause:-0}" -gt 0; then
143     echo "  property \"eject-delay\" \"$unloadpause s\""
144 fi
145 if test $havereader -eq 0; then
146     echo "  property \"fast-search\" \"no\""
147     echo "  property \"ignore-barcodes\" \"yes\""
148 fi
149 echo "  property \"load-poll\" \"$initial_poll_delay s poll $poll_drive_ready s until $max_drive_wait s\""
150 echo "}"
151 echo ""
152
153 ####
154 # and offer suggestions for loading metadata, if slotinfofile is set
155
156 if test -z "$slotinfofile"; then
157     echo "Once this configuration is in place, run"
158     echo "  amtape $CONFIG update"
159     echo "to update the changer's tape database.  For a large changer, this may take some time."
160 else
161     echo "Run the following commands to initialize the changer's tape database."
162     cat "$slotinfofile" | while read slot label; do
163         echo "  amtape $CONFIG update \"$slot=$label\""
164     done
165 fi
This page took 0.112177 seconds and 3 git commands to generate.