Guest User

Untitled

a guest
Jun 20th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #!/bin/bash
  2. # Enable display of executed commands
  3. # set -x
  4.  
  5. JAIL_NAME=$1
  6. BASE_DATASET="${2:-vault}"
  7.  
  8. echo "Preparing to migrate fstab entries from warden to iocage for the" \
  9. "${JAIL_NAME} jail under the ${BASE_DATASET} dataset:"
  10.  
  11. echo "Do you have the power?"
  12. sudo echo "I have the power!"
  13. if [[ $? == 1 ]] ; then
  14. echo "Apparently, you don't have the power."
  15. exit 1;
  16. fi
  17.  
  18. FSTAB_ENTRIES="/tmp/${JAIL_NAME}.fstab"
  19.  
  20. # Remove the temporary file if it currently exists
  21. if [[ -e "${JAIL_NAME}" ]]; then
  22. rm -f "${FSTAB_ENTRIES}"
  23. fi
  24.  
  25. # Grab the Warden fstab file and make a fixed version of it
  26. sed -e "s/\\/mnt\\/${BASE_DATASET}\\/jails\\/${JAIL_NAME}\\///g" < \
  27. "/mnt/${BASE_DATASET}/jails/.${JAIL_NAME}.meta/fstab" | \
  28. sort > "${FSTAB_ENTRIES}"
  29.  
  30. # Read in the lines, preventing backslash escapes (such as "\040") from being interpreted
  31. while IFS='' read -r entry || [[ -n "$entry" ]]; do
  32. echo "Adding the following entry: ${entry}"
  33. # Change the "\040" in the fstab entry back to a space
  34. sub_path=$(echo "${entry}" | cut -d" " -f2 | sed -e "s/\\\\040/ /g")
  35. new_path="/mnt/iocage/jails/${JAIL_NAME}/root${sub_path}"
  36. # Create the target directory
  37. sudo mkdir -pv "${new_path}"
  38. # Add the mount point
  39. sudo iocage fstab --add "${JAIL_NAME}" "${entry}"
  40. done < "${FSTAB_ENTRIES}"
  41.  
  42. # Delete the temporary mount entries
  43. rm -f "${FSTAB_ENTRIES}"
  44.  
  45. echo "Done migrating fstab entries to the iocage jail."
Add Comment
Please, Sign In to add comment