-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer.sh
86 lines (69 loc) · 1.81 KB
/
installer.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
#!/bin/bash
#
# Filename: installer.sh
# Version: 1.0.0
# Description: Install executable and source files.
# Author(s): Alex Portell <github.com/portellam>
# Maintainer(s): Alex Portell <github.com/portellam>
#
function is_user_root
{
if [[ $( whoami ) != "root" ]]; then
echo "User is not root."
return 1
fi
return 0
}
function install
{
local -r relative_path="bin"
local -r script_file="powerstate-virtmanager.sh"
if [[ ! -e "${relative_path}/${script_file}" ]]; then
echo "Error: Cannot locate script file."
return 1
fi
local -r source_file="powerstate-virtmanager.d/script-dialog"
if [[ ! -e "${relative_path}/${source_file}" ]]; then
echo "Error: Cannot locate source file."
return 1
fi
local -r destination_path="/usr/local/bin"
if ! cp --force --recursive "${relative_path}/${script_file}" \
"${destination_path}/${script_file}" &> /dev/null; then
echo "Error: Cannot copy script file."
return 1
fi
if ! mkdir --parents $( dirname "${destination_path}/${source_file}" ) \
&> /dev/null; then
echo "Error: Cannot copy script file."
return 1
fi
if ! cp --force --recursive "${relative_path}/${source_file}" \
"${destination_path}/${source_file}" &> /dev/null; then
echo "Error: Cannot copy source file."
return 1
fi
if ! chmod +x "${destination_path}/${script_file}" \
&> /dev/null; then
echo "Error: Cannot set script file as executable."
return 1
fi
if ! chmod +x "${destination_path}/${source_file}" \
&> /dev/null; then
echo "Error: Cannot set source file as executable."
return 1
fi
return 0
}
function main
{
if ! is_user_root \
|| ! install; then
echo "Install failed."
return 1
fi
echo "Install successful."
return 0
}
main
exit "${?}"