/ de-omarchy / bin / omarchy-dev-pkg-test
swadhinbiswas Initial de-omarchy: Omarchy UI layer for Arch-based distros · 8/22/2026
9f393b2
138 lines · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash

# omarchy:summary=Build and install an Omarchy package from a local checkout
# omarchy:group=dev
# omarchy:args=[package-name] [path-to-checkout]
# omarchy:examples=omarchy dev pkg-test | omarchy dev pkg-test omarchy-dev ~/Work/omarchy/omarchy-installer

set -euo pipefail

if [[ ${1:-} == "-h" || ${1:-} == "--help" ]]; then
  cat <<USAGE
Usage: omarchy dev pkg-test [package-name] [path-to-checkout]

Builds and installs an Omarchy package from a local Omarchy source
checkout. Use when changes need to land at fixed system paths (/etc/,
/usr/lib/systemd/, udev rule bodies, plymouth) that omarchy-dev-link
can't shadow.

Defaults:
  packages          omarchy-settings-dev omarchy-dev
  path-to-checkout  ~/Work/omarchy/omarchy-installer

Examples:
  omarchy dev pkg-test
  omarchy dev pkg-test omarchy-settings-dev
  omarchy dev pkg-test omarchy-dev ~/Work/omarchy/omarchy-installer

The pkgver of the built package is tagged 'dev.<short-sha>[.dirty]' so
'pacman -Q' makes it obvious where the installed version came from.

PKGBUILDs are read from \${OMARCHY_PKGBUILDS_DIR:-~/Work/omarchy/omarchy-pkgs/pkgbuilds}/<package-name>/.
USAGE
  exit 0
fi

remove_pkgver_function() {
  local pkgbuild="$1"
  local tmp="$pkgbuild.tmp"

  awk '
    /^pkgver\(\)[[:space:]]*\{/ {
      in_pkgver = 1
      depth = 0
    }
    in_pkgver {
      line = $0
      opens = gsub(/\{/, "{", line)
      line = $0
      closes = gsub(/\}/, "}", line)
      depth += opens - closes
      if (depth <= 0) {
        in_pkgver = 0
      }
      next
    }
    { print }
  ' "$pkgbuild" >"$tmp"
  mv "$tmp" "$pkgbuild"
}

dev_package_name() {
  local pkg="$1"

  case "$pkg" in
    omarchy | omarchy-settings)
      printf '%s-dev\n' "$pkg"
      ;;
    *)
      printf '%s\n' "$pkg"
      ;;
  esac
}

if (( $# == 0 )); then
  PKGS=(omarchy-settings-dev omarchy-dev)
  CHECKOUT="$HOME/Work/omarchy/omarchy-installer"
  MAKEPKG_ARGS=()
else
  PKGS=("$(dev_package_name "$1")")
  CHECKOUT="${2:-$HOME/Work/omarchy/omarchy-installer}"
  MAKEPKG_ARGS=("${@:3}")
fi
PKGBUILDS_ROOT="${OMARCHY_PKGBUILDS_DIR:-$HOME/Work/omarchy/omarchy-pkgs/pkgbuilds}"

if [[ ! -d "$CHECKOUT" ]]; then
  echo "Error: checkout not found at $CHECKOUT" >&2
  exit 1
fi
for PKG in "${PKGS[@]}"; do
  PKGBUILD_DIR="$PKGBUILDS_ROOT/$PKG"
  if [[ ! -f "$PKGBUILD_DIR/PKGBUILD" ]]; then
    echo "Error: PKGBUILD not found at $PKGBUILD_DIR/PKGBUILD" >&2
    echo "       Pass a different package name as arg 1, or set OMARCHY_PKGBUILDS_DIR." >&2
    exit 1
  fi
done

build_dir=$(mktemp -d -t omarchy-dev-pkg-test.XXXXXX)
trap 'rm -rf "$build_dir"' EXIT

# pkgver=dev.<sha>[.dirty] so pacman -Q makes the source obvious.
short_sha=$(git -C "$CHECKOUT" rev-parse --short HEAD 2>/dev/null || echo "local")
dirty=""
if [[ -d "$CHECKOUT/.git" ]] && [[ -n "$(git -C "$CHECKOUT" status --porcelain)" ]]; then
  dirty=".dirty"
fi
new_pkgver="dev.${short_sha}${dirty}"

for PKG in "${PKGS[@]}"; do
  PKGBUILD_DIR="$PKGBUILDS_ROOT/$PKG"
  package_build_dir="$build_dir/$PKG"
  mkdir -p "$package_build_dir"
  cp -a "$PKGBUILD_DIR/." "$package_build_dir/"

  remove_pkgver_function "$package_build_dir/PKGBUILD"
  sed -i "s/^pkgver=.*/pkgver=${new_pkgver}/" "$package_build_dir/PKGBUILD"

  echo "Building $PKG ${new_pkgver} from $CHECKOUT"
  echo "  build dir: $package_build_dir"
  echo "  PKGBUILD : $PKGBUILD_DIR/PKGBUILD"
  echo

  (
    cd "$package_build_dir"
    OMARCHY_SRC="$CHECKOUT" makepkg -s --skipchecksums --noconfirm "${MAKEPKG_ARGS[@]}"
  )

  # Install separately so we can pass --overwrite='*' (makepkg -i can't).
  # Dev builds frequently conflict with files left behind by previous
  # script-installed Omarchy versions; the build is the authoritative state.
  built_pkg=$(ls -t "$package_build_dir"/*.pkg.tar.* 2>/dev/null | grep -v '\.sig$' | head -1)
  if [[ -z $built_pkg ]]; then
    echo "Error: no built package found in $package_build_dir" >&2
    exit 1
  fi
  sudo pacman -U --noconfirm --overwrite='*' "$built_pkg"
done