This commit is contained in:
2023-03-23 11:05:13 +01:00
parent fb0ff3e057
commit 386f96be1c
4 changed files with 43 additions and 24 deletions

9
fun.sh
View File

@@ -1,9 +0,0 @@
#! /usr/bin/env bash
#
#for branch in $(git for-each-ref --format='%(refname)' refs/heads/); do
# echo "${branch/'refs/heads/'/''}"
#done
function test() {
git for-each-ref --format='%(refname)' refs/heads/
}

15
func.sh Normal file
View File

@@ -0,0 +1,15 @@
#! /usr/bin/env bash
function sub_akt() {
#$1 ist Branch
#$2 neue URLD
new_sub_url="$2"
pro_be_cut=${new_sub_url##*/}
sub_name=${pro_be_cut::-4}
echo "git checkout $1"
echo "git submodule set-url $sub_name $new_sub_url"
echo "git submodule update --init --recursive --remote $sub_name"
echo "git add .gitmodules"
echo "git commit -m 'Submodul aktualisiert'"
echo "git push"
}

33
main.sh
View File

@@ -1,33 +1,46 @@
#! /usr/bin/env bash #! /usr/bin/env bash
#for branch in $(git for-each-ref --format='%(refname)' refs/heads/); do
# echo "${branch/'refs/heads/'/''}"
#done
clone_work_dir="/home/jonnybravo/workdir" clone_work_dir="/home/jonnybravo/workdir"
script_folder="$(pwd)" script_folder="$(pwd)"
echo $script_folder logfile=/home/jonnybravo/sysint-migration-submodule.log
source "func.sh"
#create_clone_Folder #create_clone_Folder
if [ ! -d $clone_work_dir ] if [ ! -d $clone_work_dir ]
then then
mkdir -p $clone_work_dir mkdir -p $clone_work_dir
if [ $? -eq 0 ]; then echo " $(date '+%Y-%m-%d %H:%M:%S') - $clone_work_dir wurde angelegt!" >> $logfile
else echo "ERROR - $(date '+%Y-%m-%d %H:%M:%S') - $clone_work_dir konnte NICHT angelgt werden ERROR "; fi
fi fi
while IFS="," read -r git_url project_name while IFS="," read -r git_url new_sub_url
do do
pro_be_cut=${git_url##*/}
project_name=${pro_be_cut::-4}
clone_folder="$clone_work_dir/$project_name" clone_folder="$clone_work_dir/$project_name"
if [ -d $clone_work_dir ] if [ -d $clone_folder ]
then then
echo "Verzechnis $clone_work_dir existiert bereits" echo "Verzechnis $clone_folder existiert bereits"
else else
git clone $git_url $clone_folder git clone $git_url $clone_folder
if [ $? -eq 0 ]; then echo "INFO - $(date '+%Y-%m-%d %H:%M:%S') - $git_url wurde geclont !" >> $logfile
else echo "ERROR - $(date '+%Y-%m-%d %H:%M:%S') - $git_url konnte NICHT geclont werden ERROR "; fi
fi fi
cd $clone_folder cd $clone_folder
for branch in $(git for-each-ref --format='%(refname)' refs/heads/) for branch in $(git for-each-ref --format='%(refname)' refs/heads/)
do do
git_pro_branch="${branch/'refs/heads/'/''}" git_pro_branch="${branch/'refs/heads/'/''}"
echo "$project_name as $git_pro_branch" echo "$project_name as $git_pro_branch"
sub_akt $git_pro_branch $new_sub_url
if [ $? -eq 0 ]; then echo "INFO - $(date '+%Y-%m-%d %H:%M:%S') - konnte $new_sub_url auf $git_pro_branch aktualisieren" >> $logfile
else echo "ERROR - $(date '+%Y-%m-%d %H:%M:%S') - konnte NICHT $new_sub_url auf $git_pro_branch aktualisieren "; fi
done done
cd $script_folder cd $script_folder
rm -rf "$clone_folder"
if [ $? -eq 0 ]; then echo "INFO - $(date '+%Y-%m-%d %H:%M:%S') - $clone_folder wurde gelöscht !" >> $logfile
else echo "ERROR - $(date '+%Y-%m-%d %H:%M:%S') - $colne_folder konnte NICHT gelöscht werden ERROR "; fi
done < <(tail -n +2 project.csv) done < <(tail -n +2 project.csv)

View File

@@ -1,3 +1,3 @@
git_url,project_name, git_url,new_sub_url,
https://gitea.schlaubistechtalk.de/t4m/docker_gitlab.git,docker_gitlab, https://gitea.schlaubistechtalk.de/t4m/docker_gitlab.git, https://gitea.schlaubistechtalk.de/t4m/win_ps_hidden_files.git,
https://gitea.schlaubistechtalk.de/t4m/win_ps_hidden_files.git,win_ps_hidden_files, https://gitea.schlaubistechtalk.de/t4m/win_ps_hidden_files.git,https://gitea.schlaubistechtalk.de/t4m/docker_gitlab.git,
1 git_url project_name new_sub_url
2 https://gitea.schlaubistechtalk.de/t4m/docker_gitlab.git docker_gitlab https://gitea.schlaubistechtalk.de/t4m/win_ps_hidden_files.git
3 https://gitea.schlaubistechtalk.de/t4m/win_ps_hidden_files.git win_ps_hidden_files https://gitea.schlaubistechtalk.de/t4m/docker_gitlab.git