From f57b2f0f53bd48a29a0db340a4b7eb724d2538eb Mon Sep 17 00:00:00 2001 From: leafee98 Date: Thu, 13 Apr 2023 09:53:57 +0800 Subject: [PATCH] add script to build all and upload to webdav --- README.md | 13 +++++++++++ script/build_all.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 README.md create mode 100644 script/build_all.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..d497495 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Debian Packages + +My workflow to build deb files. + +## Build all packages and upload to webdav + +``` +export WEBDAV_USER=webdav_user +export WEBDAV_PASS=abcdefghijklmnopqrstuvwxyz +export WEBDAV_HOST=https://webdav.example.com +export WEBDAV_REPOPATH=packages +bash script/build_all.sh +``` diff --git a/script/build_all.sh b/script/build_all.sh new file mode 100644 index 0000000..f5a9377 --- /dev/null +++ b/script/build_all.sh @@ -0,0 +1,57 @@ +#!/usr/bin/evn bash +# +set -o pipefail +set -o errexit +set -o errtrace + +WEBDAV_USER=${WEBDAV_USER:?WEBDAV_USER not set} +WEBDAV_PASS=${WEBDAV_PASS:?WEBDAV_PASS not set} +WEBDAV_HOST=${WEBDAV_HOST:?WEBDAV_HOST not set} +WEBDAV_REPOPATH=${WEBDAV_REPOPATH:?WEBDAV_REPOPATH not set} + +function curl_alias { + curl --show-error --silent --user "${WEBDAV_USER}:${WEBDAV_PASS}" "$@" +} + +function webdav_is_file_exists { + local target="${1%/}" + local target="${target#/}" + local resp=$(curl_alias --head --write-out "%{http_code}" "${WEBDAV_HOST}/${WEBDAV_REPOPATH}/${target}" | tail -n 1) + [[ "${resp}" == "200" ]] +} + +function webdav_mkcol { + local dirname="${1#/}" + curl_alias --request MKCOL "${WEBDAV_HOST}/${dirname}" +} + +function webdav_upload_file { + curl_alias --silent --upload-file "$1" "${WEBDAV_HOST}/${WEBDAV_REPOPATH}/$2" + echo "file $1 uploaded to ${WEBDAV_HOST}/${WEBDAV_REPOPATH}/$2" +} + +function build_single { + ( + local package_name="$1" + local package_path="$(realpath "$1")" + cd "$package_path" + local target_filename="$(../makedeb/makedeb -STF | tail -n 1)" + + if webdav_is_file_exists "${target_filename}" ; then + echo "${package_name} already built, skipped." + return + fi + + ../makedeb/makedeb + + webdav_upload_file "${target_filename}" "${target_filename}" + ) +} + + +for i in $(find . -maxdepth 1 -mindepth 1 -type d -not -path './script' -not -path './makedeb' -not -name '.*') +do + echo === building $i + build_single $i + echo === built $i +done