forked from ALikesToCode/plasma-applet-eventcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·94 lines (83 loc) · 3.09 KB
/
install
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
#!/usr/bin/env bash
# Function to check if a command was successful
check_command_success() {
if [ "$1" != "0" ]; then
echo "Error executing command: $2"
exit 1
fi
}
# Function to install required packages
install_requirements() {
# Determine the Linux distribution
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
elif type lsb_release >/dev/null 2>&1; then
DISTRO=$(lsb_release -i | cut -d: -f2 | sed s/'^\t'//)
else
DISTRO=$(uname -s)
fi
# Normalize distro names to lowercase
DISTRO=$(echo "$DISTRO" | tr '[:upper:]' '[:lower:]')
case "$DISTRO" in
"debian"|"ubuntu"|"kali"|"raspbian")
required_commands=("kreadconfig5" "kpackagetool5")
packages_to_install=("libkf5coreaddons-bin-dev" "kpackagetool5")
install_cmd="sudo apt-get update && sudo apt-get install -y"
;;
"arch")
required_commands=("kreadconfig5" "kpackagetool5")
packages_to_install=("kcoreaddons" "kpackagetool5")
install_cmd="sudo pacman -S"
;;
"fedora")
required_commands=("kreadconfig5" "kpackagetool5")
packages_to_install=("kf5-kcoreaddons" "kf5-kpackage")
install_cmd="sudo dnf install"
;;
*)
echo "Unsupported distribution: $DISTRO"
return 1
;;
esac
for i in "${!required_commands[@]}"; do
if ! command -v "${required_commands[$i]}" &> /dev/null; then
echo "${required_commands[$i]} is not installed. Attempting to install..."
$install_cmd "${packages_to_install[$i]}"
check_command_success "$?" "Failed to install ${packages_to_install[$i]}"
fi
done
}
# Install script requirements
install_requirements
# Parse arguments for restart option
restartPlasmashell=false
for arg in "$@"; do
case "$arg" in
-r|--restart) restartPlasmashell=true;;
*) ;;
esac
done
# Determine if the package is already installed
packageNamespace=$(kreadconfig5 --file="$PWD/package/metadata.desktop" --group="Desktop Entry" --key="X-KDE-PluginInfo-Name")
packageServiceType=$(kreadconfig5 --file="$PWD/package/metadata.desktop" --group="Desktop Entry" --key="X-KDE-ServiceTypes")
kpackagetool5 --type="${packageServiceType}" --show="$packageNamespace" &> /dev/null
isAlreadyInstalled=$?
# Convert metadata.desktop to metadata.json
if command -v desktoptojson &> /dev/null ; then
desktoptojson --serviceType="plasma-applet.desktop" -i "$PWD/package/metadata.desktop" -o "$PWD/package/metadata.json"
check_command_success "$?" "desktoptojson conversion failed"
sed -i 's/ \{4\}/\t/g' "$PWD/package/metadata.json" # Tabify metadata.json
fi
# Install or update the package
if [ "$isAlreadyInstalled" == "0" ]; then
kpackagetool5 -t "${packageServiceType}" -u package
restartPlasmashell=true
else
kpackagetool5 -t "${packageServiceType}" -i package
fi
# Restart Plasma shell if required
if $restartPlasmashell; then
killall plasmashell
( cd $HOME && kstart5 plasmashell )
fi