File: cartis

package info (click to toggle)
afbackup 3.1beta1-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,500 kB
  • ctags: 1,685
  • sloc: ansic: 22,406; csh: 3,597; tcl: 964; sh: 403; makefile: 200
file content (146 lines) | stat: -rwxr-xr-x 3,196 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#! /bin/csh -f

set cmd=`basename $0`

set mandargs='(-i *[1-9][0-9]* +[1-9][0-9]* *)'
set optargs='(-S *[1-9][0-9]* *)*'

if (`echo $*|egrep '(^((('"$optargs"'*)('"$mandargs"')('"$optargs"'*))|([1-9][0-9]*))$)'|wc -l` < 1) then
  echo "usage: $cmd "'<cartridge-number>'
  echo "       $cmd "'[ -S <cartridge-set-number> ] \'
  echo "              "'-i <cartridge-number> <file-number>'
  exit 1
endif

set cartset=1

if ($#argv > 1) then
  set i=1
  while ($i <= $#argv)
    if ("_$argv[$i]" == "_-i") then
      @ i++
      set cartno=$argv[$i]
      @ i++
      set fileno=$argv[$i]
    endif
    if ("_$argv[$i]" == "_-S") then
      @ i++
      set cartset=$argv[$i]
    endif
    @ i++
  end
endif

if (! $?BACKUP_HOME) then
  set pnam=$0
  set pnam = $pnam:t
  if ($pnam == $0 || ./$pnam == $0) then
    foreach dir ($path)
      set p=$dir/$pnam
      if (-x $p) then
	break;
      endif
    end
    if ($p == ./$pnam) then
      set p=`pwd`
      setenv BACKUP_HOME  $p:h
    else
      set p=$p:h
      setenv BACKUP_HOME  $p:h
    endif
  else
    if (`echo $0|cut -c1` != "/") then
      set p=`pwd`/$0
    else
      set p=$0
    endif
    set p=$p:h
    setenv BACKUP_HOME $p:h
  endif
  set bindir="$p"
else
  set bindir=$BACKUP_HOME/bin
endif

set configfile=(`grep "$bindir/[^/]*server" /etc/inetd.conf|awk 'NR==1 {print $NF}'`)
if ($configfile == "") then
  echo Cannot find configuration file, assuming $BACKUP_HOME/lib/backup.conf
  set configfile=$BACKUP_HOME/lib/backup.conf
endif

# the solaris awk is doin' dawn f...... BS
foreach awk (nawk gawk awk)
  foreach dir ($path)
    if (-x $dir/$awk) then
      setenv AWK $dir/$awk
      break
    endif
  end
  if ($?AWK) break
end

if (! $?AWK) then
  echo 'No awk ? Is this really one of the wonderful UNIX-es ?'
  echo 'Sorry. I have to exit.'
  exit 1
endif

alias getparam $AWK' '"'"'/^[ 	]*'"'"'\!:1'"'"'/{split($0,a,"'"'"'\!:1'"'"'[ 	]*"); print a[2]}'"' $configfile"

set tapeposfile=`getparam '^[ 	]*[Tt]ape[-_ 	]*[Pp]osi?t?i?o?n?[-_ 	]*[Ff]ile:?'`
if ($tapeposfile == "") then
  echo Cannot find tape-positioning file.
  exit 1
endif

set lastcarts=(`getparam '^[ 	]*[Ll]ast[-_ 	]*[Cc]artr?i?d?g?e?s[-_ 	]*:?'`)
set num_cartsets=$#lastcarts
if ($num_cartsets < 1) then
  set num_cartsets=1
endif

if (-r $tapeposfile) then
  set nums=(`cat $tapeposfile`)
else
  if ($#argv == 1) then
    set cartno=$1
  endif
  echo 'Warning: Assuming initial startup. Setting read- and write-position'
  echo '         to cartridge '$cartno', file 1.'
  echo '         Storing into file '$tapeposfile.

  set nums=($cartno 1 $cartno 1)
  set fileno=1
endif

@ cartsets=$#nums / 2 - 1
while ($cartsets < $num_cartsets)
  set nums=($nums 0 0)
  @ cartsets=$#nums / 2 - 1
end

if ($#nums < 4) then
  echo Tape positioning file has invalid format.
  exit 1
endif

if ($#argv == 1) then
  set nums[1]="$1"
else
  @ idx1=2 * $cartset + 1
  @ idx2=$idx1 + 1

  if ($idx1 > $#nums) then
    echo Error: cartridge set number too high 'max: '$cartsets
    exit 1
  endif
  if ($idx1 < 1) then
    echo Error: Illegal cartridge number.
    exit 1
  endif

  set nums[$idx1]=$cartno
  set nums[$idx2]=$fileno
endif

echo $nums >! $tapeposfile