Mate Lakat | 57e3da9 | 2013-03-22 16:34:05 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | function xapi_plugin_location { |
| 4 | for PLUGIN_DIR in "/etc/xapi.d/plugins/" "/usr/lib/xcp/plugins/" |
| 5 | do |
| 6 | if [ -d $PLUGIN_DIR ] |
| 7 | then |
| 8 | echo $PLUGIN_DIR |
| 9 | return 0 |
| 10 | fi |
| 11 | done |
| 12 | return 1 |
| 13 | } |
| 14 | |
| 15 | function zip_snapshot_location { |
| 16 | echo $1 | sed "s:\.git$::;s:$:/zipball/$2:g" |
| 17 | } |
| 18 | |
| 19 | function create_directory_for_kernels { |
| 20 | mkdir -p "/boot/guest" |
| 21 | } |
| 22 | |
| 23 | function extract_remote_zipball { |
| 24 | local ZIPBALL_URL=$1 |
| 25 | |
| 26 | local LOCAL_ZIPBALL=$(mktemp) |
| 27 | local EXTRACTED_FILES=$(mktemp -d) |
| 28 | |
| 29 | ( |
| 30 | wget -nv $ZIPBALL_URL -O $LOCAL_ZIPBALL --no-check-certificate |
| 31 | unzip -q -o $LOCAL_ZIPBALL -d $EXTRACTED_FILES |
| 32 | rm -f $LOCAL_ZIPBALL |
| 33 | ) >&2 |
| 34 | |
| 35 | echo "$EXTRACTED_FILES" |
| 36 | } |
| 37 | |
| 38 | function find_xapi_plugins_dir { |
| 39 | find $1 -path '*/xapi.d/plugins' -type d -print |
| 40 | } |
| 41 | |
| 42 | function install_xapi_plugins_from_zipball { |
| 43 | local XAPI_PLUGIN_DIR |
| 44 | local EXTRACTED_FILES |
| 45 | local EXTRACTED_PLUGINS_DIR |
| 46 | |
| 47 | XAPI_PLUGIN_DIR=$(xapi_plugin_location) |
| 48 | |
| 49 | EXTRACTED_FILES=$(extract_remote_zipball $1) |
| 50 | EXTRACTED_PLUGINS_DIR=$(find_xapi_plugins_dir $EXTRACTED_FILES) |
| 51 | |
| 52 | cp -pr $EXTRACTED_PLUGINS_DIR/* $XAPI_PLUGIN_DIR |
| 53 | rm -rf $EXTRACTED_FILES |
| 54 | chmod a+x ${XAPI_PLUGIN_DIR}* |
| 55 | } |