-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
157 lines (125 loc) · 5.63 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env bash
# Base directory
TOP_DIR=$(cd $(dirname "$0") && pwd)
# Import common functions
source $TOP_DIR/lib/functions-common
source $TOP_DIR/lib/functions-extra
source $TOP_DIR/lib/settings
SNOOZENODE_FILES_DESTINATION=$TOP_DIR/files/snoozenode
SNOOZEIMAGES_FILES_DESTINATION=$TOP_DIR/files/snoozeimages
SNOOZEEC2_FILES_DESTINATION=$TOP_DIR/files/snoozeec2
SNOOZECLIENT_FILES_DESTINATION=$TOP_DIR/files/snoozeclient
# Determine what system we are running on. This provides ``os_VENDOR``,
# ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
# and ``DISTRO``
GetDistro
echo "You are running "
echo $os_RELEASE / $os_PACKAGE / $os_CODENAME
if [[ $EUID -eq 0 ]]; then
echo "You are running this script as root."
fi
is_package_installed sudo || install_package sudo
[[ -z "$PACKAGES" ]] && die "PACKAGES list is not set. Exiting."
echo "Installing required packages"
for i in $PACKAGES;
do
echo "Installing $i"
is_package_installed $i || install_package $i
echo "$i installed"
done
## Create the user SNOOZEADMIN / SNOOZE
if ! getent group $SNOOZEGROUP > /dev/null; then
echo "Creating the group $SNOOZEGROUP"
sudo groupadd $SNOOZEGROUP
fi
if ! getent passwd $SNOOZEADMIN > /dev/null; then
echo "Creating the user $SNOOZEADMIN"
sudo useradd -s /bin/false $SNOOZEADMIN -g $SNOOZEGROUP
fi
## Add user to the libvirt group
if [[ $os_VENDOR == "Ubuntu" ]]; then
sudo adduser snoozeadmin libvirtd
elif [[ $os_VENDOR == "Debian" ]]; then
sudo adduser snoozeadmin libvirt
else
exit_distro_not_supported "Add user"
fi
echo "Downloading snoozenode files"
mkdir -p $SNOOZENODE_FILES_DESTINATION
for i in $SNOOZENODE_FILES;
do
echo "Installing $i"
w_get "$SNOOZENODE_FILES_LOCATION/$i" "$SNOOZENODE_FILES_DESTINATION/$i"
done
echo "Downloading snoozenode files"
mkdir -p $SNOOZEEC2_FILES_DESTINATION
for i in $SNOOZEEC2_FILES;
do
echo "Installing $i"
w_get "$SNOOZEEC2_FILES_LOCATION/$i" "$SNOOZEEC2_FILES_DESTINATION/$i"
done
echo "Downloading snoozenode files"
mkdir -p $SNOOZEIMAGES_FILES_DESTINATION
for i in $SNOOZEIMAGES_FILES;
do
echo "Installing $i"
w_get "$SNOOZEIMAGES_FILES_LOCATION/$i" "$SNOOZEIMAGES_FILES_DESTINATION/$i"
done
mkdir -p $SNOOZECLIENT_FILES_DESTINATION
echo "Downloading snoozeclient files"
for i in $SNOOZECLIENT_FILES;
do
echo "Installing $i"
w_get "$SNOOZECLIENT_FILES_LOCATION/$i" "$SNOOZECLIENT_FILES_DESTINATION/$i"
done
## change jars/configs location in scripts/settings.sh
perl -pi -e "s,^install_directory.*,install_directory=\"$SNOOZENODE_FILES_DESTINATION\"," "$TOP_DIR/scripts/settings.sh"
perl -pi -e "s,^node_jar_file.*,node_jar_file=\"\\\$install_directory/snoozenode.jar\"," "$TOP_DIR/scripts/settings.sh"
perl -pi -e "s,^node_config_file.*,node_config_file=\"\\\$install_directory/snooze_node.cfg\"," "$TOP_DIR/scripts/settings.sh"
perl -pi -e "s,^node_log_file.*,node_log_file=\"\\\$install_directory/log4j.xml\"," "$TOP_DIR/scripts/settings.sh"
perl -pi -e "s,^snoozeimages_install_directory.*,snoozeimages_install_directory=\"$SNOOZEIMAGES_FILES_DESTINATION\"," "$TOP_DIR/scripts/settings.sh"
perl -pi -e "s,^snoozeimages_node_jar_file.*,snoozeimages_node_jar_file=\\\$snoozeimages_install_directory/snoozeimages.jar," "$TOP_DIR/scripts/settings.sh"
perl -pi -e "s,^snoozeimages_config_file.*,snoozeimages_config_file=\"\\\$snoozeimages_install_directory/snooze_images.cfg\"," "$TOP_DIR/scripts/settings.sh"
perl -pi -e "s,^snoozeimages_log_file.*,snoozeimages_log_file=\"\\\$snoozeimages_install_directory/log4j.xml\"," "$TOP_DIR/scripts/settings.sh"
perl -pi -e "s,^snoozeec2_install_directory.*,snoozeec2_install_directory=\"$SNOOZEEC2_FILES_DESTINATION\"," "$TOP_DIR/scripts/settings.sh"
perl -pi -e "s,^snoozeec2_node_jar_file.*,snoozeec2_node_jar_file=\\\$snoozeec2_install_directory/snoozeec2.jar," "$TOP_DIR/scripts/settings.sh"
perl -pi -e "s,^snoozeec2_config_file.*,snoozeec2_config_file=\"\\\$snoozeec2_install_directory/snooze_ec2.cfg\"," "$TOP_DIR/scripts/settings.sh"
perl -pi -e "s,^snoozeec2_log_file.*,snoozeec2_log_file=\"\\\$snoozeec2_install_directory/log4j.xml\"," "$TOP_DIR/scripts/settings.sh"
perl -pi -e "s,^snoozeec2_instances_file.*,snoozeec2_instances_file=\"\\\$snoozeec2_install_directory/instances\"," "$TOP_DIR/scripts/settings.sh"
## Installation of snoozeimages
pool=$(virsh -q pool-list --all | grep default)
if [[ -z $pool ]]
then
echo "Defining a new default pool"
sudo virsh pool-define-as --name default --target /var/lib/libvirt/images --type dir
sudo virsh pool-build default
sudo virsh pool-start default
fi
# post install
echo "fix permissions on libvirt pool"
if [[ $os_VENDOR == "Ubuntu" ]]; then
sudo adduser libvirt-qemu libvirtd
sudo chown root:libvirtd -R /var/lib/libvirt/images
elif [[ $os_VENDOR == "Debian" ]]; then
sudo adduser libvirt-qemu libvirt
sudo chown root:libvirt -R /var/lib/libvirt/images
else
exit_distro_not_supported "Cannot add libvirt-qemu to libvirt group"
fi
#snooze-context to generate context.iso
if [ ! -f "/var/lib/libvirt/images/context.iso" ]
then
#Download context.zip in the current repertory
w_get "http://snooze.inria.fr/downloads/images/context.iso" "/var/lib/libvirt/images/context.iso"
else
echo "L'image context.iso est déjà présente dans le répertoire /var/lib/libvirt/images"
fi
#snooze-ubuntu1310 already exists
if [ ! -f "/var/lib/libvirt/images/snooze-ubuntu1310.qcow2" ]
then
#download context.zip in the current repertory
w_get "http://snooze.inria.fr/downloads/images/snooze-ubuntu1310.qcow2" "/var/lib/libvirt/images/snooze-ubuntu1310.qcow2"
else
echo "l'image context.iso est déjà présente dans le répertoire /var/lib/libvirt/images"
fi
sudo chmod 775 -R /var/lib/libvirt/images