-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·120 lines (99 loc) · 2.83 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
#-------------------------------------------------------------------------------
# Install program for the PowerKVM hypervisor for OpenNebula.
# $ONE_LOCATION if defined with the -d option, otherwise it'll be installed
# under /. In this case you may specified the oneadmin user/group, so you do
# not need run the OpenNebula daemon with root privileges
#-------------------------------------------------------------------------------
ARGS=$*
usage() {
echo
echo "Usage: install.sh [-u install_user] [-g install_group]"
echo " [-d ONE_LOCATION] [-l] [-h]"
echo
echo "-d: target installation directory, if not defined it'd be root. Must be"
echo " an absolute path. Installation will be selfcontained"
echo "-l: creates symlinks instead of copying files, useful for development"
echo "-h: prints this help"
}
PARAMETERS="hlu:g:d:"
if [ $(getopt --version | tr -d " ") = "--" ]; then
TEMP_OPT=`getopt $PARAMETERS "$@"`
else
TEMP_OPT=`getopt -o $PARAMETERS -n 'install.sh' -- "$@"`
fi
if [ $? != 0 ] ; then
usage
exit 1
fi
eval set -- "$TEMP_OPT"
LINK="no"
ONEADMIN_USER=`id -u`
ONEADMIN_GROUP=`id -g`
SRC_DIR=$PWD
while true ; do
case "$1" in
-h) usage; exit 0;;
-d) ROOT="$2" ; shift 2 ;;
-l) LINK="yes" ; shift ;;
-u) ONEADMIN_USER="$2" ; shift 2;;
-g) ONEADMIN_GROUP="$2"; shift 2;;
--) shift ; break ;;
*) usage; exit 1 ;;
esac
done
export ROOT
if [ -z "$ROOT" ]; then
VAR_LOCATION="/var/lib/one"
REMOTES_LOCATION="$VAR_LOCATION/remotes"
ETC_LOCATION="/etc/one"
else
VAR_LOCATION="$ROOT/var"
REMOTES_LOCATION="$VAR_LOCATION/remotes"
ETC_LOCATION="$ROOT/etc"
fi
do_file() {
if [ "$UNINSTALL" = "yes" ]; then
rm $2/`basename $1`
else
if [ "$LINK" = "yes" ]; then
ln -fs $SRC_DIR/$1 $2
else
cp -R $SRC_DIR/$1 $2
if [[ "$ONEADMIN_USER" != "0" || "$ONEADMIN_GROUP" != "0" ]]; then
chown -R $ONEADMIN_USER:$ONEADMIN_GROUP $2
fi
fi
fi
}
copy_files() {
FILES=$1
DST=$DESTDIR$2
mkdir -p $DST
for f in $FILES; do
do_file src/$f $DST
done
}
create_dirs() {
DIRS=$*
for d in $DIRS; do
dir=$DESTDIR$d
mkdir -p $dir
done
}
change_ownership() {
DIRS=$*
for d in $DIRS; do
chown -R $ONEADMIN_USER:$ONEADMIN_GROUP $DESTDIR$d
done
}
cd `dirname $0`/src
copy_files "im/powerkvm.d/*" "$REMOTES_LOCATION/im/powerkvm.d"
copy_files "im/powerkvm-probes.d/*" "$REMOTES_LOCATION/im/powerkvm-probes.d"
copy_files "vmm/*" "$REMOTES_LOCATION/vmm/powerkvm"
# needed if packaged as zip
chmod +x $REMOTES_LOCATION/im/powerkvm-probes.d/*
chmod +x $REMOTES_LOCATION/im/powerkvm.d/*.sh
chmod +x $REMOTES_LOCATION/vmm/powerkvm/*
LINK="no"
copy_files "etc/*" "$ETC_LOCATION/vmm_exec"