forked from Zren/plasma-applet-eventcalendar
-
Notifications
You must be signed in to change notification settings - Fork 4
/
build
executable file
·115 lines (101 loc) · 4.01 KB
/
build
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
# User Variables
qtMinVer="5.12"
kfMinVer="5.68"
plasmaMinVer="5.18"
filenameTag="-plasma${plasmaMinVer}"
packageExt="plasmoid"
# Misc
startDir=$PWD
# Function Definitions
## Check Command Success
check_command_success() {
if [ "$1" != "0" ]; then
echoRed "[error] Failed executing: $2"
exit 1
fi
}
## Initialize Color Variables and Functions
initialize_colors() {
# Color definitions
TC_Red='\033[31m'; TC_Orange='\033[33m';
TC_LightGray='\033[90m'; TC_LightRed='\033[91m'; TC_LightGreen='\033[92m'; TC_Yellow='\033[93m'; TC_LightBlue='\033[94m';
TC_Reset='\033[0m'; TC_Bold='\033[1m';
if [ ! -t 1 ]; then
TC_Red=''; TC_Orange='';
TC_LightGray=''; TC_LightRed=''; TC_LightGreen=''; TC_Yellow=''; TC_LightBlue='';
TC_Bold=''; TC_Reset='';
fi
# Color echo functions
echoTC() {
local text="$1"
local textColor="$2"
echo -e "${textColor}${text}${TC_Reset}"
}
echoGray() { echoTC "$1" "$TC_LightGray"; }
echoRed() { echoTC "$1" "$TC_Red"; }
echoGreen() { echoTC "$1" "$TC_LightGreen"; }
}
## Check QML Versions
check_qml_versions() {
if [ -f checkimports.py ]; then
python3 checkimports.py --qt="$qtMinVer" --kf="$kfMinVer" --plasma="$plasmaMinVer"
check_command_success "$?" "Version check failed"
fi
}
## Handle Translations
handle_translations() {
if [ -d "package/translate" ]; then
echoGray "[build] translate dir found, running merge."
(cd package/translate && sh ./merge)
(cd package/translate && sh ./build)
if type "git" > /dev/null; then
if [ "$(git diff --stat package/translate)" != "" ]; then
echoRed "[build] Changed detected. Cancelling build."
git diff --stat .
exit 1
fi
else
echoGray "[build] Git not found, skipping translation diff check."
fi
fi
}
## Convert metadata.desktop to metadata.json
convert_metadata() {
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"
fi
}
## Package the plasmoid
package_plasmoid() {
if ! type "zip" > /dev/null; then
echoRed "[error] 'zip' command not found."
if type "zypper" > /dev/null; then
echoRed "[error] Opensuse detected, please run: ${TC_Bold}sudo zypper install zip"
fi
exit 1
fi
local packageNamespace=$(kreadconfig5 --file="$PWD/package/metadata.desktop" --group="Desktop Entry" --key="X-KDE-PluginInfo-Name")
local packageName="${packageNamespace##*.}" # Strip namespace (Eg: "org.kde.plasma.")
local packageVersion=$(kreadconfig5 --file="$PWD/package/metadata.desktop" --group="Desktop Entry" --key="X-KDE-PluginInfo-Version")
local filename="${packageName}-v${packageVersion}${filenameTag}.${packageExt}"
rm -f ${packageName}-v*.${packageExt} # Cleanup
echoGray "[${packageExt}] Zipping '${filename}'"
(cd package \
&& zip -r $filename * \
&& mv $filename $startDir/$filename \
)
echoGray "[${packageExt}] md5: $(md5sum $filename | awk '{ print $1 }')"
echoGray "[${packageExt}] sha256: $(sha256sum $filename | awk '{ print $1 }')"
}
# Main Script Logic
initialize_colors
check_qml_versions
handle_translations
convert_metadata
package_plasmoid
echoGreen "[build] Packaging completed successfully."
# Return to start directory
cd $startDir