Skip to content

Commit

Permalink
initial base chroot creation script
Browse files Browse the repository at this point in the history
  • Loading branch information
jpalus committed May 8, 2020
0 parents commit 0fb352a
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
51 changes: 51 additions & 0 deletions base.pkgs
Original file line number Diff line number Diff line change
@@ -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
61 changes: 61 additions & 0 deletions create-chroot.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 0fb352a

Please sign in to comment.