-
Notifications
You must be signed in to change notification settings - Fork 34
/
install
executable file
·72 lines (64 loc) · 2.68 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
#!/bin/bash
# Version 8
# This script detects if the widget is already installed.
# If it is, it will use --upgrade instead and restart plasmashell.
# Eg: kpackagetool6 --type "Plasma/Applet" --install package
# Eg: kpackagetool6 --type "Plasma/Applet" --upgrade package
# Eg: killall plasmashell ; kstart plasmashell
if [ -f "$PWD/package/metadata.json" ]; then # Plasma6 (and later versions of Plasma5)
packageNamespace=`python3 -c 'import sys, json; print(json.load(sys.stdin).get("KPlugin", {}).get("Id", ""))' < "$PWD/package/metadata.json"`
packageServiceType=`python3 -c 'import sys, json; print(json.load(sys.stdin).get("KPackageStructure",""))' < "$PWD/package/metadata.json"`
if [ -z "$packageServiceType" ]; then # desktoptojson will set KPlugin.ServiceTypes[0] instead of KPackageStructure
packageServiceType=`python3 -c 'import sys, json; print((json.load(sys.stdin).get("KPlugin", {}).get("ServiceTypes", [])+[""])[0])' < "$PWD/package/metadata.json"`
echo "[warning] metadata.json needs KPackageStructure set in Plasma6"
fi
elif [ -f "$PWD/package/metadata.desktop" ]; then # Plasma5
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"`
else
echo "[error] Could not find 'package/metadata.json' or 'package/metadata.desktop'"
exit 1
fi
echo "Namespace: ${packageNamespace}"
echo "Type: ${packageServiceType}"
if [ -z "$packageServiceType" ]; then
echo "[error] Could not parse metadata"
exit 1
fi
if command -v kpackagetool6 &> /dev/null ; then kpackagetool="kpackagetool6" # Plasma6
elif command -v kpackagetool5 &> /dev/null ; then kpackagetool="kpackagetool5" # Plasma5
else
echo "[error] Could not find 'kpackagetool6'"
exit 1
fi
if command -v kstart &> /dev/null ; then kstart="kstart" # Plasma6
elif command -v kstart5 &> /dev/null ; then kstart="kstart5" # Plasma5
else
echo "[error] Could not find 'kstart'"
exit 1
fi
restartPlasmashell=false
for arg in "$@"; do
case "$arg" in
-r) restartPlasmashell=true;;
--restart) restartPlasmashell=true;;
*) ;;
esac
done
isAlreadyInstalled=false
"$kpackagetool" --type="${packageServiceType}" --show="$packageNamespace" &> /dev/null
if [ $? == 0 ]; then
isAlreadyInstalled=true
fi
if $isAlreadyInstalled; then
# Eg: kpackagetool6 --type "Plasma/Applet" --upgrade package
"$kpackagetool" -t "${packageServiceType}" -u package
restartPlasmashell=true
else
# Eg: kpackagetool6 --type "Plasma/Applet" --install package
"$kpackagetool" -t "${packageServiceType}" -i package
fi
if $restartPlasmashell; then
killall plasmashell
"$kstart" plasmashell
fi