refactor: make source-script with common fn, cleanup code -> trap

This commit is contained in:
DarkCat09 2024-12-20 18:15:57 +04:00
parent 478659e4bc
commit 5a11c6cad0
Signed by: DarkCat09
GPG key ID: BD3CE9B65916CD82
4 changed files with 38 additions and 27 deletions

25
.build.sh Normal file
View file

@ -0,0 +1,25 @@
#!/bin/echo Must be sourced from a bash script **
# strict mode
export IFS=$'\n'
set -eu -o pipefail
# git clone wrapper
clone () {
if ! [ -e "$2" ]; then
git clone \
--single-branch --depth 1 \
--recurse-submodules \
"$1" \
"$2"
else
echo " ** '$2/' already exists"
fi
}
# make -j12
make_maxthreads() {
[ -v JOBS ] || JOBS=$(nproc || echo 4)
JOBS="${JOBS//[^0-9]/}"
make -j"$JOBS"
}

View file

@ -1,7 +1,6 @@
#!/bin/bash #!/bin/bash
IFS=$'\n' source .build.sh
set -eu -o pipefail
echo echo
echo '==> Checking deps' echo '==> Checking deps'
@ -12,13 +11,10 @@ which gcc || which clang
echo echo
echo '==> Cloning repo' echo '==> Cloning repo'
if ! [ -e bind9 ]; then clone https://gitlab.isc.org/isc-projects/bind9.git bind9
git clone --single-branch --depth 1 https://gitlab.isc.org/isc-projects/bind9.git bind9
else
echo ' ** bind9/ already exists'
fi
cd bind9 cd bind9
trap 'cd ..' EXIT
export CFLAGS="-O3" CPPFLAGS="-O3" export CFLAGS="-O3" CPPFLAGS="-O3"
echo echo
@ -38,10 +34,7 @@ echo '==> ./configure (check deps, generate config)'
echo echo
echo '==> make' echo '==> make'
make -j$(nproc) make_maxthreads
unset CFLAGS CPPFLAGS
cd ..
echo echo
echo '==> Done' echo '==> Done'

View file

@ -1,7 +1,6 @@
#!/bin/bash #!/bin/bash
IFS=$'\n' source .build.sh
set -eu -o pipefail
echo echo
echo '==> Checking deps' echo '==> Checking deps'
@ -13,13 +12,10 @@ which gcc || which clang
echo echo
echo '==> Cloning repo' echo '==> Cloning repo'
if ! [ -e ldns ]; then clone https://github.com/NLnetLabs/ldns.git ldns
git clone --single-branch --depth 1 --recurse-submodules https://github.com/NLnetLabs/ldns.git ldns
else
echo ' ** ldns/ already exists'
fi
cd ldns cd ldns
trap 'cd ..' EXIT
export CFLAGS="-O3" export CFLAGS="-O3"
echo echo
@ -42,10 +38,7 @@ echo '==> ./configure (check deps, generate config)'
echo echo
echo '==> make' echo '==> make'
make -j$(nproc || echo 4) make_maxthreads
unset CFLAGS
cd ..
echo echo
echo '==> Done' echo '==> Done'

View file

@ -1,7 +1,6 @@
#!/bin/bash #!/bin/bash
IFS=$'\n' source .build.sh
set -eu -o pipefail
echo echo
echo '==> Checking deps' echo '==> Checking deps'
@ -10,18 +9,19 @@ which cargo
echo echo
echo '==> Cloning repo' echo '==> Cloning repo'
git clone --single-branch --depth 1 https://github.com/hickory-dns/hickory-dns.git hickory-dns clone https://github.com/hickory-dns/hickory-dns.git hickory-dns
cd hickory-dns
trap 'cd ..' EXIT
echo echo
echo '==> Building resolve' echo '==> Building resolve'
cd hickory-dns
cargo build \ cargo build \
--release \ --release \
--bin resolve \ --bin resolve \
--features dnssec-ring \ --features dnssec-ring \
--config 'panic="abort"' \ --config 'panic="abort"' \
--config 'lto="fat"' --config 'lto="fat"'
cd ..
echo echo
echo '==> Done' echo '==> Done'