Review shell scripts
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -1,38 +1,38 @@
|
||||
echo "Stopping impermanence mount with source: ${source}, target: ${target}, path: ${path}."
|
||||
echo "Stopping impermanence mount with source: $source, target: $target, path: $path."
|
||||
|
||||
source_current="${source}"
|
||||
target_current="${target}"
|
||||
source_current="$source"
|
||||
target_current="$target"
|
||||
|
||||
IFS='/' read -ra path_parts <<< "${path}"
|
||||
IFS='/' read -ra path_parts <<< "$path"
|
||||
unset "path_parts[-1]"
|
||||
|
||||
for part in "${path_parts[@]}"; do
|
||||
source_current="${source_current}/${part}"
|
||||
target_current="${target_current}/${part}"
|
||||
source_current="$source_current/$part"
|
||||
target_current="$target_current/$part"
|
||||
|
||||
if [[ ! -d "${target_current}" ]]; then
|
||||
if [[ ! -d "$target_current" ]]; then
|
||||
break
|
||||
fi
|
||||
|
||||
if [[ -d "${source_current}" ]]; then
|
||||
if [[ -d "$source_current" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
read -r mode owner group <<< "$(stat -c '%a %u %g' "${target_current}")"
|
||||
install -d -m "${mode}" -o "${owner}" -g "${group}" "${source_current}"
|
||||
read -r mode owner group <<< "$(stat -c '%a %u %g' "$target_current")"
|
||||
install -d -m "$mode" -o "$owner" -g "$group" "$source_current"
|
||||
done
|
||||
|
||||
source=$(realpath -m "${source}/${path}")
|
||||
target=$(realpath -m "${target}/${path}")
|
||||
source=$(realpath -m "$source/$path")
|
||||
target=$(realpath -m "$target/$path")
|
||||
|
||||
if [[ ! -e "${target}" ]] || { [[ -d "${target}" ]] && [[ -z "$(ls -A "${target}")" ]]; } || { [[ -f "${target}" ]] && [[ ! -s "${target}" ]]; }; then
|
||||
if [[ ! -e "$target" ]] || { [[ -d "$target" ]] && [[ -z "$(ls -A "$target")" ]]; } || { [[ -f "$target" ]] && [[ ! -s "$target" ]]; }; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ -e "${source}" ]]; then
|
||||
>&2 echo "Error: Source ${source} already exists. Cannot move ${target} to ${source}."
|
||||
if [[ -e "$source" ]]; then
|
||||
>&2 echo "Error: Source $source already exists. Cannot move $target to $source."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Moving target ${target} to source ${source}."
|
||||
mv "${target}" "${source}"
|
||||
echo "Moving target $target to source $source."
|
||||
mv "$target" "$source"
|
||||
|
Reference in New Issue
Block a user