Skip to content

Instantly share code, notes, and snippets.

@greyltc
Last active November 14, 2023 17:49
Show Gist options
  • Save greyltc/d17802b7ed5ba0c56146b17497c9cb8e to your computer and use it in GitHub Desktop.
Save greyltc/d17802b7ed5ba0c56146b17497c9cb8e to your computer and use it in GitHub Desktop.
mkarchroot as if it was run on a given date (by using the Arch Linux Archive)
#!/usr/bin/env bash
#bash <(curl -sL https://gist.github.com/greyltc/d17802b7ed5ba0c56146b17497c9cb8e/raw) 2020-01-01 base-devel vim
TRAVEL_TO="${1}" # 2020-01-01, for example
PACKAGES="${@:2}"
TIMETRAVEL_ROOT="timetravel_${TRAVEL_TO}"
#sudo rm -rf "${TIMETRAVEL_ROOT}"
mkdir -p "${TIMETRAVEL_ROOT}"
# we need pacman.conf from the right day
git clone https://gitlab.archlinux.org/pacman/pacman.git "${TIMETRAVEL_ROOT}/pacman"
PACMAN_GIT_AGE=$(git -C "${TIMETRAVEL_ROOT}/pacman" rev-parse --until=${TRAVEL_TO})
PACMAN_GIT_REV=$(git -C "${TIMETRAVEL_ROOT}/pacman" rev-list -1 ${PACMAN_GIT_AGE} master)
git -C "${TIMETRAVEL_ROOT}/pacman" reset --hard ${PACMAN_GIT_REV}
cp "${TIMETRAVEL_ROOT}/pacman/etc/pacman.conf.in" "${TIMETRAVEL_ROOT}/pacman.conf"
# now we can mod the pacman.conf for timetravelling
sed 's,^#SigLevel.*,SigLevel = Never,' -i "${TIMETRAVEL_ROOT}/pacman.conf"
echo "[core]" >> "$(readlink -f ${TIMETRAVEL_ROOT}/pacman.conf)"
echo "Server=https://archive.archlinux.org/repos/${TRAVEL_TO//-//}/\$repo/os/\$arch" >> "${TIMETRAVEL_ROOT}/pacman.conf"
echo "[extra]" >> "$(readlink -f ${TIMETRAVEL_ROOT}/pacman.conf)"
echo "Server=https://archive.archlinux.org/repos/${TRAVEL_TO//-//}/\$repo/os/\$arch" >> "${TIMETRAVEL_ROOT}/pacman.conf"
echo "[community]" >> "$(readlink -f ${TIMETRAVEL_ROOT}/pacman.conf)"
echo "Server=https://archive.archlinux.org/repos/${TRAVEL_TO//-//}/\$repo/os/\$arch" >> "${TIMETRAVEL_ROOT}/pacman.conf"
mkarchroot -C "${TIMETRAVEL_ROOT}/pacman.conf" "${TIMETRAVEL_ROOT}"/root ${PACKAGES}
echo -e "You might\narch-nspawn $(readlink -f ${TIMETRAVEL_ROOT}/root)\nor\nmakechrootpkg -c -r $(readlink -f ${TIMETRAVEL_ROOT})"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment