2024-06-10 12:29:46 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
# klevstul :: 24.06
|
|
|
|
|
|
|
|
|
|
this_file_name=`basename "$0"`
|
|
|
|
|
if [ $# -lt 1 ]; then
|
|
|
|
|
echo "error: path to file is missing."
|
|
|
|
|
echo "usage: '$this_file_name [path_to_file]'"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
input_file=$1
|
|
|
|
|
|
|
|
|
|
sync_dir_sym=/home/${USER}/syncDir
|
|
|
|
|
syncdir_env_var=SYNCDIR_${HOSTNAME}
|
|
|
|
|
sync_dir=${!syncdir_env_var} # '!' to use the name and not the value
|
2024-06-10 12:55:05 -05:00
|
|
|
cwd=$(pwd)
|
2024-06-10 12:29:46 -05:00
|
|
|
|
|
|
|
|
#echo ${input_file}
|
|
|
|
|
#echo ${sync_dir_sym}
|
|
|
|
|
#echo ${sync_dir}
|
2024-06-10 12:55:05 -05:00
|
|
|
#echo ${cwd}
|
|
|
|
|
|
|
|
|
|
# if input file has not path specified
|
|
|
|
|
if [[ ${input_file} != *"/"* ]]; then
|
|
|
|
|
input_file=${cwd}/${input_file}
|
|
|
|
|
fi
|
2024-06-10 12:29:46 -05:00
|
|
|
|
|
|
|
|
# substitute parts of the old path, from using the symlink folder, to the non-symlink folder
|
|
|
|
|
# example:
|
|
|
|
|
# "/home/poq/syncDir/0_downloads/topBanner.jpg" > "/home/poq/nextcloud/syncDir/0_downloads/topBanner.jpg"
|
|
|
|
|
#
|
2024-06-10 12:55:05 -05:00
|
|
|
# please note, if a file outside of the sync directory is tp'ed, then the replacement will not happen.
|
|
|
|
|
# this is great, as trash-put should work normally outside of the sync-dir. and for files residing outside,
|
|
|
|
|
# no replacemant should be done.
|
|
|
|
|
#
|
2024-06-10 12:29:46 -05:00
|
|
|
# new_file=${original_string//old_substring/new_substring}
|
|
|
|
|
new_file=${input_file//$sync_dir_sym/$sync_dir}
|
|
|
|
|
|
2024-06-10 12:55:05 -05:00
|
|
|
if [[ -f ${new_file} ]] || [[ -d ${new_file} ]] ; then
|
|
|
|
|
echo ${new_file}
|
2024-06-10 12:29:46 -05:00
|
|
|
fi
|