-
Notifications
You must be signed in to change notification settings - Fork 22
/
install.sh
executable file
·93 lines (74 loc) · 2.16 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
#!/bin/bash
# Installer for PDFMtEd
# (c) 2014 Glutanimate
# License: GNU GPLv3
# Variables
Installer="$(readlink -f "$0")"
SourcePath="${Installer%/*}"
InstallPath="/usr/local"
BinPath="$InstallPath/bin"
LauncherPath="$InstallPath/share/applications"
IconPath="$InstallPath/share/icons/hicolor/scalable/apps"
Application="PDFMtEd"
InstallationFiles=("desktop/pdfmted-editor.desktop" "desktop/pdfmted-inspector.desktop"\
"desktop/pdfmted.svg" "pdfmted-editor" "pdfmted-inspector" "pdfmted-thumbnailer")
Dependencies=(yad exiftool python3 qpdf)
# Functions
check_deps() {
for i in "$@"; do
type "$i" > /dev/null 2>&1
if [[ "$?" != "0" ]]; then
MissingDeps+=" $i"
fi
done
if [[ -n "$MissingDeps" ]]; then
echo "Error: Missing dependencies(${MissingDeps})"
echo "Aborting installation."
exit 1
fi
}
check_sourcefiles(){
for i in "$@"; do
if [[ ! -f "$i" && ! -d "$i" ]]; then
echo "Error: $i not found in current directory.
Please make sure to execute the installer in the same
directory as all other project files."
echo "Aborting installation."
exit 1
fi
done
}
check_destinations(){
for i in "$@"; do
if [[ ! -d "$i" ]]; then
echo "Error: Installation directory not found ($i)"
echo "Aborting installation."
exit 1
fi
done
}
# Main
# Check if interactive
if [[ ! -t "0" ]]; then
echo "Error: Shell not interactive"
echo "Aborting installation"
exit 1
fi
# Check if root
if [[ "$(whoami)" != "root" ]]; then
echo "Error: This script needs root privileges. Restarting..."
sudo "$0"
exit
fi
cd "$SourcePath"
echo "Checking installation files for integrity..."
check_sourcefiles "${InstallationFiles[@]}"
echo "Checking installation directory..."
check_destinations "$BinPath" "$LauncherPath" "$IconPath"
echo "Checking dependencies..."
check_deps "${Dependencies[@]}"
echo "Installing $Application to $InstallPath ..."
sudo cp -v "pdfmted-editor" "pdfmted-inspector" "pdfmted-thumbnailer" "${BinPath}/"
sudo cp -v "desktop/pdfmted-editor.desktop" "desktop/pdfmted-inspector.desktop" "${LauncherPath}/"
sudo cp -v "desktop/pdfmted.svg" "${IconPath}/"
echo "Done."