mirror of
https://github.com/octoleo/octosync.git
synced 2024-11-24 13:47:35 +00:00
Fixed moving function.
This commit is contained in:
parent
a8e6ce0d73
commit
5e6d4c1531
@ -59,7 +59,7 @@ target.repo.folders=folder/path_a;folder/path_b
|
|||||||
# To merge or just make a PR (0 = PR; 1 = Merge)
|
# To merge or just make a PR (0 = PR; 1 = Merge)
|
||||||
target.repo.merge=1
|
target.repo.merge=1
|
||||||
|
|
||||||
# Target fork is rebased (HARD RESET TO UPSTREAM TARGET)
|
# Target fork is rebased to upstream target (target[dot]repo[dot]path)
|
||||||
# Then updated and used to make a PR or Merge
|
# Then updated and used to make a PR or Merge
|
||||||
target.repo.fork=org2/repo2
|
target.repo.fork=org2/repo2
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ target.repo.branch=main
|
|||||||
# source[dot]repo[dot]folders=folder/path_a;folder/path_b
|
# source[dot]repo[dot]folders=folder/path_a;folder/path_b
|
||||||
target.repo.folders=joomla_v4/source/language/en-GB;joomla_v4/source/administrator/language/en-GB;joomla_v4/source/api/language/en-GB
|
target.repo.folders=joomla_v4/source/language/en-GB;joomla_v4/source/administrator/language/en-GB;joomla_v4/source/api/language/en-GB
|
||||||
|
|
||||||
# Target fork is rebased (HARD RESET TO UPSTREAM TARGET)
|
# Target fork is rebased to upstream target (target[dot]repo[dot]path)
|
||||||
# Then updated and used to make a PR or Merge
|
# Then updated and used to make a PR or Merge
|
||||||
target.repo.fork=Llewellynvdm/core-translations
|
target.repo.fork=Llewellynvdm/core-translations
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ target.repo.folders=installation/language/en-GB;build/media_source/system/js/fie
|
|||||||
# To merge or just make a PR (0 = PR; 1 = Merge)
|
# To merge or just make a PR (0 = PR; 1 = Merge)
|
||||||
target.repo.merge=0
|
target.repo.merge=0
|
||||||
|
|
||||||
# Target fork is rebased (HARD RESET TO UPSTREAM TARGET)
|
# Target fork is rebased to upstream target (target[dot]repo[dot]path)
|
||||||
# Then updated and used to make a PR or Merge
|
# Then updated and used to make a PR or Merge
|
||||||
target.repo.fork=llewellynvdm/joomla-cms
|
target.repo.fork=llewellynvdm/joomla-cms
|
||||||
|
|
||||||
|
159
src/sync.sh
159
src/sync.sh
@ -1,5 +1,16 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
|
# Do some prep work
|
||||||
|
command -v git >/dev/null 2>&1 || {
|
||||||
|
echo >&2 "We require git for this script to run, but it's not installed. Aborting."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
# command -v gh >/dev/null 2>&1 || {
|
||||||
|
# echo >&2 "We require github CLI for this script to run, but it's not installed. Aborting."
|
||||||
|
# exit 1
|
||||||
|
# }
|
||||||
|
# will still add some github toke check (that it exist)
|
||||||
|
|
||||||
# get start time
|
# get start time
|
||||||
STARTBUILD=$(date +"%s")
|
STARTBUILD=$(date +"%s")
|
||||||
# use UTC+00:00 time also called zulu
|
# use UTC+00:00 time also called zulu
|
||||||
@ -33,8 +44,17 @@ function main() {
|
|||||||
# merge the changes into the target repository
|
# merge the changes into the target repository
|
||||||
function makeMergeToTarget() {
|
function makeMergeToTarget() {
|
||||||
# go into repo folder
|
# go into repo folder
|
||||||
cd target_repo
|
cd "${ROOT_TARGET_FOLDER}"
|
||||||
# make a commit of the changes
|
# make a commit of the changes
|
||||||
|
echo "merge:$PWD"
|
||||||
|
}
|
||||||
|
|
||||||
|
# create a pull request against the target repository
|
||||||
|
function makePullRequestAgainstTarget() {
|
||||||
|
# go into repo folder
|
||||||
|
cd "${ROOT_TARGET_FOLDER}"
|
||||||
|
# make a commit of the changes
|
||||||
|
echo "PR:$PWD"
|
||||||
}
|
}
|
||||||
|
|
||||||
# show the configuration values
|
# show the configuration values
|
||||||
@ -44,9 +64,9 @@ function checkConfValues () {
|
|||||||
|
|
||||||
# make sure SOURCE_REPO is set
|
# make sure SOURCE_REPO is set
|
||||||
[[ ! "${SOURCE_REPO}" == *"/"* ]] && echo "SOURCE_REPO:${SOURCE_REPO} is not a repo path!" && ERROR=1
|
[[ ! "${SOURCE_REPO}" == *"/"* ]] && echo "SOURCE_REPO:${SOURCE_REPO} is not a repo path!" && ERROR=1
|
||||||
[[ ! `wget -S --spider "https://github.com/${SOURCE_REPO}" 2>&1 | grep 'HTTP/1.1 200 OK'` ]] && \
|
[[ ! `wget -S --spider "https://github.com/${SOURCE_REPO}" 2>&1 | grep 'HTTP/1.1 200 OK'` ]] \
|
||||||
echo "SOURCE_REPO:https://github.com/${SOURCE_REPO} is not set correctly, or the guthub user does not have access!" && \
|
&& echo "SOURCE_REPO:https://github.com/${SOURCE_REPO} is not set correctly, or the guthub user does not have access!" \
|
||||||
ERROR=1
|
&& ERROR=1
|
||||||
|
|
||||||
# make sure SOURCE_REPO_BRANCH is set
|
# make sure SOURCE_REPO_BRANCH is set
|
||||||
[ ${#SOURCE_REPO_BRANCH} -le 1 ] && echo "SOURCE_REPO_BRANCH:${SOURCE_REPO_BRANCH} is not set correctly!" && ERROR=1
|
[ ${#SOURCE_REPO_BRANCH} -le 1 ] && echo "SOURCE_REPO_BRANCH:${SOURCE_REPO_BRANCH} is not set correctly!" && ERROR=1
|
||||||
@ -56,9 +76,9 @@ function checkConfValues () {
|
|||||||
|
|
||||||
# make sure TARGET_REPO is set
|
# make sure TARGET_REPO is set
|
||||||
[[ ! "${TARGET_REPO}" == *"/"* ]] && echo "TARGET_REPO:${TARGET_REPO} is not a repo path!" && ERROR=1
|
[[ ! "${TARGET_REPO}" == *"/"* ]] && echo "TARGET_REPO:${TARGET_REPO} is not a repo path!" && ERROR=1
|
||||||
[[ ! `wget -S --spider "https://github.com/${TARGET_REPO}" 2>&1 | grep 'HTTP/1.1 200 OK'` ]] && \
|
[[ ! `wget -S --spider "https://github.com/${TARGET_REPO}" 2>&1 | grep 'HTTP/1.1 200 OK'` ]] \
|
||||||
echo "TARGET_REPO:https://github.com/${TARGET_REPO} is not set correctly, or the guthub user does not have access!" && \
|
&& echo "TARGET_REPO:https://github.com/${TARGET_REPO} is not set correctly, or the guthub user does not have access!" \
|
||||||
ERROR=1
|
&& ERROR=1
|
||||||
|
|
||||||
# make sure TARGET_REPO_BRANCH is set
|
# make sure TARGET_REPO_BRANCH is set
|
||||||
[ ${#TARGET_REPO_BRANCH} -le 1 ] && echo "TARGET_REPO_BRANCH:${TARGET_REPO_BRANCH} is not set correctly!" && ERROR=1
|
[ ${#TARGET_REPO_BRANCH} -le 1 ] && echo "TARGET_REPO_BRANCH:${TARGET_REPO_BRANCH} is not set correctly!" && ERROR=1
|
||||||
@ -72,9 +92,9 @@ function checkConfValues () {
|
|||||||
# make sure TARGET_REPO_FORK is set correctly if set
|
# make sure TARGET_REPO_FORK is set correctly if set
|
||||||
if [ ${#TARGET_REPO_FORK} -ge 1 ]; then
|
if [ ${#TARGET_REPO_FORK} -ge 1 ]; then
|
||||||
[[ ! "${TARGET_REPO_FORK}" == *"/"* ]] && echo "TARGET_REPO_FORK:${TARGET_REPO_FORK} is not a repo path!" && ERROR=1
|
[[ ! "${TARGET_REPO_FORK}" == *"/"* ]] && echo "TARGET_REPO_FORK:${TARGET_REPO_FORK} is not a repo path!" && ERROR=1
|
||||||
[[ ! `wget -S --spider "https://github.com/${TARGET_REPO_FORK}" 2>&1 | grep 'HTTP/1.1 200 OK'` ]] && \
|
[[ ! `wget -S --spider "https://github.com/${TARGET_REPO_FORK}" 2>&1 | grep 'HTTP/1.1 200 OK'` ]] \
|
||||||
echo "TARGET_REPO_FORK:https://github.com/${TARGET_REPO_FORK} is not set correctly, or the guthub user does not have access!" && \
|
&& echo "TARGET_REPO_FORK:https://github.com/${TARGET_REPO_FORK} is not set correctly, or the guthub user does not have access!" \
|
||||||
ERROR=1
|
&& ERROR=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# if error found exit
|
# if error found exit
|
||||||
@ -84,17 +104,20 @@ function checkConfValues () {
|
|||||||
# clone the repo
|
# clone the repo
|
||||||
function cloneRepos () {
|
function cloneRepos () {
|
||||||
# clone the source repo (we don't need access on this one)
|
# clone the source repo (we don't need access on this one)
|
||||||
[[ "${SOURCE_REPO}" == *"/"* ]] && cloneRepo "https://github.com/${SOURCE_REPO}.git" "${SOURCE_REPO_BRANCH}" "source_repo"
|
[[ "${SOURCE_REPO}" == *"/"* ]] && cloneRepo "https://github.com/${SOURCE_REPO}.git" "${SOURCE_REPO_BRANCH}" "${ROOT_SOURCE_FOLDER}"
|
||||||
# clone the forked target repo if set
|
# clone the forked target repo if set
|
||||||
if [[ "${TARGET_REPO_FORK}" == *"/"* ]]; then
|
if [[ "${TARGET_REPO_FORK}" == *"/"* ]]; then
|
||||||
# we need access on this one, so we use git@github.com:
|
# we need access on this one, so we use git@github.com:
|
||||||
cloneRepo "${TARGET_REPO_FORK}" "git@github.com:${TARGET_REPO_BRANCH}.git" "target_repo"
|
cloneRepo "git@github.com:${TARGET_REPO_FORK}.git" "${TARGET_REPO_BRANCH}" "${ROOT_TARGET_FOLDER}"
|
||||||
# rebase with upstream if not in sync
|
# only rebase if fresh clone
|
||||||
rebaseWithUpstream "${TARGET_REPO}" "https://github.com/${TARGET_REPO_BRANCH}.git" "target_repo"
|
if [ $? -eq 0 ];then
|
||||||
|
# rebase with upstream (we don't need access on this one)
|
||||||
|
rebaseWithUpstream "https://github.com/${TARGET_REPO}.git" "${TARGET_REPO_BRANCH}" "${ROOT_TARGET_FOLDER}"
|
||||||
|
fi
|
||||||
# we must have merge set if we directly work with target repo
|
# we must have merge set if we directly work with target repo
|
||||||
elif (("$TARGET_REPO_ACTION" == 1)); then
|
elif (("$TARGET_REPO_ACTION" == 1)); then
|
||||||
# we need access on this one, so we use git@github.com:
|
# we need access on this one, so we use git@github.com:
|
||||||
cloneRepo "${TARGET_REPO}" "git@github.com:${TARGET_REPO_BRANCH}.git" "target_repo"
|
cloneRepo "${TARGET_REPO}" "git@github.com:${TARGET_REPO_BRANCH}.git" "${ROOT_TARGET_FOLDER}"
|
||||||
else
|
else
|
||||||
echo "You must set TARGET_REPO:${TARGET_REPO} to target.repo.merge=1 if no target.repo.fork is given!"
|
echo "You must set TARGET_REPO:${TARGET_REPO} to target.repo.merge=1 if no target.repo.fork is given!"
|
||||||
exit 20
|
exit 20
|
||||||
@ -108,14 +131,15 @@ function cloneRepo () {
|
|||||||
local git_branch="$2"
|
local git_branch="$2"
|
||||||
local git_folder="$3"
|
local git_folder="$3"
|
||||||
# with test we don't clone again
|
# with test we don't clone again
|
||||||
# if folder already exist
|
# if folder already exist (if you dont want this behaviour manually remove the folders)
|
||||||
if (("$TEST" == 1)) && [ -d "${git_folder}" ]; then
|
if (("$TEST" == 1)) && [ -d "${git_folder}" ]; then
|
||||||
echo "folder:${git_folder} already exist, repo:${git_repo} was not cloned again. (test mode)"
|
echo "folder:${git_folder} already exist, repo:${git_repo} was not cloned again. (test mode)"
|
||||||
|
return 1
|
||||||
else
|
else
|
||||||
# make sure the folder does not exist
|
# make sure the folder does not exist
|
||||||
[ -d "${git_folder}" ] && rm -fr "${git_folder}"
|
[ -d "${git_folder}" ] && rm -fr "${git_folder}"
|
||||||
# clone the repo (but only a single branch)
|
# clone the repo (but only a single branch)
|
||||||
git clone -b "$git_branch" --single-branch "$git_repo" "$git_folder" --quiet
|
git clone -b "$git_branch" --single-branch "$git_repo" "$git_folder"
|
||||||
if [ $? -eq 0 ];then
|
if [ $? -eq 0 ];then
|
||||||
echo "${git_repo} was cloned successfully."
|
echo "${git_repo} was cloned successfully."
|
||||||
else
|
else
|
||||||
@ -123,6 +147,7 @@ function cloneRepo () {
|
|||||||
exit 21
|
exit 21
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# rebase repo with its upstream (old school)
|
# rebase repo with its upstream (old school)
|
||||||
@ -137,30 +162,23 @@ function rebaseWithUpstream () {
|
|||||||
local git_upstream="stroomOp"
|
local git_upstream="stroomOp"
|
||||||
# go into repo folder
|
# go into repo folder
|
||||||
cd ${git_folder}
|
cd ${git_folder}
|
||||||
# add the upstream repo
|
# check out the upstream repository
|
||||||
git remote add "$git_upstream" "$git_repo_upstream" --quiet
|
git checkout -b "${git_upstream}" "$git_branch"
|
||||||
|
git pull ${git_repo_upstream} "$git_branch"
|
||||||
if [ $? -eq 0 ];then
|
if [ $? -eq 0 ];then
|
||||||
echo "upstream:${git_repo_upstream} was added successfully."
|
echo "upstream:${git_repo_upstream} was pulled successfully."
|
||||||
else
|
else
|
||||||
echo "Failed to add upstream:${git_repo_upstream} successfully, check that the GitHub user has access to this repo!"
|
echo "Failed to pull upstream:${git_repo_upstream} successfully, check that the GitHub user has access to this repo!"
|
||||||
exit 10
|
exit 10
|
||||||
fi
|
fi
|
||||||
# now fetch this upstream repo
|
|
||||||
git fetch "$git_upstream/${git_branch}" --quiet
|
|
||||||
if [ $? -eq 0 ];then
|
|
||||||
echo "upstream/${git_branch} was fetched successfully."
|
|
||||||
else
|
|
||||||
echo "Failed to fetch upstream/${git_branch} successfully, check that the GitHub user has access to this repo!"
|
|
||||||
exit 11
|
|
||||||
fi
|
|
||||||
# make sure we are on the targeted branch
|
# make sure we are on the targeted branch
|
||||||
git checkout "$git_branch"
|
git checkout "$git_branch"
|
||||||
# reset this branch to be same as upstream
|
# rebase to upstream
|
||||||
git reset --hard "${git_upstream}/${git_branch}" --quiet
|
git rebase "${git_upstream}"
|
||||||
if [ $? -eq 0 ];then
|
if [ $? -eq 0 ];then
|
||||||
echo "upstream:${git_repo_upstream} was rebased into the forked repo successfully."
|
echo "upstream:${git_repo_upstream} was rebased into the forked repo successfully."
|
||||||
else
|
else
|
||||||
echo "Failed to rebase upstream:${git_repo_upstream} successfully, check that the GitHub user has access to this repo!"
|
echo "Failed to rebase upstream:${git_repo_upstream} successfully!"
|
||||||
exit 12
|
exit 12
|
||||||
fi
|
fi
|
||||||
# make sure this is not a test
|
# make sure this is not a test
|
||||||
@ -168,7 +186,7 @@ function rebaseWithUpstream () {
|
|||||||
echo "The forked repo of upstream:${git_repo_upstream} not updated, as this is a test."
|
echo "The forked repo of upstream:${git_repo_upstream} not updated, as this is a test."
|
||||||
else
|
else
|
||||||
# force update the forked repo
|
# force update the forked repo
|
||||||
git push origin "$git_branch" --force --quiet
|
git push origin "$git_branch" --force
|
||||||
if [ $? -eq 0 ];then
|
if [ $? -eq 0 ];then
|
||||||
echo "The forked repo of upstream:${git_repo_upstream} successfully updated."
|
echo "The forked repo of upstream:${git_repo_upstream} successfully updated."
|
||||||
else
|
else
|
||||||
@ -182,6 +200,11 @@ function rebaseWithUpstream () {
|
|||||||
|
|
||||||
# move the source folders and files to the target folders
|
# move the source folders and files to the target folders
|
||||||
function moveFoldersFiles () {
|
function moveFoldersFiles () {
|
||||||
|
# with test we show in what folder
|
||||||
|
# we are in when we start moving stuff
|
||||||
|
if (("$TEST" == 1)); then
|
||||||
|
echo "Location: [$PWD]"
|
||||||
|
fi
|
||||||
# check if we have an array of folders
|
# check if we have an array of folders
|
||||||
if [[ "${SOURCE_REPO_FOLDERS}" == *";"* ]] && [[ "${TARGET_REPO_FOLDERS}" == *";"* ]]; then
|
if [[ "${SOURCE_REPO_FOLDERS}" == *";"* ]] && [[ "${TARGET_REPO_FOLDERS}" == *";"* ]]; then
|
||||||
# set the folders array
|
# set the folders array
|
||||||
@ -239,13 +262,14 @@ function moveFolderFiles () {
|
|||||||
target_folder="${target_folder%/}"
|
target_folder="${target_folder%/}"
|
||||||
target_folder="${target_folder#/}"
|
target_folder="${target_folder#/}"
|
||||||
# make sure the source folder exist
|
# make sure the source folder exist
|
||||||
if [ ! -f "source_repo/${source_folder}" ]; then
|
if [ ! -d "${ROOT_SOURCE_FOLDER}/${source_folder}" ]; then
|
||||||
echo "failed to copy [source_repo/${source_folder}/* -> target_repo/${target_folder}] since source folder does not exist. (failure)"
|
echo "failed to copy [${ROOT_SOURCE_FOLDER}/${source_folder} -> ${ROOT_TARGET_FOLDER}/${target_folder}] since source folder does not exist. (failure)"
|
||||||
|
echo "current_folder:${PWD}"
|
||||||
else
|
else
|
||||||
# make sure the target folder exist
|
# make sure the target folder exist
|
||||||
if [ ! -f "target_repo/${target_folder}" ]; then
|
if [ ! -f "${ROOT_TARGET_FOLDER}/${target_folder}" ]; then
|
||||||
# create this folder if it does not exist
|
# create this folder if it does not exist
|
||||||
mkdir -p "target_repo/${target_folder}"
|
mkdir -p "${ROOT_TARGET_FOLDER}/${target_folder}"
|
||||||
fi
|
fi
|
||||||
# check if we have number command
|
# check if we have number command
|
||||||
re='^[0-9]+$'
|
re='^[0-9]+$'
|
||||||
@ -253,33 +277,36 @@ function moveFolderFiles () {
|
|||||||
# 0 = all
|
# 0 = all
|
||||||
if (("$source_files" == 0)); then
|
if (("$source_files" == 0)); then
|
||||||
# copy both files and sub-folders recursive by force
|
# copy both files and sub-folders recursive by force
|
||||||
cp -fr "source_repo/${source_folder}/*" "target_repo/${target_folder}"
|
cp -fr "${ROOT_SOURCE_FOLDER}/${source_folder}/"* "${ROOT_TARGET_FOLDER}/${target_folder}"
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "copied [source_repo/${source_folder}/* -> target_repo/${target_folder}] (success)"
|
echo "copied [${ROOT_SOURCE_FOLDER}/${source_folder}/* -> ${ROOT_TARGET_FOLDER}/${target_folder}] (success)"
|
||||||
else
|
else
|
||||||
echo "failed to copy [source_repo/${source_folder}/* -> target_repo/${target_folder}] (failure)"
|
echo "failed to copy [${ROOT_SOURCE_FOLDER}/${source_folder}/* -> ${ROOT_TARGET_FOLDER}/${target_folder}] (failure [0])"
|
||||||
|
echo "current_folder:${PWD}"
|
||||||
fi
|
fi
|
||||||
# 1 = only all files (no sub-folders)
|
# 1 = only all files (no sub-folders)
|
||||||
elif (("$source_files" == 1)); then
|
elif (("$source_files" == 1)); then
|
||||||
# copy only the file by force
|
# copy only the file by force
|
||||||
cp -f "source_repo/${source_folder}/*" "target_repo/${target_folder}"
|
cp -f "${ROOT_SOURCE_FOLDER}/${source_folder}/"* "${ROOT_TARGET_FOLDER}/${target_folder}"
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "copied [source_repo/${source_folder}/* -> target_repo/${target_folder}] (success)"
|
echo "copied [${ROOT_SOURCE_FOLDER}/${source_folder}/* -> ${ROOT_TARGET_FOLDER}/${target_folder}] (success)"
|
||||||
else
|
else
|
||||||
echo "failed to copy [source_repo/${source_folder}/* -> target_repo/${target_folder}] (failure)"
|
echo "failed to copy [${ROOT_SOURCE_FOLDER}/${source_folder}/* -> ${ROOT_TARGET_FOLDER}/${target_folder}] (failure [1])"
|
||||||
|
echo "current_folder:${PWD}"
|
||||||
fi
|
fi
|
||||||
# 2 = only all sub-folders and their files
|
# 2 = only all sub-folders and their files
|
||||||
elif (("$source_files" == 2)); then
|
elif (("$source_files" == 2)); then
|
||||||
echo "This command:2 means to copy only all sub-folders and their files."
|
echo "This command:2 means to copy only all sub-folders and their files."
|
||||||
echo 'Yet this file command:${source_files} for source_repo/${source_folder} is not ready to be used... so nothing was copied!';
|
echo 'Yet this file command:${source_files} for ${ROOT_SOURCE_FOLDER}/${source_folder} is not ready to be used... so nothing was copied!';
|
||||||
# could be a file (name as number) so we try to copy it
|
# could be a file (name as number) so we try to copy it
|
||||||
else
|
else
|
||||||
# copy file/folder recursive by force
|
# copy file/folder recursive by force
|
||||||
cp -fr "source_repo/${source_folder}/${source_files}" "target_repo/${target_folder}"
|
cp -fr "${ROOT_SOURCE_FOLDER}/${source_folder}/${source_files}" "${ROOT_TARGET_FOLDER}/${target_folder}"
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "copied [source_repo/${source_folder}/${source_files} -> target_repo/${target_folder}] (success)"
|
echo "copied [${ROOT_SOURCE_FOLDER}/${source_folder}/${source_files} -> ${ROOT_TARGET_FOLDER}/${target_folder}] (success)"
|
||||||
else
|
else
|
||||||
echo "failed to copy [source_repo/${source_folder}/${source_files} -> target_repo/${target_folder}] (failure)"
|
echo "failed to copy [${ROOT_SOURCE_FOLDER}/${source_folder}/${source_files} -> ${ROOT_TARGET_FOLDER}/${target_folder}] (failure [.])"
|
||||||
|
echo "current_folder:${PWD}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@ -292,11 +319,12 @@ function moveFolderFiles () {
|
|||||||
file="${file%/}"
|
file="${file%/}"
|
||||||
file="${file#/}"
|
file="${file#/}"
|
||||||
# copy file/folder recursive by force
|
# copy file/folder recursive by force
|
||||||
cp -fr "source_repo/${source_folder}/${file}" "target_repo/${target_folder}"
|
cp -fr "${ROOT_SOURCE_FOLDER}/${source_folder}/${file}" "${ROOT_TARGET_FOLDER}/${target_folder}"
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "copied [source_repo/${source_folder}/${file} -> target_repo/${target_folder}] (success)"
|
echo "copied [${ROOT_SOURCE_FOLDER}/${source_folder}/${file} -> ${ROOT_TARGET_FOLDER}/${target_folder}] (success)"
|
||||||
else
|
else
|
||||||
echo "failed to copy [source_repo/${source_folder}/${file} -> target_repo/${target_folder}] (failure)"
|
echo "failed to copy [${ROOT_SOURCE_FOLDER}/${source_folder}/${file} -> ${ROOT_TARGET_FOLDER}/${target_folder}] (failure [..])"
|
||||||
|
echo "current_folder:${PWD}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
@ -304,11 +332,12 @@ function moveFolderFiles () {
|
|||||||
source_files="${source_files%/}"
|
source_files="${source_files%/}"
|
||||||
source_files="${source_files#/}"
|
source_files="${source_files#/}"
|
||||||
# copy file/folder recursive by force
|
# copy file/folder recursive by force
|
||||||
cp -fr "source_repo/${source_folder}/${source_files}" "target_repo/${target_folder}"
|
cp -fr "${ROOT_SOURCE_FOLDER}/${source_folder}/${source_files}" "${ROOT_TARGET_FOLDER}/${target_folder}"
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "copied [source_repo/${source_folder}/${source_files} -> target_repo/${target_folder}] (success)"
|
echo "copied [${ROOT_SOURCE_FOLDER}/${source_folder}/${source_files} -> ${ROOT_TARGET_FOLDER}/${target_folder}] (success)"
|
||||||
else
|
else
|
||||||
echo "failed to copy [source_repo/${source_folder}/${source_files} -> target_repo/${target_folder}] (failure)"
|
echo "failed to copy [${ROOT_SOURCE_FOLDER}/${source_folder}/${source_files} -> ${ROOT_TARGET_FOLDER}/${target_folder}] (failure [...])"
|
||||||
|
echo "current_folder:${PWD}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -325,20 +354,22 @@ function moveFolder () {
|
|||||||
target_folder="${target_folder%/}"
|
target_folder="${target_folder%/}"
|
||||||
target_folder="${target_folder#/}"
|
target_folder="${target_folder#/}"
|
||||||
# make sure the source folder exist
|
# make sure the source folder exist
|
||||||
if [ ! -f "source_repo/${source_folder}" ]; then
|
if [ ! -d "${ROOT_SOURCE_FOLDER}/${source_folder}" ]; then
|
||||||
echo "failed to copy [source_repo/${source_folder}/* -> target_repo/${target_folder}] since source folder does not exist. (failure)"
|
echo "failed to copy [${ROOT_SOURCE_FOLDER}/${source_folder} -> ${ROOT_TARGET_FOLDER}/${target_folder}] since source folder does not exist. (failure )"
|
||||||
|
echo "current_folder:${PWD}"
|
||||||
else
|
else
|
||||||
# make sure the target folder exist
|
# make sure the target folder exist
|
||||||
if [ ! -f "target_repo/${target_folder}" ]; then
|
if [ ! -f "${ROOT_TARGET_FOLDER}/${target_folder}" ]; then
|
||||||
# create this folder if it does not exist
|
# create this folder if it does not exist
|
||||||
mkdir -p "target_repo/${target_folder}"
|
mkdir -p "${ROOT_TARGET_FOLDER}/${target_folder}"
|
||||||
fi
|
fi
|
||||||
# copy both files and sub-folders recursive by force
|
# copy both files and sub-folders recursive by force
|
||||||
cp -fr "source_repo/${source_folder}/*" "target_repo/${target_folder}"
|
cp -fr "${ROOT_SOURCE_FOLDER}/${source_folder}/"* "${ROOT_TARGET_FOLDER}/${target_folder}"
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "copied [source_repo/${source_folder}/* -> target_repo/${target_folder}] (success)"
|
echo "copied [${ROOT_SOURCE_FOLDER}/${source_folder}/* -> ${ROOT_TARGET_FOLDER}/${target_folder}] (success)"
|
||||||
else
|
else
|
||||||
echo "failed to copy [source_repo/${source_folder}/* -> target_repo/${target_folder}] (failure)"
|
echo "failed to copy [${ROOT_SOURCE_FOLDER}/${source_folder}/* -> ${ROOT_TARGET_FOLDER}/${target_folder}] (failure [*])"
|
||||||
|
echo "current_folder:${PWD}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -436,6 +467,10 @@ CONFIG_FILE=""
|
|||||||
TEST=0
|
TEST=0
|
||||||
DRYRUN=0
|
DRYRUN=0
|
||||||
|
|
||||||
|
# local repo folders
|
||||||
|
ROOT_SOURCE_FOLDER="source_repo"
|
||||||
|
ROOT_TARGET_FOLDER="target_repo"
|
||||||
|
|
||||||
# CONFIG VALUES
|
# CONFIG VALUES
|
||||||
# see: conf/example (for details)
|
# see: conf/example (for details)
|
||||||
SOURCE_REPO=""
|
SOURCE_REPO=""
|
||||||
@ -473,8 +508,8 @@ while :; do
|
|||||||
--conf=?* | --config=?*)
|
--conf=?* | --config=?*)
|
||||||
CONFIG_FILE=${1#*=} # Delete everything up to "=" and assign the remainder.
|
CONFIG_FILE=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||||
;;
|
;;
|
||||||
--conf= | --config) # Handle the case of an empty --conf=
|
--conf= | --config=) # Handle the case of an empty --conf=
|
||||||
echo 'ERROR: "--conf" requires a non-empty option argument.'
|
echo 'ERROR: "--conf=" requires a non-empty option argument.'
|
||||||
exit 17
|
exit 17
|
||||||
;;
|
;;
|
||||||
*) # Default case: No more options, so break out of the loop.
|
*) # Default case: No more options, so break out of the loop.
|
||||||
|
Loading…
Reference in New Issue
Block a user