Skip to content

Commit

Permalink
Rework invocations of helper executables
Browse files Browse the repository at this point in the history
  • Loading branch information
plengauer authored Aug 16, 2024
1 parent d4e1e6c commit 2726b8b
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 27 deletions.
3 changes: 2 additions & 1 deletion package/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash -e
export PATH=/usr/share/gitaptly:"$PATH"

if [ "$1" = 'abort-configure' ] || [ "$1" = 'abort-upgrade' ] || [ "$1" = 'abort-remove' ] || [ "$1" = 'abort-deconfigure' ]; then
exit 0
Expand Down Expand Up @@ -40,7 +41,7 @@ elif [ "$MODE" = "proxy" ]; then
rm -rf /var/lib/gitaptly/pool || true
ln --symbolic /usr/share/gitaptly/serve /var/lib/gitaptly/pool
fi
bash /usr/share/gitaptly/update
update

systemctl daemon-reload
systemctl enable gitaptly
Expand Down
3 changes: 1 addition & 2 deletions package/etc/cron.d/gitaptly
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
0 * * * * root /usr/share/gitaptly/update

0 * * * * root /bin/sh -c 'export PATH=/usr/share/gitaptly:"$PATH"; exec update'
2 changes: 1 addition & 1 deletion package/etc/systemd/system/gitaptly.service
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ Restart=always
RestartSec=1
StartLimitBurst=10
User=nobody
ExecStart=/usr/share/gitaptly/run_ftp
ExecStart=/bin/sh -c 'export PATH=/usr/share/gitaptly:"$PATH"; exec run_ftp'
[Install]
WantedBy=multi-user.target
3 changes: 1 addition & 2 deletions package/usr/share/gitaptly/create_release
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
set -e
#!/bin/bash -e
directory=$1

cd $directory
Expand Down
3 changes: 1 addition & 2 deletions package/usr/share/gitaptly/reset
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/bin/bash
set -e
#!/bin/bash -e
parallel rm -rf ::: /var/lib/gitaptly/dists/stable/Release /var/lib/gitaptly/dists/stable/main/binary-all/Packages.gz /var/lib/gitaptly/dists/stable/main/binary-all/Packages /var/lib/gitaptly/pool/main/*
3 changes: 2 additions & 1 deletion package/usr/share/gitaptly/run_ftp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash -e
export PATH=/usr/share/gitaptly:"$PATH"
source /opt/gitaptly/env
if [ -n "$OTLP_TRACES_ENDPOINT" ] || [ -n "$OTLP_METRICS_ENDPOINT" ]; then
export OTEL_SERVICE_NAME=GitAptly
Expand All @@ -12,6 +13,6 @@ if [ -n "$OTLP_TRACES_ENDPOINT" ] || [ -n "$OTLP_METRICS_ENDPOINT" ]; then
export OTEL_EXPORTER_OTLP_METRICS_HEADERS=authorization=$(echo "$OTLP_METRICS_HEADER" | jq -Rr @uri)
export OTEL_EXPORTER_OTLP_LOGS_ENDPOINT="$OTLP_LOGS_ENDPOINT"
export OTEL_EXPORTER_OTLP_LOGS_HEADERS=authorization=$(echo "$OTLP_LOGS_HEADER" | jq -Rr @uri)
export OTEL_SHELL_EXPERIMENTAL_OBSERVE_PIPES=TRUE
export OTEL_SHELL_CONFIG_OBSERVE_PIPES=TRUE
fi
exec abomhttp "$PORT" /var/lib/gitaptly
3 changes: 1 addition & 2 deletions package/usr/share/gitaptly/scan
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
set -e
#!/bin/bash -e
source /opt/gitaptly/env
if [ -n "$GITHUB_API_TOKEN" ]; then
auth_header="Authorization: Bearer $GITHUB_API_TOKEN"
Expand Down
12 changes: 3 additions & 9 deletions package/usr/share/gitaptly/serve
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
#!/bin/bash -e
export PATH=/usr/share/gitaptly:"$PATH"
method="$1"
path="$2"

Expand All @@ -12,7 +12,7 @@ file=$(echo "$path" | rev | cut -d/ -f1 | rev)
repo=$(echo "$path" | rev | cut -d/ -f2 | rev)
owner=$(echo "$path" | rev | cut -d/ -f3 | rev)

url="$(bash -e /usr/share/gitaptly/scan $owner/$repo | grep "$file"'$' | head --lines=1)"
url="$(scan $owner/$repo | grep "$file"'$' | head --lines=1)"

if [ -z "$url" ]; then
printf 'HTTP/1.1 404 Not Found\r\n\r\n'
Expand All @@ -22,9 +22,3 @@ fi
printf 'HTTP/1.1 308 Permanent Redirect\r\n'
printf 'location: '"$url"'\r\n'
printf '\r\n'

# printf 'HTTP/1.1 200 OK\r\n'
# printf 'content-encoding: identity\r\n'
# printf 'content-type: application/vnd.debian.binary-package\r\n'
# printf '\r\n'
# wget -O - "$url"
14 changes: 7 additions & 7 deletions package/usr/share/gitaptly/update
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
#!/bin/bash -e
export PATH=/usr/share/gitaptly:"$PATH"
source /opt/gitaptly/env
if [ -f /usr/bin/opentelemetry_shell.sh ]; then
export OTEL_SERVICE_NAME=GitAptly
Expand All @@ -12,15 +12,15 @@ if [ -f /usr/bin/opentelemetry_shell.sh ]; then
export OTEL_EXPORTER_OTLP_METRICS_HEADERS=authorization=$(echo "$OTLP_METRICS_HEADER" | jq -Rr @uri)
export OTEL_EXPORTER_OTLP_LOGS_ENDPOINT="$OTLP_LOGS_ENDPOINT"
export OTEL_EXPORTER_OTLP_LOGS_HEADERS=authorization=$(echo "$OTLP_LOGS_HEADER" | jq -Rr @uri)
export OTEL_SHELL_EXPERIMENTAL_OBSERVE_PIPES=TRUE
export OTEL_SHELL_EXPERIMENTAL_INSTRUMENT_MINIMALLY=TRUE
export OTEL_SHELL_CONFIG_OBSERVE_PIPES=TRUE
export OTEL_SHELL_CONFIG_INSTRUMENT_MINIMALLY=TRUE
source otel.sh
fi
cd /var/lib/gitaptly

if [ "$MODE" = 'cache' ]; then
cat /etc/gitaptly.conf | xargs -r -I {} mkdir -p pool/main/{}
cat /etc/gitaptly.conf | sort -u | sort -R | parallel -q bash -c 'bash -e /usr/share/gitaptly/scan {} | xargs -r wget -nc -P pool/main/{}/'
cat /etc/gitaptly.conf | sort -u | sort -R | parallel -q bash -c 'scan {} | xargs -r wget -nc -P pool/main/{}/'
dpkg-scanpackages --multiversion pool/ > dists/stable/main/binary-all/Packages
elif [ "$MODE" = 'proxy' ]; then
indexify() {
Expand All @@ -40,11 +40,11 @@ elif [ "$MODE" = 'proxy' ]; then
touch dists/stable/main/binary-all/Packages
index="$(mktemp)"
cat dists/stable/main/binary-all/Packages | grep '^Filename: ' | cut -d ' ' -f 2- | cut -d / -f 3- | awk -F'/' '{print "^https://.*/"$1"/"$2"/.*/"$3"$"}' > "$index"
cat /etc/gitaptly.conf | sort -u | sort -R | parallel bash -e /usr/share/gitaptly/scan | grep -v -f "$index" | parallel indexify
cat /etc/gitaptly.conf | sort -u | sort -R | parallel scan | grep -v -f "$index" | parallel indexify
rm "$index"
else
exit 1
fi

gzip -9 < dists/stable/main/binary-all/Packages > dists/stable/main/binary-all/Packages.gz
bash -e /usr/share/gitaptly/create_release dists/stable > dists/stable/Release
create_release dists/stable > dists/stable/Release

0 comments on commit 2726b8b

Please sign in to comment.