From e2c434ebaeede0373335ace70dd873a4ab349843 Mon Sep 17 00:00:00 2001 From: Marko Semet Date: Fri, 25 Dec 2020 02:24:28 +0100 Subject: [PATCH] Fix build and upload repo --- build.sh | 2 +- update_repo.py | 21 ++++++++----------- upload.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 14 deletions(-) create mode 100755 upload.sh diff --git a/build.sh b/build.sh index b841701..d86aae7 100755 --- a/build.sh +++ b/build.sh @@ -17,7 +17,7 @@ if [ -z "$4" ]; then BUILD_DIR= exec flatpak-builder $3 --arch "$2" --sandbox --rebuild-on-sdk-change --bundle-sources "$BUILD_DIR" "$1" else HASH="$("$(dirname "$0")/hash_modules.py" --installed "$1" "$2" | sed -n '1p')" && - ID="$("$(dirname "$0")/hash_modules.py" --get-id "$1" "$2").Builds" && + ID="$(IFS=';' && "$(dirname "$0")/hash_modules.py" --get-id "$1" "$2" | read a b c && echo "$a/$b.Builds/$c")" && ( find '.flatpak-builder/build' '.flatpak-builder/cache' -delete || rm -rf ".flatpak-builder/build" '.flatpak-builder/cache' diff --git a/update_repo.py b/update_repo.py index 8766afe..cb1fe06 100755 --- a/update_repo.py +++ b/update_repo.py @@ -13,7 +13,7 @@ class Repo: @property def flatpaks(self): tmp = subprocess.run(["ostree", "refs", "--repo", self._repo], capture_output=True, check=True) - return list(filter(lambda x: x.startswith(("runtime/", "app/")), tmp.stdout.decode().splitlines())) + return list(filter(lambda x: x.startswith(("runtime/", "app/")) or x == "empty", tmp.stdout.decode().splitlines())) def move_commit(self, repo, commit:str, no_fsync:bool=False, gpg_key:str=None, collection:str=None): assert isinstance(repo, Repo) @@ -29,7 +29,7 @@ class Repo: run_args.append("--gpg-sign=" + gpg_key) if collection: run_args.append("--extra-collection-id=" + collection) - subprocess.run(["flatpak", "build-commit-from"] + run_args + ["--src-repo=" + repo._repo, "--src-ref=" + commit, "--no-update-summary", self._repo, commit], check=True) + subprocess.run(["flatpak", "build-commit-from"] + run_args + ["--src-repo=" + repo._repo, "--src-ref=" + commit, self._repo, commit], check=True) def make_eol(self, commit:str, no_fsync:bool=False, gpg_key:str=None, collection:str=None): assert isinstance(commit, str) @@ -44,16 +44,11 @@ class Repo: run_args.append("--gpg-sign=" + gpg_key) if collection: run_args.append("--extra-collection-id=" + collection) - subprocess.run(["flatpak", "build-commit-from"] + run_args + ["--end-of-life=Base commit doesn't exists any more.", "--no-update-summary", "--src-ref=empty", self._repo, commit], check=True) - - def gen_empty(self): - subprocess.run(["tar", "-cf", "empty.tar", "-T", "/dev/null"], check=True) - subprocess.run(["ostree", "commit", "--repo", self._repo, "--tar-autocreate-parents", "--tree=tar=empty.tar", "-b", "empty"], check=True) - os.remove("empty.tar") + subprocess.run(["flatpak", "build-commit-from", "--no-update-summary", "--no-summary-index"] + run_args + ["--end-of-life=Base commit doesn't exists any more.", self._repo, commit], check=True) def delete(self, ref:str): assert isinstance(ref, str) - os.remove(os.path.join(self._repo, "refs", "heads", *(ref.split("/")))) + subprocess.run(["ostree", "refs", "--repo", self._repo, "--delete", ref], check=True) if __name__ == "__main__": @@ -84,10 +79,6 @@ if __name__ == "__main__": for j in tmp: target_repo.move_commit(i, j, no_fsync=args.no_fsync, gpg_key=args.gpg, collection=args.collection) - # Create empty - if not args.delete and "empty" not in target_repo.flatpaks: - target_repo.gen_empty() - # Remove old commits_added = set(commits_added) for i in filter(lambda x: x not in commits_added, target_repo.flatpaks): @@ -95,3 +86,7 @@ if __name__ == "__main__": target_repo.delete(i) else: target_repo.make_eol(i, no_fsync=args.no_fsync, gpg_key=args.gpg, collection=args.collection) + + # Update summary and appstream + subprocess.run(["ostree", "summary", "--repo", args.repo, "-u"] + (["--gpg-sign=" + args.gpg] if args.gpg else []), check=True) + subprocess.run(["flatpak", "build-update-repo"] + (["--deploy-collection-id", "--collection-id", args.collection] if args.collection else []) + (["--gpg-sign", args.gpg] if args.gpg else []) + [args.repo], check=True) \ No newline at end of file diff --git a/upload.sh b/upload.sh new file mode 100755 index 0000000..0ecc104 --- /dev/null +++ b/upload.sh @@ -0,0 +1,56 @@ +#! /usr/bin/env bash +# Args: [] [] +ARG_REPO="$1" +ARG_REPO_SOURCE="$2" +ARG_REMOTE="$3" +ARG_REMOTE_PATH="$4" +ARG_GPG="$5" +ARG_COLLECTION="$6" + +# +# Generate +# +if [ -z "$NO_UPDATE" ] +then + REPO=() + FLATPAK=() + if [ -n "$ARG_GPG" ] + then + REPO=( "${REPO[@]}" "--gpg" "$ARG_GPG" ) + FLATPAK=( "${FLATPAK[@]}" "--gpg-sign=$ARG_GPG" ) + fi + if [ -n "$ARG_COLLECTION" ] + then + REPO=( "${REPO[@]}" "-c" "$ARG_COLLECTION" ) + FLATPAK=( "${FLATPAK[@]}" "--collection-id=$ARG_COLLECTION" "--deploy-collection-id" ) + fi + "$(dirname "$0")/update_repo.py" --no-fsync "${REPO[@]}" "$ARG_REPO" "$ARG_REPO_SOURCE" && + flatpak build-update-repo --prune --prune-depth=5 "${FLATPAK[@]}" "$ARG_REPO" +fi && + +# +# Send data +# +if [ -z "$PORT" ] +then + export PORT=8000 +fi && +echo "PORT: $PORT" && +export "LOCK_FILE=$(mktemp)" && +( ( + cd "$ARG_REPO" && + exec python3 -m http.server --bind 127.0.0.1 "$PORT" 2> /dev/null & + SESSION="$!" && + sleep 1 && + exec 200> "$LOCK_FILE" && + flock -x 200 && + kill "$SESSION" && + wait + rm "$LOCK_FILE" +) &) && +( + exec 200> "$LOCK_FILE" && + flock -x 200 && + sleep 10 && + ssh "$ARG_REMOTE" -R"$PORT":127.0.0.1:"$PORT" bash -c \''ostree remote add --force --no-gpg-verify --repo "$0" origin http://127.0.0.1:'"$PORT"'/ && ostree pull --repo "$0" --mirror origin && flatpak build-update-repo --prune --prune-depth=5 --no-update-summary --no-update-appstream --generate-static-deltas "$0" '\' "$ARG_REMOTE_PATH" +) \ No newline at end of file