Naposledy aktivní 1 month ago

Create a new Arch Linux package for Squeebot plugin

evert's Avatar evert revidoval tento gist 1 month ago. Přejít na revizi

1 file changed, 1 insertion, 1 deletion

mkpackage.sh

@@ -47,7 +47,7 @@ ExecStart=/usr/bin/squeeboot @squeebot/$PLUGIN
47 47 WorkingDirectory=-%h/.config/squeebot/
48 48
49 49 [Install]
50 - WantedBy=multi-user.target
50 + WantedBy=default.target
51 51
52 52 EOF
53 53 )

evert's Avatar evert revidoval tento gist 1 month ago. Přejít na revizi

1 file changed, 150 insertions

mkpackage.sh(vytvořil soubor)

@@ -0,0 +1,150 @@
1 + #!/usr/bin/env bash
2 + set -euo pipefail
3 + PLUGIN=$1
4 + NPM_USER=Squeebot
5 + PACKAGER="${NPM_USER,,}"
6 + PACKAGEBASE=https://git.icynet.eu/api/packages/$NPM_USER/npm
7 +
8 + if [ -z $PLUGIN ]; then
9 + echo 'Please provide plugin name'
10 + exit 1
11 + fi
12 +
13 + DESTDIR=$PWD/pkgbuilds/nodejs-$PACKAGER-$PLUGIN
14 +
15 + echo "Creating directory for package"
16 + mkdir -p $DESTDIR
17 +
18 + PLUGINSRC=https://git.icynet.eu/$NPM_USER/$PLUGIN
19 +
20 + function get_version_src() {
21 + echo "$PACKAGEBASE/%40$NPM_USER%2F$PLUGIN"
22 + }
23 +
24 + function get_package_src() {
25 + echo "$PACKAGEBASE/%40$NPM_USER%2F$PLUGIN/-/$1/$PLUGIN-$1.tgz"
26 + }
27 +
28 + echo "Determining the latest version"
29 +
30 + # Get latest version from Gitea
31 + LATEST_VERSION=$(curl -s $(get_version_src) | jq -r '.["dist-tags"].latest')
32 +
33 + echo "Found version $LATEST_VERSION, determining sha256sum"
34 +
35 + # Get latest version checksum for the PKGBUILD
36 + LATEST_CHECKSUM=$(curl -s $(get_package_src $LATEST_VERSION) | sha256sum | cut -f 1 -d " ")
37 +
38 + SERVICE=$(cat <<EOF
39 + [Unit]
40 + Description=Squeebot v4 ${PLUGIN^} plugin
41 + After=network.target nats-server.service
42 +
43 + [Service]
44 + Type=simple
45 + ExecStartPre=mkdir -p %h/.config/squeebot/
46 + ExecStart=/usr/bin/squeeboot @squeebot/$PLUGIN
47 + WorkingDirectory=-%h/.config/squeebot/
48 +
49 + [Install]
50 + WantedBy=multi-user.target
51 +
52 + EOF
53 + )
54 +
55 + SERVICE_CHECKSUM=$(echo "$SERVICE" | sha256sum | cut -f 1 -d " ")
56 +
57 + PKGBUILD=$(cat <<EOF
58 + # Maintainer: Evert Prants
59 +
60 + _npm_user=$PACKAGER
61 + _npm_pkg=$PLUGIN
62 + pkgname=nodejs-\$_npm_user-\$_npm_pkg
63 + pkgdesc="Squeebot v4 ${PLUGIN^} plugin"
64 + pkgver=$LATEST_VERSION
65 + pkgrel=1
66 + url="$PLUGINSRC"
67 + arch=(any)
68 + license=(MIT)
69 + makedepends=('npm')
70 + optdepends=('nodejs-squeebot-squeeboot: Required to use the included service')
71 + noextract=("\${_npm_pkg}-\${pkgver}.tgz")
72 + sha256sums=(
73 + '$LATEST_CHECKSUM'
74 + '$SERVICE_CHECKSUM'
75 + )
76 + _filename=\$_npm_pkg-\$pkgver.tgz
77 + source=(
78 + "$PACKAGEBASE/%40\$_npm_user%2F\$_npm_pkg/-/\$pkgver/\$_filename"
79 + "local://$PACKAGER-$PLUGIN.service"
80 + )
81 + function package() {
82 + npm set "@\${_npm_user}:registry" "$PACKAGEBASE/"
83 + npm i -g --prefix "\${pkgdir}/usr" "\${srcdir}/\$_filename"
84 + find "\${pkgdir}" -name package.json -print0 | xargs -r -0 sed -i '/_where/d'
85 +
86 + # npm gives ownership of ALL FILES to build user
87 + # https://bugs.archlinux.org/task/63396
88 + chown -R root:root "\${pkgdir}"
89 +
90 + install -Dm 644 "\${srcdir}/$PACKAGER-$PLUGIN.service" -t "\${pkgdir}/usr/lib/systemd/user"
91 + }
92 +
93 + EOF
94 + )
95 +
96 + GITIGNORE=$(cat <<EOF
97 + src/
98 + pkg/
99 + *.pkg.tar.zst
100 + *.tgz
101 +
102 + EOF
103 + )
104 +
105 + GITEA=$(cat <<EOF
106 + name: Publish packages
107 + on:
108 + push:
109 + branches: [main]
110 +
111 + jobs:
112 + publish:
113 + runs-on: ubuntu-latest
114 + steps:
115 + - uses: actions/checkout@v4
116 + - name: Build archlinux package
117 + uses: https://git.icynet.eu/evert/arch-makepkg-action@v1
118 + - name: Publish archlinux package
119 + uses: https://git.icynet.eu/evert/gitea-publish-arch-packages@v1
120 + with:
121 + token: \${{ secrets.PUB_ACCESS_TOKEN }}
122 + repository: squeebot
123 + files: |-
124 + **.pkg.tar.zst
125 +
126 + EOF
127 + )
128 +
129 + echo "Writing out"
130 +
131 + cd $DESTDIR
132 + git init
133 +
134 + echo "$SERVICE" > "$PACKAGER-$PLUGIN.service"
135 + echo "$PKGBUILD" > PKGBUILD
136 + echo "$GITIGNORE" > .gitignore
137 +
138 + mkdir -p .gitea/workflows
139 + echo "$GITEA" > .gitea/workflows/publish.yml
140 +
141 + echo "Building package for the first time"
142 +
143 + makepkg --printsrcinfo > .SRCINFO
144 + makepkg
145 +
146 + echo "Adding to git"
147 + git add .
148 + git commit -m "Initial commit"
149 +
150 + echo "All done!"
Novější Starší