-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpkg_build.sh
executable file
·61 lines (47 loc) · 1.66 KB
/
pkg_build.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
#!/bin/bash
plugin_name="docker.labelInjector"
CWD=$(pwd)
tmpdir="$CWD/tmp/tmp.$(($RANDOM * 19318203981230 + 40))"
version=$(date +"%Y.%m.%d")
filename="$CWD/archive/$plugin_name-$version.txz"
rm "$filename"
dayversion=$(ls "$CWD"/archive/$plugin_name-"$version"*.txz 2>/dev/null | wc -l)
if [ "$dayversion" -gt 0 ]; then
filename=$CWD/archive/$plugin_name-$version.$dayversion.txz
fi
mkdir -p "$tmpdir"
rsync -av --progress src/$plugin_name/ "$tmpdir" --exclude .git --exclude tmp --exclude .env --exclude archive
cd "$tmpdir" || exit
tar_command="tar"
sed_prefix="-i"
if [[ "$(uname)" == "Darwin" ]]; then
tar_command="gtar"
sed_prefix="-i ''"
fi
$tar_command --owner=root --group=root -cJf "$filename" .
cd - || exit
if [[ "$(uname)" == "Darwin" ]]; then
md5hash=$(md5 -q "$filename")
else
md5hash=$(md5sum "$filename" | awk '{ print $1 }')
fi
rm -rf "$tmpdir"
sed "$sed_prefix" 's/<!ENTITY version ".*">/<!ENTITY version "'"$version"'">/' $plugin_name.plg
sed "$sed_prefix" 's/<!ENTITY md5 ".*">/<!ENTITY md5 "'"$md5hash"'">/' $plugin_name.plg
echo "MD5: $(md5sum "$filename")"
echo "once pushed install via https://raw.githubusercontent.com/phyzical/$plugin_name/main/$plugin_name.plg"
$tar_command -tvf "$filename"
# Check for ownership issues
OWN=$($tar_command -tvf "$filename" | grep -v "root/root" | grep -v "root root")
if [ -n "$OWN" ]; then
echo "Ownership issues (should be root/root):"
echo "$OWN"
exit 1
fi
# Check for permission issues
PERM=$($tar_command -tvf "$filename" | grep -v "rwxr-xr-x" | grep -v "rw-r--r--")
if [ -n "$PERM" ]; then
echo "Permission issues (should be rwxr-xr-x or rw-r--r--):"
echo "$PERM"
exit 1
fi