DebArrs/build.sh

147 lines
3.6 KiB
Bash
Raw Permalink Normal View History

2024-05-19 14:02:06 +10:00
#!/usr/bin/env zsh
SCRIPT_PATH="${0:A:h}"
source $SCRIPT_PATH/apikeys.sh
2024-05-19 18:05:11 +10:00
if [ $# -ne 2 ]; then
2024-05-19 14:02:06 +10:00
echo "please give me target and architecture(s) plss..."
exit
fi
2024-05-19 18:05:11 +10:00
if (( $+commands[gsed] )); then
alias sed=gsed
fi
if (( $+commands[gdate] )); then
alias date=gdate
fi
2024-05-19 14:02:06 +10:00
target=${1:l}
2024-05-19 18:05:11 +10:00
architecture=${2:l}
2024-05-19 14:02:06 +10:00
NAME_CAPS=${(C)target}
2024-05-19 18:05:11 +10:00
echo "Building $NAME_CAPS..."
TEMP_DIR=$(mktemp -d)
BUILD_DIR=$TEMP_DIR/build
mkdir -p $BUILD_DIR
DEBIAN_DIR=$BUILD_DIR/debian
mkdir -p $DEBIAN_DIR
curl -Ls https://api.github.com/repos/$NAME_CAPS/$NAME_CAPS/releases --header "Authorization: Bearer $GITHUB_API_KEY" --header "X-GitHub-Api-Version: 2022-11-28" | jq -c '.[]' | while read -r release; do
version=$(jq -r '.name' <<<$release)
echo "$target ($version) testing; urgency=medium"
echo ""
jq -r '.body' <<<$release | sed -e '/^\*/!d' -e '/\*$/d' | sed -E 's/\*\*/-/g' | while read -r line; do
echo " $line"
done
author=$(jq -r '.author.login' <<<$release)
date=$(jq -r '.published_at' <<<$release)
date=$(date --date="$date" -R)
echo ""
echo " $author $date"
echo ""
done > $DEBIAN_DIR/changelog
source $SCRIPT_PATH/config/$target.config.sh
VERSION=$(jq -r '.name' <<<$JSON)
echo "\tVersion: $VERSION"
echo 12 > $DEBIAN_DIR/compat
echo "#!/usr/bin/make -f
clean:
build:
binary:
dh_installsysusers
dh_installsystemd
dh_installtmpfiles
dh_gencontrol
dh_builddeb" > $DEBIAN_DIR/rules
echo "Source: $target
2024-05-19 14:14:49 +10:00
Section: $SECTION
2024-05-19 14:02:06 +10:00
Priority: optional
2024-05-19 14:23:00 +10:00
Maintainer: alex
Package: $target
Depends: $DEPENDS
Version: $VERSION
2024-05-19 18:05:11 +10:00
Architecture: $architecture
Description: $target" > $DEBIAN_DIR/control
2024-05-19 14:14:49 +10:00
2024-05-19 18:05:11 +10:00
PKG_DIR=$DEBIAN_DIR/$target
mkdir -p $PKG_DIR
tmpfiles_file="# Override this file with a modified version in /etc/tmpfiles.d/
d /var/lib/$target 0755 $target $target
Z /var/lib/$target - $target $target
Z /usr/lib/$target - $target $target
L /var/log/$target - - - - /var/lib/$target/logs/"
echo $tmpfiles_file > $DEBIAN_DIR/$target.tmpfiles
2024-05-19 14:02:06 +10:00
2024-05-19 18:05:11 +10:00
sysusers_file="u $target - - /var/lib/$target
g $target -"
echo $sysusers_file > $DEBIAN_DIR/$target.sysusers
2024-05-19 14:02:06 +10:00
service_file="# Be sure to use \`systemctl edit $target\` to modify this service with an override.conf because
# direct changes will be overwritten by package updates.
[Unit]
Description=$NAME_CAPS Service
Wants=network-online.target
After=network-online.target
[Service]
User=$target
Group=$target
SyslogIdentifier=$target
ExecStart=/usr/lib/$target/bin/$NAME_CAPS -nobrowser -data=/var/lib/$target
Type=simple
[Install]
WantedBy=multi-user.target"
2024-05-19 18:05:11 +10:00
echo $service_file > $DEBIAN_DIR/$target.service
2024-05-19 14:02:06 +10:00
rel_info=$(jq '.assets[] | select(.name | contains("linux")) | select(.name | contains("musl") | not)' <<<$JSON)
declare -a tarballs=($(jq '"\(.browser_download_url) /\(.name)"' <<<$rel_info | tr -d '"' | tr "\n" " "))
for ((i = 1; i < ${#tarballs[@]}; i += 2)); do
url="${tarballs[i]}"
filename="${tarballs[i + 1]#/}"
arch=$(sed -E "s/^.+?linux-(.+?).tar.gz$/\1/g" <<<"${tarballs[i + 1]}")
if [[ "$arch" == "x64" ]] || [[ "$arch" == "core-x64" ]]; then
arch="amd64"
fi
if [[ "$arch" == "core-x86" ]]; then
arch="i386"
fi
if [[ "$arch" == "arm" ]] || [[ "$arch" == "core-arm" ]]; then
arch="armhf"
fi
if [[ "$arch" == "core-arm64" ]]; then
arch="arm64"
fi
2024-05-19 18:05:11 +10:00
if [[ "$arch" == "$architecture" ]]; then
curl -Ls $url | tar xz -C $BUILD_DIR/
rm -rf $BUILD_DIR/$NAME_CAPS/$NAME_CAPS.Update
install -d -m 755 "$PKG_DIR/usr/lib/$target/bin"
cp -dpr --no-preserve=ownership "$BUILD_DIR/$NAME_CAPS"* "$PKG_DIR/usr/lib/$target/bin"
2024-05-19 14:02:06 +10:00
fi
done
2024-05-19 18:05:11 +10:00
cd $BUILD_DIR
dpkg-buildpackage -b
cd $TEMP_DIR
rm -rf $BUILD_DIR
OUT_DIR=$SCRIPT_PATH/debs
mkdir -p $OUT_DIR
cp $TEMP_DIR/* $OUT_DIR