3 # read an id off the tape and display it to the user
5 # This file is part of chiark backup, a system for backing up GNU/Linux and
6 # other UN*X-compatible machines, as used on chiark.greenend.org.uk.
9 # Copyright (C) 1997-1998,2000-2001 Ian Jackson <ian@chiark.greenend.org.uk>
10 # Copyright (C) 1999 Peter Maydell <pmaydell@chiark.greenend.org.uk>
12 # This is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2, or (at your option) any later version.
16 # This is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 # You should have received a copy of the GNU General Public License along
22 # with this program; if not, write to the Free Software Foundation, Inc.,
23 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 # First rough hack; mostly just code nabbed from full.
26 # --list assumes the dump type was 'zafio', which is a bit bogus.
28 # whatsthis : no args => just print tapeid
29 # whatsthis --list [n] : print tapeid then list archive n (if n omitted,
30 # 0 is assumed.) Note that archives are numbered from zero!
35 $etc='/etc/chiark-backup';
36 require "$etc/settings.pl";
37 require 'backuplib.pl';
41 # This isn't intended to be run automatically, so don't bother
42 # with setting status.
44 # If we are run with the argument --list then list the backup to
45 # stdout. Otherwise just print the tape ID.
46 $listing = 0; # default : don't list
47 $listing = 1 if ($ARGV[0] eq '--list');
49 $listarchive = $ARGV[1] if defined $ARGV[1];
51 print "Trying to read tape ID from currently inserted tape...\n";
54 system "mt -f $ntape setblk $blocksizebytes"; $? and die $?;
55 system "dd if=$ntape bs=${blocksize}b count=10 | tar -b$blocksize -vvxf - TAPEID";
56 $? and stopandsay "Failed to read TAPEID.\n";
58 if (!open(T, "TAPEID"))
60 stopandsay "Tape has no ID label.\n";
63 # OK, there's a TAPEID file, read the ID and check for sanity.
65 if ($tapeid =~ m/[^0-9a-zA-Z]/)
67 stopandsay "Tape has a bad (non-alphanumeric) TAPEID ($&).\n";
69 elsif (! $tapeid =~ m/[0-9a-zA-Z]/)
71 stopandsay "Empty TAPEID.\n";
74 print "TAPEID is $tapeid.\n";
77 # If we aren't listing the tape contents, we can just rewind the tape
85 # List the contents of archive $listarchive on the tape.
86 # We are already at the right place for the first archive
88 # For any other archive, we skip forwards to the start of that archive.
91 system "mt -f $ntape fsf $listarchive";
92 $? and stopandsay "Couldn't skip forward to archive $listarchive.";
95 # Use file to figure out what the archive type is
96 # This doesn't seem to work too well, so I'm disabling it -- PMM
97 #$ftype = `dd if=$ntape ibs=$blocksizebytes | file -`;
98 #$? and stopandsay "couldn't determine file type: $?";
101 # What we want to do here is roughly:
102 # dd if=$ntape ibs=$blocksizebytes | readbuffer | afio ???
104 # where the afio options are such as to list an archive created with
105 # afio -b $softblocksizebytes -Zvo
107 if ($ftype =~ /POSIX tar/) {
108 # POSIX tar archive; we read it with cpio
109 $reader = "cpio -it -C$softblocksizebytes -Hustar";
110 } elsif ($ftype =~ /ASCII cpio/) {
111 $reader = "afio -b $softblocksizebytes -Zt -";
112 } elsif ($ftype =~ /dump file/) {
113 stopandsay "sorry: can't list dump files yet";
115 stopandsay "listing failed: unknown archive type";
118 # Now back up so we can read the file again properly
119 #system "mt -f $ntape bsf 1"; $? and stopandsay "couldn't backspace tape: $?";
121 system "dd if=$ntape ibs=$blocksizebytes | readbuffer | $reader";
122 $? and stopandsay "listing failed: $?";
124 # All's well, stop here.
125 print "Listing complete.\n";
133 system "mt -f $tape rewind"; $? and die $?;
136 # Print the given message, rewind the tape and exit failure.