vpeter

mount_overlay.sh

Oct 27th, 2021
748
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # mount_overlay.sh
  3. echo
  4. dir="$1"
  5.  
  6. if [ -z "$dir" ]; then
  7.   echo "no build folder specified"
  8.   echo "or use <mount/umount> argument"
  9.   echo
  10.   exit 0
  11. fi
  12.  
  13. ##################################################
  14. if [ "$dir" = "mount" -o "$dir" = "umount" ]; then
  15.   for build_folder in build.LibreELEC-* build.CoreELEC-* ; do
  16.     if [ -d "$build_folder" ]; then
  17.       [ "$dir" = "mount" ]  &&          $0 $build_folder
  18.       [ "$dir" = "umount" ] && sudo umount $build_folder
  19.     fi
  20.   done
  21.  
  22.   mount | awk '/build/ { for (i=1; i<=3; i++) printf("%s ", $i); printf("\n") }'
  23.   exit 0
  24. fi
  25.  
  26. ##################################################
  27. if [ "${UID}" -eq 0 ]; then
  28.   echo "dont run as root"
  29.   exit
  30. fi
  31.  
  32. # remove last / from dir
  33. dir_name=$(dirname ${dir})
  34. if [ "$dir_name" = "." ]; then
  35.   # current folder, ignore .
  36.   dir="$(basename ${dir})"
  37. else
  38.   dir="$dir_name/$(basename ${dir})"
  39. fi
  40.  
  41. if [ -z "${dir}" -o ! -d "${dir}" ]; then
  42.   echo "Usage: $0 build_folder"
  43.   exit 1
  44. fi
  45.  
  46. ROOT_PWD=$(pwd)
  47. FULL_PATH=$(readlink -f ${dir})
  48. echo "FULL_PATH: $FULL_PATH"
  49. echo " ROOT_PWD: $ROOT_PWD"
  50. echo "      dir: ${dir}"
  51. echo
  52.  
  53. if [ "$(echo $FULL_PATH | sed "s|$ROOT_PWD/||")" != "${dir}" ]; then
  54.   echo "1) $FULL_PATH"
  55.   echo "2) $ROOT_PWD"
  56.   echo "3) ${dir}"
  57.   echo "Usage: $0 build_folder as in current folder"
  58.   exit 1
  59. fi
  60.  
  61. UPPER_DIR="overlay_build/${dir}-upper"
  62. WORK_DIR="overlay_build/${dir}-work"
  63.  
  64. mkdir -p "${UPPER_DIR}" "${WORK_DIR}"
  65.  
  66. sudo mount -t overlay overlay -olowerdir=${dir},upperdir=${UPPER_DIR},workdir=${WORK_DIR} ${dir}
  67.  
  68. echo
  69. mount | grep ${dir} | sed "s|$ROOT_PWD/||"
  70. echo
  71.  
RAW Paste Data