Last active
June 19, 2018 05:27
-
-
Save Arcanemagus/7531f2e682025f22d7b1d7fccf0e32d3 to your computer and use it in GitHub Desktop.
Migrates the fstab entries from a Warden jail to an iocage jail
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 | |
# Enable display of executed commands | |
# set -x | |
JAIL_NAME=$1 | |
BASE_DATASET="${2:-vault}" | |
echo "Preparing to migrate fstab entries from warden to iocage for the" \ | |
"${JAIL_NAME} jail under the ${BASE_DATASET} dataset:" | |
echo "Do you have the power?" | |
sudo echo "I have the power!" | |
if [[ $? == 1 ]] ; then | |
echo "Apparently, you don't have the power." | |
exit 1; | |
fi | |
FSTAB_ENTRIES="/tmp/${JAIL_NAME}.fstab" | |
# Remove the temporary file if it currently exists | |
if [[ -e "${JAIL_NAME}" ]]; then | |
rm -f "${FSTAB_ENTRIES}" | |
fi | |
# Grab the Warden fstab file and make a fixed version of it | |
sed -e "s/\\/mnt\\/${BASE_DATASET}\\/jails\\/${JAIL_NAME}\\///g" < \ | |
"/mnt/${BASE_DATASET}/jails/.${JAIL_NAME}.meta/fstab" | \ | |
sort > "${FSTAB_ENTRIES}" | |
# Read in the lines, preventing backslash escapes (such as "\040") from being interpreted | |
while IFS='' read -r entry || [[ -n "$entry" ]]; do | |
echo "Adding the following entry: ${entry}" | |
# Change the "\040" in the fstab entry back to a space | |
sub_path=$(echo "${entry}" | cut -d" " -f2 | sed -e "s/\\\\040/ /g") | |
new_path="/mnt/iocage/jails/${JAIL_NAME}/root${sub_path}" | |
# Create the target directory | |
sudo mkdir -pv "${new_path}" | |
# Add the mount point | |
sudo iocage fstab --add "${JAIL_NAME}" "${entry}" | |
done < "${FSTAB_ENTRIES}" | |
# Delete the temporary mount entries | |
rm -f "${FSTAB_ENTRIES}" | |
echo "Done migrating fstab entries to the iocage jail." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment