147 lines
3.6 KiB
Bash
Executable file
147 lines
3.6 KiB
Bash
Executable file
#!/usr/bin/env zsh
|
|
|
|
SCRIPT_PATH="${0:A:h}"
|
|
source $SCRIPT_PATH/apikeys.sh
|
|
|
|
|
|
if [ $# -ne 2 ]; then
|
|
echo "please give me target and architecture(s) plss..."
|
|
exit
|
|
fi
|
|
|
|
if (( $+commands[gsed] )); then
|
|
alias sed=gsed
|
|
fi
|
|
if (( $+commands[gdate] )); then
|
|
alias date=gdate
|
|
fi
|
|
|
|
target=${1:l}
|
|
architecture=${2:l}
|
|
NAME_CAPS=${(C)target}
|
|
|
|
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
|
|
Section: $SECTION
|
|
Priority: optional
|
|
Maintainer: alex
|
|
|
|
Package: $target
|
|
Depends: $DEPENDS
|
|
Version: $VERSION
|
|
Architecture: $architecture
|
|
Description: $target" > $DEBIAN_DIR/control
|
|
|
|
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
|
|
|
|
sysusers_file="u $target - - /var/lib/$target
|
|
g $target -"
|
|
echo $sysusers_file > $DEBIAN_DIR/$target.sysusers
|
|
|
|
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"
|
|
|
|
echo $service_file > $DEBIAN_DIR/$target.service
|
|
|
|
|
|
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
|
|
|
|
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"
|
|
fi
|
|
done
|
|
|
|
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 |