moved pct-push-r out of .pct-helpers

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2023-12-30 17:52:29 +03:00
parent 5689ef211c
commit 339b4c578a
3 changed files with 57 additions and 33 deletions

View File

@ -126,33 +126,6 @@ hostname2ct(){
}
#----------------------------------------------------------------------
pct-push-r(){
local id=$1
local from=$2
local to=$3
local IFS=$'\n'
local 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
local files=($(find "$from" -type f))
for file in "${files[@]}" ; do
file=${file#${from}}
[ $QUIET ] \
|| echo "copy: \"${from}/${file}\" -> $id:\"${to}/${file}\""
pct push $id "${from}/${file}" "${to}/${file}"
done
}
#----------------------------------------------------------------------
# vim:set ts=4 sw=4 nowrap :

View File

@ -49,24 +49,24 @@ running=$(pct list | grep "running\s*$host\s*$")
# error checking...
if [ -z $id ] || [ -z $to ] ; then
echo ERR need both id and target id
echo ERR need both id and target id 1>&2
exit 1
fi
if [ $id = $to ] ; then
echo ERR need id and target id must be different
echo ERR need id and target id must be different 1>&2
exit 1
fi
if ! [ -e $ct ] ; then
echo ERR $ct does not exist.
echo ERR $ct does not exist. 1>&2
exit 1
fi
if [ -e ${CT_DIR}/${to}.conf ] ; then
echo ERR $to already exists.
echo ERR $to already exists. 1>&2
exit 1
fi
if ! [ -z $tpl ] && [ -e ${CT_DIR}/${tpl}.conf ] ; then
echo ERR $to already exists.
echo ERR $to already exists. 1>&2
exit 1
fi
@ -75,7 +75,7 @@ IFS=$'\n' mounts=($(cat $ct | grep 'mp[0-9]*:'))
# check...
for mp in ${mounts[@]} ; do
if ! [ $(grep ": $SHARE_ROOT" <<< $mp) ] ; then
echo "ERR mountpoint: \"$mp\" heeds to handled manually."
echo "ERR mountpoint: \"$mp\" heeds to handled manually." 1>&2
exit 1
fi
done

51
pct-push-r Normal file
View File

@ -0,0 +1,51 @@
#!/usr/bin/bash
#----------------------------------------------------------------------
#
#----------------------------------------------------------------------
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
id=$1
from=$2
to=$3
IFS=$'\n'
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
local files=($(find "$from" -type f))
for file in "${files[@]}" ; do
file=${file#${from}}
[ $QUIET ] \
|| echo "copy: \"${from}/${file}\" -> $id:\"${to}/${file}\""
pct push $id "${from}/${file}" "${to}/${file}"
done
#----------------------------------------------------------------------
# vim:set ts=4 sw=4 nowrap :