Last active 1 month ago

Create a new Arch Linux package for Squeebot plugin

mkpackage.sh Raw
1#!/usr/bin/env bash
2set -euo pipefail
3PLUGIN=$1
4NPM_USER=Squeebot
5PACKAGER="${NPM_USER,,}"
6PACKAGEBASE=https://git.icynet.eu/api/packages/$NPM_USER/npm
7
8if [ -z $PLUGIN ]; then
9 echo 'Please provide plugin name'
10 exit 1
11fi
12
13DESTDIR=$PWD/pkgbuilds/nodejs-$PACKAGER-$PLUGIN
14
15echo "Creating directory for package"
16mkdir -p $DESTDIR
17
18PLUGINSRC=https://git.icynet.eu/$NPM_USER/$PLUGIN
19
20function get_version_src() {
21 echo "$PACKAGEBASE/%40$NPM_USER%2F$PLUGIN"
22}
23
24function get_package_src() {
25 echo "$PACKAGEBASE/%40$NPM_USER%2F$PLUGIN/-/$1/$PLUGIN-$1.tgz"
26}
27
28echo "Determining the latest version"
29
30# Get latest version from Gitea
31LATEST_VERSION=$(curl -s $(get_version_src) | jq -r '.["dist-tags"].latest')
32
33echo "Found version $LATEST_VERSION, determining sha256sum"
34
35# Get latest version checksum for the PKGBUILD
36LATEST_CHECKSUM=$(curl -s $(get_package_src $LATEST_VERSION) | sha256sum | cut -f 1 -d " ")
37
38SERVICE=$(cat <<EOF
39[Unit]
40Description=Squeebot v4 ${PLUGIN^} plugin
41After=network.target nats-server.service
42
43[Service]
44Type=simple
45ExecStartPre=mkdir -p %h/.config/squeebot/
46ExecStart=/usr/bin/squeeboot @squeebot/$PLUGIN
47WorkingDirectory=-%h/.config/squeebot/
48
49[Install]
50WantedBy=default.target
51
52EOF
53)
54
55SERVICE_CHECKSUM=$(echo "$SERVICE" | sha256sum | cut -f 1 -d " ")
56
57PKGBUILD=$(cat <<EOF
58# Maintainer: Evert Prants
59
60_npm_user=$PACKAGER
61_npm_pkg=$PLUGIN
62pkgname=nodejs-\$_npm_user-\$_npm_pkg
63pkgdesc="Squeebot v4 ${PLUGIN^} plugin"
64pkgver=$LATEST_VERSION
65pkgrel=1
66url="$PLUGINSRC"
67arch=(any)
68license=(MIT)
69makedepends=('npm')
70optdepends=('nodejs-squeebot-squeeboot: Required to use the included service')
71noextract=("\${_npm_pkg}-\${pkgver}.tgz")
72sha256sums=(
73 '$LATEST_CHECKSUM'
74 '$SERVICE_CHECKSUM'
75)
76_filename=\$_npm_pkg-\$pkgver.tgz
77source=(
78 "$PACKAGEBASE/%40\$_npm_user%2F\$_npm_pkg/-/\$pkgver/\$_filename"
79 "local://$PACKAGER-$PLUGIN.service"
80)
81function 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
93EOF
94)
95
96GITIGNORE=$(cat <<EOF
97src/
98pkg/
99*.pkg.tar.zst
100*.tgz
101
102EOF
103)
104
105GITEA=$(cat <<EOF
106name: Publish packages
107on:
108 push:
109 branches: [main]
110
111jobs:
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
126EOF
127)
128
129echo "Writing out"
130
131cd $DESTDIR
132git init
133
134echo "$SERVICE" > "$PACKAGER-$PLUGIN.service"
135echo "$PKGBUILD" > PKGBUILD
136echo "$GITIGNORE" > .gitignore
137
138mkdir -p .gitea/workflows
139echo "$GITEA" > .gitea/workflows/publish.yml
140
141echo "Building package for the first time"
142
143makepkg --printsrcinfo > .SRCINFO
144makepkg
145
146echo "Adding to git"
147git add .
148git commit -m "Initial commit"
149
150echo "All done!"
151