Created
April 27, 2014 01:58
-
-
Save likewhoa/11335918 to your computer and use it in GitHub Desktop.
A script that allows you to chroot into a failed catalyst environment to fix errors manually.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Help menu | |
print_help() { | |
cat <<-HELP | |
Arguments: | |
--spec - --spec=stage1.spec (default) | |
--config - --config=/etc/catalyst.conf (default) | |
HELP | |
exit 0 | |
} | |
# Parse Command Line Arguments | |
while [ $# -gt 0 ]; do | |
case "$1" in | |
--config=*) | |
# The catalyst.conf | |
config="${1#*=}" | |
;; | |
--spec=*) | |
# The spec file i.e stage1.spec | |
spec="${1#*=}" | |
;; | |
--help|-h) | |
print_help | |
;; | |
*) | |
echo "Invalid argument given!"; exit | |
esac | |
shift | |
done | |
main() { | |
# Config specific paths | |
config="${config:-/etc/catalyst.conf}" | |
storedir="$(grep storedir\= ${config} |cut -d\" -f2)" | |
snapshot_cache="$(grep snapshot_cache\= ${config} |cut -d\" -f2)" | |
# Spec specific values | |
spec="${spec:-stage1.spec}" | |
subarch="$(awk '/subarch/ {print $2}' ${spec:-stage1.spec})" | |
target="$(awk '/target/ {print $2}' ${spec:-stage1.spec})" | |
version_stamp="$(awk '/version_stamp/ {print $2}' ${spec:-stage1.spec})" | |
rel_type="$(awk '/rel_type/ {print $2}' ${spec:-stage1.spec})" | |
snapshot="$(awk '/snapshot/ {print $2}' ${spec:-stage1.spec})" | |
source_subpath="${target}-${subarch}-${version_stamp}" | |
if ! [ -d "${snapshot_cache}/${snapshot}" ]; then | |
echo "Snapshot directory ${snapshot} is invalid!" | |
exit | |
fi | |
echo "Entering ${subarch} FAILDebug Catalyst Chroot" | |
# Mount filesystems | |
mount -t proc none ${storedir}/tmp/${rel_type}/${source_subpath}/proc | |
mount -o bind /dev ${storedir}/tmp/${rel_type}/${source_subpath}/dev | |
mount -t tmpfs shm ${storedir}/tmp/${rel_type}/${source_subpath}/dev/shm | |
mount -t sysfs none ${storedir}/tmp/${rel_type}/${source_subpath}/sys | |
# Check to see we have a /usr/portage directory | |
if ! [ -d ${storedir}/tmp/${rel_type}/${source_subpath}/usr/portage ]; then | |
mkdir -p ${storedir}/tmp/${rel_type}/${source_subpath}/usr/portage | |
fi | |
# bind /usr/portage/* | |
mount -o bind ${snapshot_cache}/${snapshot}/portage \ | |
${storedir}/tmp/${rel_type}/${source_subpath}/usr/portage | |
mount -o bind ${storedir}/packages/${rel_type}/${source_subpath} \ | |
${storedir}/tmp/${rel_type}/${source_subpath}/usr/portage/packages | |
# Start chroot | |
if [ ${subarch} = amd64 ]; then | |
linux64 chroot ${storedir}/tmp/${rel_type}/${source_subpath} /bin/bash | |
else | |
linux32 chroot ${storedir}/tmp/${rel_type}/${source_subpath} /bin/bash | |
fi | |
echo "Exiting ECatalyst Chroot!" | |
echo "Umount packages" | |
umount ${storedir}/tmp/${rel_type}/${source_subpath}/usr/portage/packages | |
echo "Umounting syfs,proc,dev,dev/shm & usr/portage" | |
umount ${storedir}/tmp/${rel_type}/${source_subpath}/{dev/shm,dev,sys,proc,usr/portage} | |
echo "All done!" | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment