From ce4acae5b6dce01fdacae7673b359521d37f749d Mon Sep 17 00:00:00 2001 From: Facinorous Date: Thu, 5 Nov 2020 07:33:08 -0500 Subject: [PATCH] Updated reaxme, fixed generation of mirrormangement folders --- README.md | 77 ++++++++++++++++++++++++++++++++++++++++++------------ setup | 13 ++++----- setup.conf | 13 +++++---- 3 files changed, 73 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 028d3db..3f9d7db 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,65 @@ -Yes, I know this README sucks. -This isn't the final version. This is just to give you a basic understanding of how easy it will be to run this shit. +TODO: +1. Make & test creategroups script < TO BE AIRED > +2. Test setcron script +3. Test mirror script +4. Test update script +5. Test adding more groups after, then running set up script again +6. Test setcron script again after adding new groups +7. Verify folder structure matches the one listed in this README +8. Rewrite this README to actually look good and be easy to follow -== SET UP == -1. Create a user in your gitlab named gitmirror -2. Create a new user on your linux system, probably best to name it gitmirror too -3. Clone this repo into your new users home directory ~ -4. Edit setup.conf to your desires -5. Run ./setup to begin the set up process -6. Copy ssh key shown in terminal at the end of setup script into your gitlab users account -7. Run ./creategroups to make all the groups in gitlab <-- this is a WIP script, for now you must make your own in gitlab under the user you made before -8. Run ./setcron to add the mirror cron jobs to the users cron table +# Prerequisites -== ADDING MIRRORS == +### Required software + +* [Tested with GitLab 8.x/9.x/10/x][gitlab] +* [python-gitlab @ v1.1.0][python-gitlab] +* [GNU coreutils][coreutils] +* [git 1.8.0][git] or later + +#### python-gitlab + + `yum install python-pip` | `sudo apt install python-pip` + `pip install python-gitlab` + + +# Set Up + +1. Create a user in your gitlab, name it `gitmirror` +2. Create a user on your linux machine, call it `gitmirror` by running: `sudo adduser gitmirror` +3. Switch to the new user by typing `su - gitmirror` and by default you are, but make sure you are in it's home directory by typing `cd ~` +4. Clone this repo by typing `git clone https://github.com/Facinorous-420/gitmirrors-bs.git` +5. Enter the new directory by typing `cd gitmirrors-bs` +6. Edit setup.conf by typing `nano setup.conf` +7. Give the setup script execute permissions by typing `chmod u+x ./setup` +
+ +Be sure to read the config and change all things to your desired specifications. Refer to the comments in that file for info on what everything is. +Do not edit anything under the system variables section, only the user variables. You'll need to generate a Personal Access Token in the user `gitmirror` on gitlab for the config. + +**NOTE:** Currently you must create the groups in gitlab using the `gitmirror` user manually. This will be changed in a future update. Once this text is gone, it'll be automatic. +8. Run `./setup` to begin the automatic set up process. +9. Once the set up is done, you will be given a SSH key. Login to your `gitmirror` account on your gitlab instance, and add that SSH key to it. +10. Run `./setcron` to add the mirror cron jobs to the users cron table + +# Mirroring Run ./mirror to set up a mirror -If you at any time want to add more groups you can mirror to, simply add them to the setup.conf file and rdo the set up process again. +
+ +The full syntax for the command is `./mirror -g GROUPNAME -n REPONAME -r SOURCEREPOLOCATION` +Where `-g` means **destination group name**, `-n` means **destination repo name**, and `-r` means **source repo location** +
+ +If you at any time want to add more groups you can mirror to, simply add them to the setup.conf file and redo the set up process. + +# Updating -== UPDATING DEPENDANCIES == +You might find out that gitlab-mirror doesn't actually update that often. Although, if it ever does, you can simply run `./update` to update your project's gitlab-mirror. -Use ./update to update your gitlab-mirror dependancy +# Updating -== FILE STRUCTURE == +When done, the file structure in your system should look as such: ``` /home/gitmirror/gitmirrors-bs @@ -40,4 +79,8 @@ Use ./update to update your gitlab-mirror dependancy │ └── systems-svn └── Group2 └── GitLab Enterprise Edition -``` \ No newline at end of file +``` + +# Great Thanks + +Great thanks to the original creator of [gitlab-mirrors](https://github.com/samrocketman/gitlab-mirrors), [samrocketman](https://github.com/samrocketman) obviously as that is the main foundation to these bash scripts. \ No newline at end of file diff --git a/setup b/setup index a2c6e5d..bfd3824 100644 --- a/setup +++ b/setup @@ -7,23 +7,23 @@ # and move it into correct locstion for project. for group in "${groupArray[@]}"; do git clone $gitmirrorsRepo ~/$projectLocation/mirrormanagement/$group +chmod 755 ~/$projectLocation/mirrormanagement/$group/*.sh 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 "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 "62s/.*/merge_requests_enabled=\"${merge_requests_enabled}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh sed -i "63s/.*/public=\"${public}\"/" ~/$projectLocation/mirrormanagement/$group/config.sh done -# Generate an ssh key +# Generate a ssh key echo -e "\n\n\n" | ssh-keygen -t rsa # Generate ssh server config -mkdir ~/.ssh cat > ~/.ssh/config < 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 @@ -148,5 +149,5 @@ echo "" echo "Please put this SSH key into your gitlab mirror user." echo "" echo "SSH Key:" -cat ./ssh/id_rsa.pub +cat ~/.ssh/id_rsa.pub diff --git a/setup.conf b/setup.conf index 0624743..a6f3379 100644 --- a/setup.conf +++ b/setup.conf @@ -1,12 +1,14 @@ +#################### ## USER VARIABLES ## +#################### # Your gitlab information -gitlabURL=https://git.example.com +gitlabURL=https://gitmirror:gitmirrorpssword@git.example.com gitlabUser=gitmirror gitlabToken=REPLACE_ME_WITH_GITLAB_PRIVATE_TOKEN_OF_MIRROR_ACCOUNT # Groups repos csn be mirrored into on your gitlab instance -groupArray=(test1) +groupArray=(group1 group2 group3) # # Gitlab new project default settings. If a project needs to be created by @@ -24,12 +26,9 @@ 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 -#################### - +###################### ## SYSTEM VARIABLES ## - +###################### groupCount=${#groupArray[@]} gitmirrorsRepo=https://github.com/samrocketman/gitlab-mirrors.git - -#################### \ No newline at end of file