mkpackage.sh
· 3.2 KiB · Bash
Raw
#!/usr/bin/env bash
set -euo pipefail
PLUGIN=$1
NPM_USER=Squeebot
PACKAGER="${NPM_USER,,}"
PACKAGEBASE=https://git.icynet.eu/api/packages/$NPM_USER/npm
if [ -z $PLUGIN ]; then
echo 'Please provide plugin name'
exit 1
fi
DESTDIR=$PWD/pkgbuilds/nodejs-$PACKAGER-$PLUGIN
echo "Creating directory for package"
mkdir -p $DESTDIR
PLUGINSRC=https://git.icynet.eu/$NPM_USER/$PLUGIN
function get_version_src() {
echo "$PACKAGEBASE/%40$NPM_USER%2F$PLUGIN"
}
function get_package_src() {
echo "$PACKAGEBASE/%40$NPM_USER%2F$PLUGIN/-/$1/$PLUGIN-$1.tgz"
}
echo "Determining the latest version"
# Get latest version from Gitea
LATEST_VERSION=$(curl -s $(get_version_src) | jq -r '.["dist-tags"].latest')
echo "Found version $LATEST_VERSION, determining sha256sum"
# Get latest version checksum for the PKGBUILD
LATEST_CHECKSUM=$(curl -s $(get_package_src $LATEST_VERSION) | sha256sum | cut -f 1 -d " ")
SERVICE=$(cat <<EOF
[Unit]
Description=Squeebot v4 ${PLUGIN^} plugin
After=network.target nats-server.service
[Service]
Type=simple
ExecStartPre=mkdir -p %h/.config/squeebot/
ExecStart=/usr/bin/squeeboot @squeebot/$PLUGIN
WorkingDirectory=-%h/.config/squeebot/
[Install]
WantedBy=default.target
EOF
)
SERVICE_CHECKSUM=$(echo "$SERVICE" | sha256sum | cut -f 1 -d " ")
PKGBUILD=$(cat <<EOF
# Maintainer: Evert Prants
_npm_user=$PACKAGER
_npm_pkg=$PLUGIN
pkgname=nodejs-\$_npm_user-\$_npm_pkg
pkgdesc="Squeebot v4 ${PLUGIN^} plugin"
pkgver=$LATEST_VERSION
pkgrel=1
url="$PLUGINSRC"
arch=(any)
license=(MIT)
makedepends=('npm')
optdepends=('nodejs-squeebot-squeeboot: Required to use the included service')
noextract=("\${_npm_pkg}-\${pkgver}.tgz")
sha256sums=(
'$LATEST_CHECKSUM'
'$SERVICE_CHECKSUM'
)
_filename=\$_npm_pkg-\$pkgver.tgz
source=(
"$PACKAGEBASE/%40\$_npm_user%2F\$_npm_pkg/-/\$pkgver/\$_filename"
"local://$PACKAGER-$PLUGIN.service"
)
function package() {
npm set "@\${_npm_user}:registry" "$PACKAGEBASE/"
npm i -g --prefix "\${pkgdir}/usr" "\${srcdir}/\$_filename"
find "\${pkgdir}" -name package.json -print0 | xargs -r -0 sed -i '/_where/d'
# npm gives ownership of ALL FILES to build user
# https://bugs.archlinux.org/task/63396
chown -R root:root "\${pkgdir}"
install -Dm 644 "\${srcdir}/$PACKAGER-$PLUGIN.service" -t "\${pkgdir}/usr/lib/systemd/user"
}
EOF
)
GITIGNORE=$(cat <<EOF
src/
pkg/
*.pkg.tar.zst
*.tgz
EOF
)
GITEA=$(cat <<EOF
name: Publish packages
on:
push:
branches: [main]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build archlinux package
uses: https://git.icynet.eu/evert/arch-makepkg-action@v1
- name: Publish archlinux package
uses: https://git.icynet.eu/evert/gitea-publish-arch-packages@v1
with:
token: \${{ secrets.PUB_ACCESS_TOKEN }}
repository: squeebot
files: |-
**.pkg.tar.zst
EOF
)
echo "Writing out"
cd $DESTDIR
git init
echo "$SERVICE" > "$PACKAGER-$PLUGIN.service"
echo "$PKGBUILD" > PKGBUILD
echo "$GITIGNORE" > .gitignore
mkdir -p .gitea/workflows
echo "$GITEA" > .gitea/workflows/publish.yml
echo "Building package for the first time"
makepkg --printsrcinfo > .SRCINFO
makepkg
echo "Adding to git"
git add .
git commit -m "Initial commit"
echo "All done!"
| 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=default.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!" |
| 151 |