From 339b4c578a2a77ce014b3bfe07100113f5dfb0c6 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 30 Dec 2023 17:52:29 +0300 Subject: [PATCH] moved pct-push-r out of .pct-helpers Signed-off-by: Alex A. Naanou --- .pct-helpers | 27 --------------------------- pct-mclone | 12 ++++++------ pct-push-r | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 33 deletions(-) create mode 100644 pct-push-r diff --git a/.pct-helpers b/.pct-helpers index 6e9439c..3a20cf9 100644 --- a/.pct-helpers +++ b/.pct-helpers @@ -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 : diff --git a/pct-mclone b/pct-mclone index 63582e0..de3901f 100644 --- a/pct-mclone +++ b/pct-mclone @@ -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 diff --git a/pct-push-r b/pct-push-r new file mode 100644 index 0000000..2f25225 --- /dev/null +++ b/pct-push-r @@ -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 :