From 0fb352a68c6b60b43df8e61c795c49402e2d1e28 Mon Sep 17 00:00:00 2001 From: Jan Palus Date: Fri, 8 May 2020 19:39:32 +0200 Subject: [PATCH] initial base chroot creation script --- base.pkgs | 51 ++++++++++++++++++++++++++++++++++++++++ create-chroot.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 base.pkgs create mode 100755 create-chroot.sh diff --git a/base.pkgs b/base.pkgs new file mode 100644 index 0000000..48ac676 --- /dev/null +++ b/base.pkgs @@ -0,0 +1,51 @@ +bash +bc +bind-utils +bzip2 +coreutils +cpio +cryptsetup +dhcp-client +e2fsprogs +file +findutils +gawk +grep +gzip +htop +iproute2 +iputils +less +lftp +lvm2 +lz4 +lzo +mawk +mksh +openssh-clients +openssh-server +ping +poldek +rpm +rsync +sed +setup +shadow +strace +sudo +systemd +systemd-init +tar +the_silver_searcher +time +tmux +unrar +unzip +util-linux +vim +vim-rt +wget +which +xz +zsh +zstd diff --git a/create-chroot.sh b/create-chroot.sh new file mode 100755 index 0000000..47f0400 --- /dev/null +++ b/create-chroot.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +log() { + echo "$@" >> "$LOG_FILE" +} + +error() { + echo "ERROR: $*" | tee -a "$LOG_FILE" >&2 + exit 1 +} + +run_log() { + local msg="$1"; shift + log "Running $@" + echo -n "$msg..." + "$@" >> "$LOG_FILE" 2>&1 + if [ $? -eq 0 ]; then + echo "OK" + else + echo "FAILED" + error "Command failed: $@" + fi +} + +run_log_priv() { + local msg="$1"; shift + run_log "$msg" $SUDO "$@" +} + +if [ "$EUID" != "0" ]; then + echo "Non-root user detected, using sudo" + SUDO="sudo" +fi + + +SCRIPT_DIR=$(dirname $(readlink -f "$0")) +TIMESTAMP=$(date +%Y%m%d) +RELEASE_NAME="pld-linux-base-aarch64-$TIMESTAMP" +LOG_FILE="$SCRIPT_DIR/$RELEASE_NAME.log" +echo "Creating release $RELEASE_NAME" + +CHROOT_DIR="$(mktemp -t -d $RELEASE_NAME.XXXXXXXXXX)" +if [ $? -ne 0 ]; then + error 'failed to create temporary chroot directory' +fi + +: > "$LOG_FILE" +echo "Logging to $LOG_FILE" + +run_log_priv "Setting up temporary chroot in $CHROOT_DIR" rpm --initdb --root "$CHROOT_DIR" +run_log_priv "Installing packages from $SCRIPT_DIR/base.pkgs" poldek -iv --pset="$SCRIPT_DIR/base.pkgs" --root="$CHROOT_DIR" --noask +run_log_priv "Adjusting poldek repository configuration" sed -i -e '/^_prefix = / a _aarch64_prefix = http://jpalus.fastmail.com.user.fm/dists/th' -e 's|%{_prefix}/PLD/%{_arch}/RPMS|%{_aarch64_prefix}/PLD/%{_arch}/RPMS|' "$CHROOT_DIR/etc/poldek/repos.d/pld.conf" +rpm --root="$CHROOT_DIR" -qa|sort > "$SCRIPT_DIR/$RELEASE_NAME.packages" +run_log_priv "Creating archive $SCRIPT_DIR/$RELEASE_NAME.tar.xz" tar -Jcpf "$SCRIPT_DIR/$RELEASE_NAME.tar.xz" -C "$CHROOT_DIR" . + +if [ "$EUID" != "0" ]; then + run_log_priv "Changing ownership of $RELEASE_NAME.tar.xz" chown $USER "$SCRIPT_DIR/$RELEASE_NAME.tar.xz" +fi + +run_log 'Signing' gpg --sign --armor --detach-sig "$SCRIPT_DIR/$RELEASE_NAME.tar.xz" +run_log_priv 'Cleaning up' rm -rf "$CHROOT_DIR"