master ohmu/fastfetch-openbsd / debian / publish.sh
ohmu  ·  2026-10-15
 1#!/usr/bin/env bash
 2# WARNING: DO NOT RUN THIS SCRIPT UNLESS YOU KNOW WHAT YOU ARE DOING.
 3
 4set -euo pipefail
 5
 6command -v debuild >/dev/null 2>&1 || { echo "debuild not found. Install devscripts." >&2; exit 1; }
 7command -v dput >/dev/null 2>&1 || { echo "dput not found." >&2; exit 1; }
 8
 9SCRIPT_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
10ROOT_DIR="$(cd -- "$SCRIPT_DIR/.." >/dev/null 2>&1 && pwd)"
11OUT_DIR="$(dirname "$ROOT_DIR")"
12PPA="ppa:zhangsongcui3371/fastfetch"
13CODENAMES=( jammy noble plucky questing resolute stonking )
14DRY_RUN=0
15
16if [[ -d "$OUT_DIR/build" ]]; then
17    echo "Output directory exists: $OUT_DIR/build" >&2
18    echo "Please move or delete it before proceeding." >&2
19    exit 1
20fi
21
22TEMPLATE="$ROOT_DIR/debian/changelog.tpl"
23CHANGELOG_DEBIAN="$ROOT_DIR/debian/changelog"
24
25if [[ ! -f "$TEMPLATE" ]]; then
26  echo "Template not found: $TEMPLATE" >&2
27  exit 1
28fi
29
30if ! grep -q '#UBUNTU_CODENAME#' "$TEMPLATE"; then
31  echo "Template missing placeholder: #UBUNTU_CODENAME#" >&2
32  exit 1
33fi
34
35echo "IMPORTANT: Before proceeding, please ensure that 'debian/changelog.tpl' is up-to-date"
36echo "   with the correct version number, release notes, and maintainer information."
37echo
38echo "   The template must contain a placeholder like '#UBUNTU_CODENAME#' for the codename."
39echo
40read -p "Have you reviewed and updated 'debian/changelog.tpl'? (y/N): " -r
41echo
42if [[ ! $REPLY =~ ^[Yy]$ ]]; then
43    exit 1
44fi
45
46cleanup() {
47    rm -f "$CHANGELOG_DEBIAN"
48    rm -f "$ROOT_DIR/debian/files"
49}
50trap cleanup EXIT
51
52shopt -s nullglob
53
54for codename in "${CODENAMES[@]}"; do
55  echo "==> Publishing distro: $codename"
56  sed "s/#UBUNTU_CODENAME#/${codename}/g" "$TEMPLATE" > "$CHANGELOG_DEBIAN"
57
58  ( cd "$ROOT_DIR" && debuild -S -i -I )
59
60  changes=( "$OUT_DIR"/fastfetch_*~${codename}_source.changes )
61  if [[ ${#changes[@]} -ne 1 ]]; then
62    echo "Unable to uniquely identify .changes for '$codename' in: $OUT_DIR" >&2
63    printf 'Found:\n'; printf '  %s\n' "${changes[@]}" >&2 || true
64    exit 1
65  fi
66
67  if [[ $DRY_RUN -eq 1 ]]; then
68    echo "[DRY-RUN] dput \"$PPA\" \"${changes[0]}\""
69  else
70    dput "$PPA" "${changes[0]}"
71  fi
72
73  rm -f "$OUT_DIR"/fastfetch_*~${codename}_source.{changes,dsc,tar.*}
74
75  echo "<== Done: $codename"
76done