From 1ee4796b8ddda4c11d3fb4c9c82d5377d4829ff9 Mon Sep 17 00:00:00 2001 From: Facinorous Date: Wed, 4 Nov 2020 20:02:11 -0500 Subject: [PATCH] repository clean up, moved all scripts to setup script to be generated on first run. Still needs to be tested, probably doesnt work. --- .gitignore | 1 + creategroups | 6 ---- setup | 78 +++++++++++++++++++++++++++++++++++++++++----------- setup.conf | 3 ++ update | 6 ---- 5 files changed, 66 insertions(+), 28 deletions(-) create mode 100644 .gitignore delete mode 100644 creategroups delete mode 100644 update diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a882b40 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +./repositorymanagement/ \ No newline at end of file diff --git a/creategroups b/creategroups deleted file mode 100644 index 948b5af..0000000 --- a/creategroups +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -# Source config file -. ./setup.conf - -# Update the gitmirrors repo to latest version. diff --git a/setup b/setup index aecd2a2..a2c6e5d 100644 --- a/setup +++ b/setup @@ -6,26 +6,25 @@ # Clone latest gitmirrors repo into local project folder # and move it into correct locstion for project. for group in "${groupArray[@]}"; do -git clone $gitmirrorsRepo ./mirrormanagement/$group -sed "37s/.*/gitlab_namespace=\"${group}\"/" ./mirrormanagement/$group/config.sh.SAMPLE > ./mirrormanagement/$group/config.sh -sed -i "39s/.*/gitlab_url=\"${gitlabURL}\"/" ./mirrormanagement/$group/config.sh -sed -i "42s/.*/gitlab_user=\"${gitlabUser}\"/" ./mirrormanagement/$group/config.sh -sed -i "50s/.*/http_remote=true/" ./mirrormanagement/$group/config.sh -sed -i "58s/.*/issues_enabled=\"${issues_enabled}\"/" ./mirrormanagement/$group/config.sh -sed -i "59s/.*/wall_enabled=\"${wall_enabled}\"/" ./mirrormanagement/$group/config.sh -sed -i "60s/.*/wiki_enabled=\"${wiki_enabled}\"/" ./mirrormanagement/$group/config.sh -sed -i "61s/.*/snippets_enabled=\"${snippets_enabled}\"/" ./mirrormanagement/$group/config.sh -sed -i "62s/.*/gitlab_user=\"${merge_requests_enabled}\"/" ./mirrormanagement/$group/config.sh -sed -i "63s/.*/public=\"${public}\"/" ./mirrormanagement/$group/config.sh -rm ./mirrormanagement/$group/config.sh.SAMPLE +git clone $gitmirrorsRepo ~/$projectLocation/mirrormanagement/$group +sed "37s/.*/gitlab_namespace=\"${group}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh.SAMPLE > ~/$projectLocation/mirrormanagement/$group/config.sh +sed -i "39s/.*/gitlab_url=\"${gitlabURL}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh +sed -i "42s/.*/gitlab_user=\"${gitlabUser}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh +sed -i "50s/.*/http_remote=true/" ~/$projectLocation/mirrormanagement/$group/config.sh +sed -i "58s/.*/issues_enabled=\"${issues_enabled}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh +sed -i "59s/.*/wall_enabled=\"${wall_enabled}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh +sed -i "60s/.*/wiki_enabled=\"${wiki_enabled}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh +sed -i "61s/.*/snippets_enabled=\"${snippets_enabled}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh +sed -i "62s/.*/gitlab_user=\"${merge_requests_enabled}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh +sed -i "63s/.*/public=\"${public}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh done # Generate an ssh key echo -e "\n\n\n" | ssh-keygen -t rsa # Generate ssh server config -mkdir ./.ssh -cat > ./.ssh/config < ~/.ssh/config < ./private_token +# Generate cron job creation script. +cat > setcron < update < ~/$projectLocation/mirrormanagement/$group/config.sh +sed -i "39s/.*/gitlab_url=\"${gitlabURL}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh +sed -i "42s/.*/gitlab_user=\"${gitlabUser}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh +sed -i "50s/.*/http_remote=true/" ~/$projectLocation/mirrormanagement/$group/config.sh +sed -i "58s/.*/issues_enabled=\"${issues_enabled}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh +sed -i "59s/.*/wall_enabled=\"${wall_enabled}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh +sed -i "60s/.*/wiki_enabled=\"${wiki_enabled}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh +sed -i "61s/.*/snippets_enabled=\"${snippets_enabled}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh +sed -i "62s/.*/gitlab_user=\"${merge_requests_enabled}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh +sed -i "63s/.*/public=\"${public}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh +done + +echo "All mirror group's gitlab-mirror dependancies have been updated." +EOF +chmod u+x update + # Generate mirror script. cat > mirror <<'EOF' #!/bin/bash @@ -79,7 +123,7 @@ then fi done -# Main switch script, depending on which group is specified it runs the add mirror in that location TODO: make this into proper for loop that works with user variables. +# Main switch script, depending on which group is specified it runs the add mirror in that location if (( "$wronggroup" > ((groupCount-1)) )) then echo "The Gitlab group you specified does not exist, please make sure you select a group in the groups array of this script." @@ -90,7 +134,7 @@ for group in "${groupArray[@]}"; do if [[ ${GROUP} = "$group" ]] then echo "Mirroring repo ${REPO} into Gitlab group $group" - ./mirrormanagement/$group/gitlab-mirrors/add_mirror.sh --git --project-name ${NAME} --mirror ${REPO} + ~/$projectLocation/mirrormanagement/$group/gitlab-mirrors/add_mirror.sh --git --project-name ${NAME} --mirror ${REPO} fi done @@ -98,6 +142,8 @@ fi EOF chmod u+x mirror +# CREATE A SCRIPT THAT WILL CREATE GROUPS IF NEEDED + echo "" echo "Please put this SSH key into your gitlab mirror user." echo "" diff --git a/setup.conf b/setup.conf index c1260fb..0624743 100644 --- a/setup.conf +++ b/setup.conf @@ -21,6 +21,9 @@ snippets_enabled=false merge_requests_enabled=false public=false +# Project location's directory name. The name of the folder you cloned the repo from to get these files. Usually just the default. +projectLocation=gitmirrors-bs + #################### diff --git a/update b/update deleted file mode 100644 index 948b5af..0000000 --- a/update +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -# Source config file -. ./setup.conf - -# Update the gitmirrors repo to latest version.