From fe22cde6616c8aecf01a082ff680ae5525685a2b Mon Sep 17 00:00:00 2001 From: tuxwarrior Date: Fri, 3 May 2024 12:54:25 -0500 Subject: [PATCH] + syncDirSetup.sh --- dots/bin/syncDirSetup.sh | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 dots/bin/syncDirSetup.sh diff --git a/dots/bin/syncDirSetup.sh b/dots/bin/syncDirSetup.sh new file mode 100755 index 0000000..e098ed0 --- /dev/null +++ b/dots/bin/syncDirSetup.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +# klevstul :: 24.04 + +this_file_name=`basename "$0"` +echo ":: $this_file_name :: [K] ::" + +src_dir=${SYNCDIR}_${HOSTNAME} +trg_dir=~/syncDir + +echo +echo "\$src_dir: ${src_dir}" +echo "\$trg_dir: ${trg_dir}" +echo + +if [[ "${src_dir}" == "" ]]; then + echo "environment variable SYNCDIR_${HOSTNAME} is not set." + echo "" + echo "do you want to manually input the sync dir path instead? (y/n)" + read user_input + + if [[ ${user_input} == "y" ]]; then + echo "enter the full path to the sync directory:" + read user_input + src_dir=${user_input} + else + echo "set SYNCDIR, then re-run this script." >&2; exit 1 + fi +fi + +if [[ "${src_dir}" == "${trg_dir}" ]]; then + echo "src == trg. there is nothing to do. bye!" >&2; exit 1 +fi + +if ! [[ -d ${src_dir} ]]; then + echo "creating non-existing source directory '${src_dir}'" + mkdir -p ${src_dir} +fi + +if ! [[ -d ${trg_dir} ]]; then + echo "creating non-existing target directory '${trg_dir}'." + mkdir -p ${trg_dir} +fi + +if mount | grep ${trg_dir} > /dev/null; then + echo "${trg_dir} is already mounted." + echo "if you want to unmount this directory, please run:" + echo "umount ${trg_dir}" +else + echo "mounting source '${src_dir}' to target '${trg_dir}'." + + # example command: + # sudo mount -o bind --source /media/drive2/nass/lo/pCloudSync --target ~/pCloudSync + sudo mount -o bind --source ${src_dir} --target ${trg_dir} + + du --human-readable --max-depth=1 ${trg_dir} +fi + +echo