-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathbuild-packages
More file actions
executable file
·138 lines (110 loc) · 4.04 KB
/
build-packages
File metadata and controls
executable file
·138 lines (110 loc) · 4.04 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
#!/usr/bin/env bash
set -e
: "${HELPER_PACKAGES_DIR:=/var/lib/pi-gen-micro/helper-packages}"
: "${PACKAGES_DIR:=/var/lib/pi-gen-micro/internal/packages}"
usage() {
cat <<EOF
Usage: $(basename "$0") [options] [package_dir ...]
Build helper .deb packages from control/install definitions and
regenerate the local package index.
With no arguments, rebuilds all packages found under HELPER_PACKAGES_DIR.
With arguments, builds only the specified package directories.
Options:
-h, --help Show this help message
-n, --dry-run Show what would be built without building
Environment variables:
HELPER_PACKAGES_DIR Path to helper package sources (default: /var/lib/pi-gen-micro/helper-packages)
PACKAGES_DIR Output directory for .deb files (default: /var/lib/pi-gen-micro/internal/packages)
Examples:
$(basename "$0") # rebuild all
$(basename "$0") cryptroot # rebuild just cryptroot
$(basename "$0") cryptroot ssh-service # rebuild specific packages
To list available packages with descriptions, use:
pi-gen-micro --list-packages
EOF
exit 0
}
list_package_names() {
find "${HELPER_PACKAGES_DIR}" -maxdepth 2 -name control -printf '%h\n' | sort | while read -r dir; do
printf " %s\n" "$(basename "$dir")"
done
}
DRY_RUN=0
TARGETS=()
while [ $# -gt 0 ]; do
case "$1" in
-h|--help) usage ;;
-n|--dry-run) DRY_RUN=1; shift ;;
-*) echo "Unknown option: $1" >&2; exit 1 ;;
*) TARGETS+=("$1"); shift ;;
esac
done
# Find package directories to build
PACKAGE_DIRS=()
if [ ${#TARGETS[@]} -eq 0 ]; then
while IFS= read -r dir; do
PACKAGE_DIRS+=("$dir")
done < <(find "${HELPER_PACKAGES_DIR}" -maxdepth 2 -name control -printf '%h\n' | sort)
else
for target in "${TARGETS[@]}"; do
target="${target%/}"
dir="${HELPER_PACKAGES_DIR}/${target}"
if [ ! -f "${dir}/control" ]; then
echo "Error: No control file found in ${target}/" >&2
echo "Available packages:" >&2
list_package_names >&2
exit 1
fi
PACKAGE_DIRS+=("$dir")
done
fi
if [ ${#PACKAGE_DIRS[@]} -eq 0 ]; then
echo "No packages found to build." >&2
exit 1
fi
mkdir -p "${PACKAGES_DIR}"
for dir in "${PACKAGE_DIRS[@]}"; do
name="$(basename "$dir")"
pkg_name="$(sed -n 's/^Package: *//p' "$dir/control")"
version="$(dpkg-parsechangelog -l "$dir/changelog" -S Version)"
arch="$(sed -n 's/^Architecture: *//p' "$dir/control")"
if [ "$DRY_RUN" -eq 1 ]; then
echo "[dry-run] Would build: ${pkg_name}_${version}_${arch}.deb from ${name}/"
continue
fi
echo "Building ${pkg_name} ${version} from ${name}/"
# Remove any previous version of this package
rm -f "${PACKAGES_DIR}/${pkg_name}_"*".deb"
# Create staging directory
staging="$(mktemp -d)"
mkdir -p "$staging/DEBIAN"
# Inject version from changelog into control
sed "1a\\
Version: ${version}" "$dir/control" > "$staging/DEBIAN/control"
# Process install manifest: <src> <dest-dir> <mode>
while read -r src dest mode; do
[ -z "$src" ] && continue
mkdir -p "$staging$dest"
cp "$dir/$src" "$staging$dest/$src"
chmod "${mode:-0644}" "$staging$dest/$src"
done < "$dir/install"
# Process symlinks: <target> <link-path>
if [ -f "$dir/links" ]; then
while read -r target link_path; do
[ -z "$target" ] && continue
mkdir -p "$staging$(dirname "$link_path")"
ln -s "$target" "$staging$link_path"
done < "$dir/links"
fi
dpkg-deb --root-owner-group --build "$staging" \
"${PACKAGES_DIR}/${pkg_name}_${version}_${arch}.deb"
rm -rf "$staging"
done
if [ "$DRY_RUN" -eq 1 ]; then
echo "[dry-run] Would regenerate ${PACKAGES_DIR}/Packages.gz"
exit 0
fi
echo "Regenerating package index..."
(cd "${PACKAGES_DIR}" && dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz)
echo "Done. Packages in ${PACKAGES_DIR}/:"
find "${PACKAGES_DIR}" -maxdepth 1 -name '*.deb' -printf ' %f\n' | sort