Skip to content

Commit 3ee69b1

Browse files
committed
Refactor the installer for Linux
1 parent 8c368ab commit 3ee69b1

File tree

1 file changed

+43
-24
lines changed

1 file changed

+43
-24
lines changed

misc/install.sh

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,47 @@
11
#!/bin/bash
2+
set -euo pipefail
23

34
VERSION="0.9"
45
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
56

6-
install(){
7+
perform_install(){
78
# Remove older version
89
if [ -d "/opt/xl-converter" ]; then
10+
echo "Removing the previous installation from /opt/xl-converter"
911
sudo rm -rf "/opt/xl-converter/"
1012
sleep 0.5 # Stops menu entry from disappearing until restart
1113
fi
1214

13-
# Desktop entries
14-
cp -f "$SCRIPT_DIR/xl-converter.desktop" ~/Desktop/
15-
sudo cp -f "$SCRIPT_DIR/xl-converter.desktop" /usr/share/applications/
16-
1715
# Install
18-
echo "Installing..."
19-
sudo cp -rf "$SCRIPT_DIR/xl-converter" /opt/ # Copy program files
20-
sudo chmod -R +rx /opt/xl-converter # Add permissions
21-
22-
echo "Installation complete"
16+
echo "Installing XL Converter to /opt/xl-converter"
17+
sudo cp -rf "$SCRIPT_DIR/xl-converter" /opt/
18+
sudo chmod -R +rx /opt/xl-converter
19+
20+
if command -v xdg-user-dir &> /dev/null; then
21+
DESKTOP_DIR=$(xdg-user-dir DESKTOP)
22+
if [ -d "$DESKTOP_DIR" ]; then
23+
echo "Copying a .desktop file to $DESKTOP_DIR"
24+
cp -f "$SCRIPT_DIR/xl-converter.desktop" "$DESKTOP_DIR/"
25+
fi
26+
fi
27+
28+
if [ -d "/usr/share/applications" ]; then
29+
echo "Adding a menu entry to /usr/share/applications"
30+
sudo cp -f "$SCRIPT_DIR/xl-converter.desktop" /usr/share/applications/
31+
fi
32+
33+
echo "Installation complete."
2334
}
2435

25-
check_root_permissions(){
36+
request_root_permissions(){
2637
# Check if sudo is installed
2738
if ! command -v sudo &> /dev/null; then
28-
echo "Install sudo and try again"
39+
echo "Install sudo and try again."
2940
exit 1
3041
fi
3142

32-
# Get root privileges (for copying files into /opt/)
33-
if [ $EUID -ne 0 ]; then
43+
# Request root privileges from user (for copying files into /opt/)
44+
if [ "$EUID" -ne 0 ]; then
3445
sudo -v || { echo "Installation canceled, try again."; exit 1; }
3546
fi
3647
}
@@ -40,8 +51,6 @@ post_install(){
4051
if command -v update-desktop-database &> /dev/null; then
4152
sudo update-desktop-database /usr/share/applications/ &> /dev/null
4253
fi
43-
44-
echo "You will find shortcuts in the start menu and on the desktop"
4554
}
4655

4756
main(){
@@ -55,14 +64,24 @@ main(){
5564

5665
echo -e "[2] Exit\n"
5766

58-
read -p "Choice: " choice
59-
60-
if [ "$choice" == "1" ]; then
61-
check_root_permissions
62-
install
63-
post_install
64-
exit 0
65-
fi
67+
while true; do
68+
read -r -p "Choice: " choice
69+
case "$choice" in
70+
1)
71+
request_root_permissions
72+
perform_install
73+
post_install
74+
exit 0
75+
;;
76+
2)
77+
echo "Exiting."
78+
exit 0
79+
;;
80+
*)
81+
echo "Invalid option, try again."
82+
;;
83+
esac
84+
done
6685
}
6786

6887
main

0 commit comments

Comments
 (0)