-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconfigure_archive.sh
More file actions
executable file
·59 lines (46 loc) · 1.51 KB
/
configure_archive.sh
File metadata and controls
executable file
·59 lines (46 loc) · 1.51 KB
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
#!/usr/bin/env bash
# Functions
# FN fatal_error
# Description: display error message then exits 1
# arg1: message
fatal_error(){
local message="$1"
echo "[fatal] $message" >&2
exit 1
}
# Globals
archive_path=$1
archive_filename=$(basename "$archive_path")
# We expect the folder to be the same as the archive
archive_folder=${archive_filename%.tar.gz}
# Can be specific per OS
module_destination=/usr/share/centreon/www/modules
module_destination_path="${module_destination:?}"/"$archive_folder"
destination_user=apache
destination_group=apache
# Main
if ! [ -f "$archive_path" ]; then
fatal_error "Unable to find archive"
fi
if (( "$(id -u)" != 0 )); then
fatal_error "Script is not run by root, we need it to move the folder and give it proper permission"
fi
if ! tar -xvf "$archive_path" > /dev/null; then
fatal_error "Unable to extract archive"
fi
if ! [ -d "$archive_folder" ]; then
fatal_error "Unable to find archive folder '$archive_folder', ensure you made a valid archive"
fi
if [ -d "$module_destination_path" ]; then
echo "Existing module at centreon, removing"
if ! rm -rf "$module_destination_path"; then
fatal_error "Unable to remove previous module"
fi
fi
if ! mv "$archive_folder" "$module_destination/"; then
fatal_error "Unable to move archive folder to centreon module folder"
fi
if ! chown -R "$destination_user":"$destination_group" "$module_destination_path"; then
fatal_error "Unable to move archive folder to centreon module folder"
fi
echo Done