Use basename when checking the script name
[ext/instance-debootstrap.git] / common.sh
index 62cea59..7759730 100644 (file)
--- a/common.sh
+++ b/common.sh
@@ -1,4 +1,17 @@
 
+SCRIPT_NAME=$(basename $0)
+
+for dir in /lib/udev /sbin; do
+  if [ -f $dir/vol_id -a -x $dir/vol_id ]; then
+    VOL_ID=$dir/vol_id
+  fi
+done
+
+if [ -z "$VOL_ID" ]; then
+    echo "vol_id not found, please install udev"
+    exit 1
+fi
+
 get_api5_arguments() {
   TEMP=`getopt -o o:n:i:b:s: -n '$0' -- "$@"`
   if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
@@ -23,31 +36,31 @@ get_api5_arguments() {
     echo "Missing OS API Argument"
     exit 1
   fi
-  if [ "$0" != "export" -a -z "$swapdev"  ]; then
+  if [ "$SCRIPT_NAME" != "export" -a -z "$swapdev"  ]; then
     echo "Missing OS API Argument"
     exit 1
   fi
-  if [ "$0" = "rename" -a -z "$new_name"  ]; then
+  if [ "$SCRIPT_NAME" = "rename" -a -z "$new_name"  ]; then
     echo "Missing OS API Argument"
     exit 1
   fi
 }
 
 get_api10_arguments() {
-  if [ -z "$INSTANCE" -o -z "$HYPERVISOR" -o -z "$DISK_COUNT" ]; then
+  if [ -z "$INSTANCE_NAME" -o -z "$HYPERVISOR" -o -z "$DISK_COUNT" ]; then
     echo "Missing OS API Variable"
     exit 1
   fi
-  instance=$INSTANCE
+  instance=$INSTANCE_NAME
   if [ $DISK_COUNT -lt 1 -o -z "$DISK_0_PATH" ]; then
     echo "At least one disk is needed"
     exit 1
   fi
   blockdev=$DISK_0_PATH
-  if [ "$0" = "rename" -a -z "$NEW_INSTANCE_NAME" ]; then
+  if [ "$SCRIPT_NAME" = "rename" -a -z "$OLD_INSTANCE_NAME" ]; then
     echo "Missing OS API Variable"
   fi
-  new_name=$NEW_INSTANCE_NAME
+  old_name=$OLD_INSTANCE_NAME
 }
 
 if [ -z "$OS_API_VERSION" -o "$OS_API_VERSION" = "5" ]; then
@@ -55,7 +68,7 @@ if [ -z "$OS_API_VERSION" -o "$OS_API_VERSION" = "5" ]; then
   get_api5_arguments
 elif [ "$OS_API_VERSION" = "10" ]; then
   get_api10_arguments
-  if [ $0 = "import" -o $0 = "export" ]; then
+  if [ $SCRIPT_NAME = "import" -o $SCRIPT_NAME = "export" ]; then
     echo "import/export still not compatible with API version 10"
     exit 1
   fi