488e0b49d4b280e6e7b274852238e88936a6b267
[ext/instance-debootstrap.git] / common.sh
1
2 for dir in /lib/udev /sbin; do
3   if [ -f $dir/vol_id -a -x $dir/vol_id ]; then
4     VOL_ID=$dir/vol_id
5   fi
6 done
7
8 if [ -z "$VOL_ID" ]; then
9     echo "vol_id not found, please install udev"
10     exit 1
11 fi
12
13 get_api5_arguments() {
14   TEMP=`getopt -o o:n:i:b:s: -n '$0' -- "$@"`
15   if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
16   # Note the quotes around `$TEMP': they are essential!
17   eval set -- "$TEMP"
18   while true; do
19     case "$1" in
20       -i|-n) instance=$2; shift 2;;
21
22       -o) old_name=$2; shift 2;;
23
24       -b) blockdev=$2; shift 2;;
25
26       -s) swapdev=$2; shift 2;;
27
28       --) shift; break;;
29
30       *)  echo "Internal error!"; exit 1;;
31     esac
32   done
33   if [ -z "$instance" -o -z "$blockdev" ]; then
34     echo "Missing OS API Argument"
35     exit 1
36   fi
37   if [ "$0" != "export" -a -z "$swapdev"  ]; then
38     echo "Missing OS API Argument"
39     exit 1
40   fi
41   if [ "$0" = "rename" -a -z "$new_name"  ]; then
42     echo "Missing OS API Argument"
43     exit 1
44   fi
45 }
46
47 get_api10_arguments() {
48   if [ -z "$INSTANCE_NAME" -o -z "$HYPERVISOR" -o -z "$DISK_COUNT" ]; then
49     echo "Missing OS API Variable"
50     exit 1
51   fi
52   instance=$INSTANCE_NAME
53   if [ $DISK_COUNT -lt 1 -o -z "$DISK_0_PATH" ]; then
54     echo "At least one disk is needed"
55     exit 1
56   fi
57   blockdev=$DISK_0_PATH
58   if [ "$0" = "rename" -a -z "$OLD_INSTANCE_NAME" ]; then
59     echo "Missing OS API Variable"
60   fi
61   old_name=$OLD_INSTANCE_NAME
62 }
63
64 if [ -z "$OS_API_VERSION" -o "$OS_API_VERSION" = "5" ]; then
65   OS_API_VERSION=5
66   get_api5_arguments
67 elif [ "$OS_API_VERSION" = "10" ]; then
68   get_api10_arguments
69   if [ $0 = "import" -o $0 = "export" ]; then
70     echo "import/export still not compatible with API version 10"
71     exit 1
72   fi
73 else
74   echo "Unknown OS API VERSION $OS_API_VERSION"
75   exit 1
76 fi