#!/bin/sh set -eu [ "$#" -lt 2 ] && { echo "Use: [workdir] [basepath] #items on stdin" exit; } readonly mepath="$(readlink -m $(dirname $0)/..)" starttime="$(date +%s)" ddate() { date -u "-d@$starttime" "$1"; } ftime() { faketime -f "$(ddate '+%Y-%m-%d %H:%M:%SZ') x0" "$@"; } base_dir="$1"; shift base_url="$1"; shift # hacky thing to make sure url ends in / if ! echo "$base_url" | grep -q '/$'; then base_url="${base_url}/" fi safeurl() { echo "$1" | sed 's,/,_,g;s,_$,,'; } [ -d "$base_dir" ] || mkdir "$base_dir" base_url_hostonly="$(echo "$base_url" | sed -e 's,^http,,;s,^s,,;s,^://,,')" item_id="$(safeurl "$base_url_hostonly")__bundles_$(ddate '+%Y%m%d')${1:-}" work_dir="${base_dir}/${item_id}" echo "-- making $item_id folder --" mkdir "$work_dir" while IFS='' read -r url; do urlp="$(safeurl "$url")" urlwp="$work_dir/$urlp" { unset HOME XDG_CONFIG_HOME SSH_ASKPASS GIT_ASKPASS set +e echo "$ git clone --mirror $url $urlp" USER=archiveteam-codearchiver-runner ftime git -c 'core.sshCommand=ssh -F /dev/null -o "UserKnownHostsFile /dev/null" -o "IdentitiesOnly yes" -o "StrictHostKeyChecking no"' -c 'credential.interactive=false' clone --mirror "$url" "$urlwp" echo "$ GIT_DIR=$urlp git bundle create $urlp.bundle --all" USER=archiveteam-codearchiver-runner GIT_DIR=$urlwp ftime git bundle create "$urlwp.bundle" --all [ "$?" = "0" ] && { echo "$ rm --recursive --force $urlp" USER=archiveteam-codearchiver-runner rm --recursive --force "$urlwp" } set -e } 2>&1 | tee "$urlwp.log" sed -i $'s\1'"$work_dir"$'\1'"/archive/"$'\1g' "$urlwp.log" zstd --rm -19 "$urlwp.log" done echo "-- finished job for $base_url --" echo "-- generating dir-to-ia.conf (check it and write as .config) --" cat >"${work_dir}/.dir-to-ia.conf" <git clone --mirror \$REPOURL \$TMPCLONEDIR and GIT_DIR=\$TMPCLONEDIR git bundle create \$BUNDLENAME --all" "mediatype:software" "title:$base_url_hostonly repository bundles ($(ddate '+%Y-%m-%d'))" ) EoC