2023-08-03 10:21:36 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# shellcheck source=patcher.sh
|
2023-07-03 13:24:45 +03:00
|
|
|
|
|
|
|
WORKDIR=$(pwd)
|
2024-04-09 12:01:27 +03:00
|
|
|
ARCH="${ARCH:-x86_64}"
|
|
|
|
LIBC="${LIBC:-musl}"
|
|
|
|
TARGET="$ARCH-unknown-linux-$LIBC"
|
2023-07-03 13:24:45 +03:00
|
|
|
|
|
|
|
|
|
|
|
# ---
|
|
|
|
dep () {
|
2023-07-20 11:42:58 +03:00
|
|
|
if ! which "$1" 2>/dev/null
|
|
|
|
then
|
|
|
|
echo "$1 not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-07-03 13:24:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
clone () {
|
|
|
|
git clone --single-branch --depth 1 "$1" "$2" || exit 2
|
|
|
|
}
|
|
|
|
|
|
|
|
cd_and_exec () {
|
|
|
|
old=$(pwd)
|
|
|
|
cd "$1" || exit 3
|
|
|
|
shift
|
|
|
|
"$@" || exit 4
|
|
|
|
cd "$old" || exit 3
|
|
|
|
}
|
|
|
|
|
2024-04-08 11:30:37 +03:00
|
|
|
update_repo () {
|
|
|
|
if [ -e "$1" ]
|
|
|
|
then
|
|
|
|
echo "$1 exists, updating"
|
2024-04-08 18:15:39 +03:00
|
|
|
old=$(pwd)
|
|
|
|
cd "$1" || exit 3
|
2024-04-08 11:30:37 +03:00
|
|
|
git stash && git stash drop
|
2024-04-08 18:15:39 +03:00
|
|
|
git pull || exit 2
|
|
|
|
cd "$old" || exit 3
|
2024-04-08 11:30:37 +03:00
|
|
|
else
|
|
|
|
echo "$1 not found, cloning"
|
|
|
|
clone "$2" "$1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-07-03 13:24:45 +03:00
|
|
|
try_exec () {
|
|
|
|
"$@"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2023-07-27 12:18:58 +03:00
|
|
|
set_piped_version () {
|
2023-08-03 10:21:36 +03:00
|
|
|
# From GitHub Actions
|
2023-07-27 12:18:58 +03:00
|
|
|
commit_date=$(git log -1 --date=short --pretty=format:%cd)
|
|
|
|
commit_sha=$(git rev-parse --short HEAD)
|
|
|
|
echo "$commit_date-$commit_sha" >VERSION
|
|
|
|
}
|
|
|
|
|
2023-07-03 13:24:45 +03:00
|
|
|
title () {
|
2023-07-03 15:19:58 +03:00
|
|
|
# Newline, Bold text, $1, Normal text, Newline
|
|
|
|
printf '\n\033[1m%s\033[0m\n' "$1"
|
2023-07-03 13:24:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# ---
|
|
|
|
title 'Checking dependencies...'
|
|
|
|
dep git
|
|
|
|
dep java
|
|
|
|
dep cargo
|
|
|
|
dep 7z
|
|
|
|
|
2024-04-08 11:30:37 +03:00
|
|
|
title 'Updating repositories...'
|
|
|
|
update_repo backend https://github.com/TeamPiped/Piped-Backend
|
|
|
|
update_repo reqwest4j https://github.com/TeamPiped/reqwest4j
|
2023-07-03 13:24:45 +03:00
|
|
|
|
|
|
|
title 'Applying patches...'
|
2023-08-03 10:21:36 +03:00
|
|
|
source patcher.sh
|
|
|
|
cd_and_exec backend patch_backend
|
|
|
|
cd_and_exec reqwest4j patch_reqwest4j
|
2023-07-03 13:24:45 +03:00
|
|
|
|
|
|
|
|
|
|
|
# ---
|
2024-04-09 12:01:27 +03:00
|
|
|
[ "$LIBC" = "musl" ] && export RUSTFLAGS="-C target-feature=-crt-static"
|
2023-07-03 13:24:45 +03:00
|
|
|
|
2023-07-04 12:23:53 +03:00
|
|
|
title 'Building reqwest-jni'
|
2023-07-20 12:04:54 +03:00
|
|
|
cd_and_exec reqwest4j/reqwest-jni \
|
2024-04-09 12:01:27 +03:00
|
|
|
cargo build --release --target "$TARGET"
|
2023-07-04 12:23:53 +03:00
|
|
|
|
|
|
|
title 'Building reqwest4j without Rust library...'
|
2023-11-24 15:56:04 +03:00
|
|
|
OLD_PATH="$PATH"
|
2024-04-04 19:17:34 +03:00
|
|
|
export JAVA_HOME="/usr/lib/jvm/java-21-openjdk"
|
2023-11-24 15:56:04 +03:00
|
|
|
export PATH="$JAVA_HOME/bin:$PATH"
|
2023-07-03 13:24:45 +03:00
|
|
|
cd_and_exec reqwest4j ./gradlew shadowJar
|
|
|
|
cd_and_exec reqwest4j ./gradlew --stop
|
2023-11-24 15:56:04 +03:00
|
|
|
export PATH="$OLD_PATH"
|
|
|
|
unset JAVA_HOME
|
2023-07-03 13:24:45 +03:00
|
|
|
|
|
|
|
|
|
|
|
# ---
|
2023-07-04 12:23:53 +03:00
|
|
|
title 'Adding built libreqwest_jni into reqwest4j JAR...'
|
2023-07-03 13:24:45 +03:00
|
|
|
|
2023-07-04 12:56:10 +03:00
|
|
|
title '--Copying files'
|
|
|
|
|
2023-07-04 12:23:53 +03:00
|
|
|
# Copy JAR into workdir
|
2023-07-03 13:24:45 +03:00
|
|
|
REQ4J_NAME="reqwest4j.jar"
|
|
|
|
REQ4J="$WORKDIR/$REQ4J_NAME"
|
2023-07-03 15:05:05 +03:00
|
|
|
|
2023-07-03 13:24:45 +03:00
|
|
|
cd_and_exec reqwest4j/build/libs \
|
|
|
|
find . -maxdepth 1 -name 'reqwest4j-*-all.jar' -exec \
|
|
|
|
cp {} "$REQ4J" \;
|
|
|
|
|
2023-07-04 12:23:53 +03:00
|
|
|
# Copy built reqwest-jni into workdir
|
|
|
|
REQJNI_NAME="libreqwest.so"
|
|
|
|
REQJNI="$WORKDIR/$REQJNI_NAME"
|
2023-07-04 12:56:10 +03:00
|
|
|
|
2024-04-09 12:01:27 +03:00
|
|
|
cd_and_exec "reqwest4j/reqwest-jni/target/$TARGET/release" \
|
2023-07-04 12:23:53 +03:00
|
|
|
cp libreqwest_jni.so "$REQJNI"
|
|
|
|
|
|
|
|
# Create JAR native libraries tree
|
2023-07-04 12:56:10 +03:00
|
|
|
title '--Creating libraries directory tree'
|
2024-04-09 12:01:27 +03:00
|
|
|
NATIVES="META-INF/natives/linux/$ARCH"
|
2023-07-04 12:23:53 +03:00
|
|
|
mkdir -p "$NATIVES"
|
|
|
|
|
|
|
|
# Move reqwest-jni to native libraries directory
|
2023-07-04 12:56:10 +03:00
|
|
|
title '--Moving libreqwest'
|
2023-07-04 12:23:53 +03:00
|
|
|
mv "$REQJNI" "$NATIVES/$REQJNI_NAME"
|
|
|
|
|
|
|
|
# Add native libraries into JAR
|
2023-07-04 12:56:10 +03:00
|
|
|
title '--Injecting libraries directory into reqwest4j JAR'
|
2023-07-04 12:23:53 +03:00
|
|
|
7z u "$REQ4J" META-INF
|
|
|
|
|
|
|
|
# Clean up
|
2023-07-04 12:56:10 +03:00
|
|
|
title '--Cleaning up'
|
2023-07-04 12:23:53 +03:00
|
|
|
rm -rf META-INF
|
|
|
|
rm -f "$REQJNI"
|
|
|
|
|
2023-07-03 13:24:45 +03:00
|
|
|
|
|
|
|
# ---
|
2023-07-04 12:23:53 +03:00
|
|
|
title 'Adding reqwest4j JAR into Piped sources...'
|
2023-07-03 15:07:17 +03:00
|
|
|
cd_and_exec backend mkdir -p libs
|
2023-07-03 13:24:45 +03:00
|
|
|
cd_and_exec backend/libs mv "$REQ4J" ./
|
|
|
|
|
2023-07-27 11:42:20 +03:00
|
|
|
title 'Creating VERSION file...'
|
2023-07-27 12:18:58 +03:00
|
|
|
cd_and_exec backend set_piped_version
|
2023-07-27 11:42:20 +03:00
|
|
|
|
2023-07-03 13:24:45 +03:00
|
|
|
title 'Building Piped...'
|
2023-11-24 15:56:04 +03:00
|
|
|
OLD_PATH="$PATH"
|
|
|
|
export JAVA_HOME="/usr/lib/jvm/java-21-openjdk"
|
|
|
|
export PATH="$JAVA_HOME/bin:$PATH"
|
2023-07-03 13:24:45 +03:00
|
|
|
cd_and_exec backend ./gradlew shadowJar
|
|
|
|
cd_and_exec backend ./gradlew --stop
|
2023-11-24 15:56:04 +03:00
|
|
|
export PATH="$OLD_PATH"
|
|
|
|
unset JAVA_HOME
|
2023-07-03 13:24:45 +03:00
|
|
|
|
|
|
|
|
|
|
|
# ---
|
|
|
|
title 'Copying Piped JAR...'
|
|
|
|
cd_and_exec backend/build/libs \
|
|
|
|
find . -maxdepth 1 -name 'piped-*-all.jar' -exec \
|
|
|
|
cp {} "$WORKDIR/piped.jar" \;
|
|
|
|
|
2023-07-27 11:53:33 +03:00
|
|
|
title 'Copying config and version...'
|
|
|
|
cd_and_exec backend cp config.properties VERSION "$WORKDIR"
|
2023-07-03 13:24:45 +03:00
|
|
|
|
|
|
|
|
|
|
|
# ---
|
2023-07-04 12:56:10 +03:00
|
|
|
echo
|
2023-07-03 13:27:16 +03:00
|
|
|
echo '*** ************** ***'
|
|
|
|
echo '*** DONE ***'
|
|
|
|
echo '*** ************** ***'
|
|
|
|
|
2023-07-03 13:24:45 +03:00
|
|
|
title 'You need these files:'
|
2023-07-03 13:27:16 +03:00
|
|
|
|
2023-07-27 11:53:33 +03:00
|
|
|
for f in "piped.jar" "config.properties" "VERSION"
|
2023-07-03 13:24:45 +03:00
|
|
|
do
|
|
|
|
echo " $(readlink -f "$f")"
|
|
|
|
done
|