Imported Upstream version 2.4.4p3
[debian/amanda] / contrib / mkamandisk
1 #!/bin/bash
2
3 # This script prepares an IOmega disk for use with amanda.
4 # More precisely, it
5 # - formats the disk, checking for bad sectors
6 # - mounts the disk and adds a data subdirectory
7 # - makes user amanda owner of this data sub directory
8 # - calls amlabel to label the disk
9 # - unmounts and ejects the disk.
10
11 # This shell script is not generally usable as is, 
12 # because it is relying on a couple of settings of personal taste, such as
13 # - IOmega disks are partitioned and the fourth primary partition 
14 #   is taking the whole disk. So the disk is visible as /dev/sda4.
15 # - I am preferring to use an ext2 filesystem on the disk 
16 #   (rather then a dos or vfat file system)
17 # - I am doing a chown of the data sub directory such that - depending 
18 #   on the umask setting - only user amanda and root can see 
19 #   the files written to the disk.
20
21 # It has to be called as root
22
23 if [ "$#" -lt "2" ]
24         then
25         echo "Usage : $0 <backup set> <disk label>"
26         exit 1
27 fi
28
29 backup="$1"
30 label="$2"
31
32 echo "insert tape $2 into slot and press return" 
33 read ANSWER
34
35 mkfs.ext2 -c -L $label /dev/iomega
36
37 echo "mounting disk ..."
38 mount /dev/iomega
39 if [ ! -d /mnt/iomega/lost+found ]
40         then
41         echo "mount did not work properly - please investigate"
42         exit 1
43 fi
44
45 echo "adding data subdirectory ..."
46 cd /mnt/iomega
47 mkdir data
48 chown -R amanda:disk .
49 if [ -n "$label" ]
50         then
51         echo "attempting to write amanda disk label"
52         su - amanda -c "/usr/sbin/amlabel $backup $label"
53 fi
54
55 echo "preparing to eject disk ..."
56 cd >/dev/null 2>&1
57 eject /mnt/iomega
58
59 echo "please don't forget to label with $backup $label"