forked from alexandregz/gogs-spk
-
Notifications
You must be signed in to change notification settings - Fork 23
/
create_spk.sh
executable file
·101 lines (76 loc) · 2.18 KB
/
create_spk.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
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
#!/bin/sh
# Determines the binary for which the package should be build.
select_binary()
{
local args=$1
local binary=""
if [ ! "$args" = "" ]; then
if [ -f $args ]; then
binary=$args
else
echo "$1 not found"
exit 1
fi
else
# pick the latest binary
binary=$(ls -1 -t gitea-*-linux-*[!.spk] 2>/dev/null | head -1)
if [ ! $? -eq 0 ]; then
echo "No gitea binary found. Please download a binary from https://github.com/go-gitea/gitea/releases"
exit 1
fi
fi
echo "$binary"
}
# Determines the version number of the given Gitea binary.
get_version()
{
local binary="$1"
echo ${binary} | sed 's/[^0-9.]*\([0-9.]*\).*/\1/'
}
# Determines the platform identifier of the given Gitea binary.
get_platform()
{
local binary="$1"
echo ${binary} | sed 's/.*linux-\(.*\)/\1/'
}
# Determines the Synology arch values for the given Gitea binary.
get_arch()
{
local binary="$1"
local platform=`get_platform $binary`
# lookup the arch values for the given platform in the mappings file
grep "^$platform " 'arch.desc' | awk '{for (i=2; i<=NF; i++) printf "%s ", $i}' | xargs
}
# Updates the package metadata to reflect the given Gitea binary.
update_metadata()
{
local version="$1"
local arch="$2"
if [ "$arch" = "" ]; then
echo "$binary is not a supported platform"
exit 1
fi
cp 2_create_project/INFO.in 2_create_project/INFO
sed -i -e "s/[0-9]\+\.[0-9]\+\.[0-9]\+/$version/" 2_create_project/INFO
sed -i -e "s#arch=\".*\"#arch=\"$arch\"#" 2_create_project/INFO
}
# Builds the package for the given Gitea binary.
build()
{
local current=$PWD
local binary=$1
version=`get_version $binary`
arch=`get_arch $binary`
update_metadata "$version" "$arch"
chmod +x $binary
mkdir -p 1_create_package/gitea
ln -sf "$PWD/$binary" 1_create_package/gitea/gitea
cd 1_create_package
tar cvfhz ../2_create_project/package.tgz *
cd ../2_create_project/
tar cvfz ../$binary.spk --exclude=INFO.in *
rm -f package.tgz
cd $current
}
binary=`select_binary $@`
build "$binary"