proxmox-utils/pct-push-r
Alex A. Naanou c9a200d42e updated x-bits...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2023-12-30 16:05:41 +00:00

72 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/bash
#----------------------------------------------------------------------
#
#----------------------------------------------------------------------
# XXX
source $(dirname "$0")/.pct-helpers
#----------------------------------------------------------------------
case $1 in
-h|--help)
echo "Recursively push a directory to a CT creating the necessary paths"
echo
echo "Usage:"
echo " `basename $0` ID FROM TO"
echo
exit
;;
-*)
echo "Unknown option: $1"
exit
;;
esac
if [[ $# < 3 ]] ; then
echo ERR need both id and target id 1>&2
exit 1
fi
IFS=$'\n'
#----------------------------------------------------------------------
id=$1
from=$2
to=$3
#----------------------------------------------------------------------
wd=$(pwd)
# get from path relative to working directory...
if [[ ${from:0:1} != '/' ]] ; then
from="$(normpath "${wd}/${from}")"
fi
dirs=($(find "$from" -type d))
for dir in "${dirs[@]}" ; do
if [[ "$dir" == "${to}" ]] ; then
continue
fi
dir=${dir#${from}}
lxc-attach $id -- mkdir -p "${to}/${dir}"
done
files=($(find "$from" -type f))
for file in "${files[@]}" ; do
file=${file#${from}}
f=$(normpath "${from}/${file}")
t=$(normpath "${to}/${file}")
[ $QUIET ] \
|| echo "copy: \"${f#${wd}/}\" -> $id:\"$t\""
pct push $id "$f" "$t"
done
#----------------------------------------------------------------------
# vim:set ts=4 sw=4 nowrap :