Browse Source

add README.md + users to quadlet archive

main
Nicolas Massé 2 weeks ago
parent
commit
288df2c76d
  1. 1
      scripts/common.mk
  2. 72
      scripts/generate-tarball.sh

1
scripts/common.mk

@ -373,6 +373,7 @@ build/$(PROJECT_NAME).tar.gz build/$(PROJECT_NAME).bu build/$(PROJECT_NAME)-exam
build/$(PROJECT_NAME).tar.gz build/$(PROJECT_NAME).bu build/$(PROJECT_NAME)-examples.bu: export SYSTEMD_START_UNITS := $(SYSTEMD_START_UNITS)
build/$(PROJECT_NAME).tar.gz build/$(PROJECT_NAME).bu build/$(PROJECT_NAME)-examples.bu: export SYSTEMD_TIMER_NAMES := $(SYSTEMD_TIMER_NAMES)
build/$(PROJECT_NAME).tar.gz build/$(PROJECT_NAME).bu build/$(PROJECT_NAME)-examples.bu: export DIRECT_DEPENDENCIES := $(DEPENDENCIES)
build/$(PROJECT_NAME).tar.gz build/$(PROJECT_NAME).bu build/$(PROJECT_NAME)-examples.bu: export PROJECT_USER := $(PROJECT_NAME) $(PROJECT_UID) $(PROJECT_GID) /var/lib/quadlets/$(PROJECT_NAME)
build/$(PROJECT_NAME).tar.gz build/$(PROJECT_NAME).bu build/$(PROJECT_NAME)-examples.bu &:
@if [ -z "$(TARGET_CHROOT)" ]; then \
echo "TARGET_CHROOT is not set!"; exit 1; \

72
scripts/generate-tarball.sh

@ -32,7 +32,7 @@ trap 'rm -rf "$tmp_dir"' EXIT
# Generate the file list from the TARGET_CHROOT, excluding files and directories in the BUTANE_BLOCKLIST
declare -A files_to_include=()
filelist_file="$tmp_dir/filelist.txt"
inner_filelist_file="$tmp_dir/filelist.txt"
for path in $(find "$TARGET_CHROOT"); do
rel_path="${path#$TARGET_CHROOT}"
# Skip files & directories that are already part of the CoreOS default installation
@ -46,7 +46,7 @@ for path in $(find "$TARGET_CHROOT"); do
fi
# The leading / is removed from the relative path in order for tar to find the file.
echo "${rel_path#/}" >> "$filelist_file"
echo "${rel_path#/}" >> "$inner_filelist_file"
# Although, the absolute path is stored in the metadata file.
files_to_include["$rel_path"]="$(stat --format='%u %g %a %F' "$path")"
@ -54,27 +54,28 @@ done
# Generate metadata.json
metadata_file="$tmp_dir/metadata.yaml"
cat <<EOF > "$metadata_file"
exec 3>&1 > "$metadata_file"
cat <<EOF
name: $PROJECT_NAME
EOF
if [ -n "${ALL_DEPENDENCIES}" ]; then
echo "dependencies:" >> "$metadata_file"
echo "dependencies:"
for dep in ${ALL_DEPENDENCIES};
do echo "- $dep"
done >> "$metadata_file"
done
else
echo "dependencies: []" >> "$metadata_file"
echo "dependencies: []"
fi
if [ -n "${DIRECT_DEPENDENCIES}" ]; then
echo "direct_dependencies:" >> "$metadata_file"
echo "direct_dependencies:"
for dep in ${DIRECT_DEPENDENCIES};
do echo "- $dep"
done >> "$metadata_file"
done
else
echo "direct_dependencies: []" >> "$metadata_file"
echo "direct_dependencies: []"
fi
if [ "${#files_to_include[@]}" -gt 0 ]; then
echo "files:" >> "$metadata_file"
echo "files:"
for file in "${!files_to_include[@]}"; do
read -r owner group mode type <<< "${files_to_include[$file]}"
if [ "$type" == "directory" ]; then
@ -82,7 +83,7 @@ if [ "${#files_to_include[@]}" -gt 0 ]; then
elif [ "$type" == "regular file" ]; then
type="file"
else
echo "Unsupported file type: $type for file $file"
echo "Unsupported file type: $type for file $file" >&2
exit 1
fi
cat <<EOY
@ -92,29 +93,57 @@ if [ "${#files_to_include[@]}" -gt 0 ]; then
mode: "0$mode"
type: $type
EOY
done >> "$metadata_file"
done
else
echo "files: []" >> "$metadata_file"
echo "files: []"
fi
if [ -n "${SYSTEMD_START_UNITS}" ]; then
echo "systemd_start_units:" >> "$metadata_file"
echo "systemd_start_units:"
for unit in ${SYSTEMD_START_UNITS}; do
echo "- $unit"
done >> "$metadata_file"
done
else
echo "systemd_start_units: []" >> "$metadata_file"
echo "systemd_start_units: []"
fi
if [ -n "${SYSTEMD_ENABLE_UNITS}" ]; then
echo "systemd_enable_units:" >> "$metadata_file"
echo "systemd_enable_units:"
for unit in ${SYSTEMD_ENABLE_UNITS}; do
echo "- $unit"
done >> "$metadata_file"
done
else
echo "systemd_enable_units: []"
fi
if [ -n "${PROJECT_USER}" ]; then
read -r username uid gid home <<< "${PROJECT_USER}"
if [ "$uid" -ne 0 ] && [ "$gid" -ne 0 ]; then
echo "users:"
echo "- name: $username"
echo " uid: $uid"
echo " gid: $gid"
echo " home: $home"
else
echo "systemd_enable_units: []" >> "$metadata_file"
echo "users: []"
fi
else
echo "users: []"
fi
# Restore stdout
exec 1>&3
# The list of files to be included in the outer tarball.
declare -a outer_filelist=(
"metadata.json"
)
# Convert metadata.yaml to metadata.json
yq -o json "$metadata_file" > "$tmp_dir/metadata.json"
# Add the project's README file to the tarball if it exists.
if [ -f "README.md" ]; then
cp "README.md" "$tmp_dir/README.md"
outer_filelist+=("README.md")
fi
# Common tar options to ensure that the tarball is reproducible and does not contain unnecessary metadata
declare -a tar_options=(
"--no-selinux"
@ -124,7 +153,8 @@ declare -a tar_options=(
)
# Generate content.tar with the files to be included in the tarball, preserving their relative paths and permissions.
tar -cf "$tmp_dir/content.tar" "${tar_options[@]}" -C "$TARGET_CHROOT" --verbatim-files-from --files-from="$filelist_file"
tar -cf "$tmp_dir/content.tar" "${tar_options[@]}" -C "$TARGET_CHROOT" --verbatim-files-from --files-from="$inner_filelist_file"
outer_filelist+=("content.tar")
# Generate the final tarball.
tar -czf "$1" "${tar_options[@]}" -C "$tmp_dir" --owner=0 --group=0 metadata.json content.tar
tar -czf "$1" "${tar_options[@]}" -C "$tmp_dir" --owner=0 --group=0 "${outer_filelist[@]}"

Loading…
Cancel
Save