]> git.sur5r.net Git - bacula/rescue/blob - rescue/knoppix/cdrom/makecdimage
Add new knoppix directory
[bacula/rescue] / rescue / knoppix / cdrom / makecdimage
1 #! /bin/sh
2
3 # This script makes a copy of an existing boot cd or iso on
4 #   disk so that we can add the Bacula code to it for remastering
5 #
6 # When we are done if there is no error, we should have the
7 #   cdrom image in cdimage
8 #
9
10 export LANG=C
11
12 # Print Usage message
13 usage () {
14    cat <<END_OF_DATA
15 Usage: make_rescue_disk
16   -h, --help             print this message
17   --type=cdrom|iso       start with a cdrom or iso image
18   --where=path           the path to the device (mounted) or the iso
19 END_OF_DATA
20 }
21
22 if [ ! `whoami` = "root" ] ; then
23   echo ""
24   echo "You need to be root to run this, otherwise"
25   echo "I cannot mount the loopback. Continuing anyway ..."
26   echo ""
27 fi
28
29
30 #
31 # Process command line options
32 #
33 for option in "$@" ; do
34    case "$option" in
35    -h | --help)
36       usage
37       exit 0
38       ;;
39    --type=cdrom)
40       type=cdrom
41       ;;
42    --type=iso)
43       type=iso
44       ;;
45    --where*)
46       where=`echo "$option"|cut -c 9-`
47       ;;
48    *)
49       echo "Unknown option specified: $option"
50       usage
51       exit 1
52       ;;
53    esac
54 done
55
56 if [ x$type == x ] ; then
57    echo " "
58    echo "You can make the rescue disk either from a mounted CDROM or"
59    echo "from a .iso image. Please enter cdrom or iso:"
60    read type   
61    if [ $type == 'cdrom' ] ; then 
62       echo "OK want mounted CDROM"
63    elif [ $type == 'iso' ] ; then
64       echo "OK want iso image"
65    else
66       echo "Type missing"
67       exit 1
68    fi
69 fi
70 if [ x$where == x ] ; then
71    echo " "
72    echo "Enter location of image e.g. /mnt/cdrom or /home/src/.../rescue.iso"
73    read where
74 fi
75 if [ ! -e $where ]; then
76    echo "Cannot find rescue image $where"
77     exit 1
78 fi
79 if [ $type == iso ]; then
80   rm -rf mnt
81   mkdir mnt
82   mount -o loop $where mnt
83   if [ $? != 0 ] ; then
84     echo "Mount failed."
85     rm -rf mnt
86     exit 1;
87   fi
88   rm -rf cdimage
89   mkdir cdimage
90   cp -a mnt/* cdimage/
91   if [ $? != 0 ] ; then
92     echo "Copy from iso to cdimage failed"
93     unmount mnt
94     rm -rf mnt cdimage
95     exit 1;
96   fi
97   unmount mnt
98   rm -rf mnt
99 fi
100 if [ $type == cdrom ] ; then
101   rm -rf cdimage
102   mkdir cdimage
103   cp -a $where/* cdimage
104   if [ $? != 0 ] ; then
105     echo "Copy from cdrom to cdimage failed"
106     rm -rf cdimage
107     exit 1;
108   fi
109 fi
110 #