SSH Config creation script, readme update

This commit is contained in:
2025-09-11 15:56:06 +09:00
parent 222cc2594d
commit a780df5422
3 changed files with 76 additions and 3 deletions

View File

@@ -8,6 +8,8 @@ the clone base for one campaign and a simple crontab script to pull data from th
- base_setup.sh: setup for the folder structure, users, etc
- new_clone.sh: Basic clone script
- git_sync.sh: The script to run in crontab, to sync the changes
- switch_branch.sh: Switch from one branch to the other
- create_ssh_config.sh: setup ssh key and ssh config entry
## Run commands
@@ -30,6 +32,14 @@ as is, if the folder exists it will only copy the scripts, will not alter or cha
Planned to get auto fixes for wrong ACL, etc or missing config settings
### SSH Key generation
A SSH Key has to be generated for each git respository that will be synced and the configuration has to be added to the ssh config file
```sh
create_ssh_config.sh [SSH Key name] [repo url full] ([jump proxy])
```
### new_clone.sh
Create a new clone
@@ -38,7 +48,7 @@ Create a new clone
new_clone.sh [repository] [branch] ([host]) ([remote name])
```
The [host] is the SSH Host name entry, this sill repalce any "[host]:" in the [repository]. If the [host] is not set the host set in the [repository] will be used. If nothing found the script will abort
The [host] is the SSH Host name entry, this will replace any "[host]:" in the [repository]. If the [host] is not set the host set in the [repository] will be used. If nothing found the script will abort
A [branch] name must be set all the time.

View File

@@ -0,0 +1,56 @@
#!/usr/bin/env bash
# <s> [SSH Key name] [repo url] ([Jump Proxy])
# ssh-keygen -t ed25519 -N "" -C "${repo_url}" -f "${ssh_key_name}"
# CONFIG
# Host <Repo name flattened>
# Hostname <host name>
# User git
# IdentityFile ~/.ssh/<pem key name>
# [ProxyJump <jump proxy>]
SSH_KEY_NAME="$1";
REPOSITORY="$2";
JUMP_PROXY="$3";
# below are only to skip error
BRANCH="-"
BASE_FOLDER=$(dirname "$(readlink -f "$0")")"/";
# shellcheck source=init.sh
. "${BASE_FOLDER}init.sh";
SSH_CONFIG_BASE="${GIT_WEBHOOK_BASE_FOLDER}.ssh/config/";
if [ -f "${SSH_CONFIG_BASE}${SSH_KEY_NAME}.pem" ]; then
echo "SSH Key: ${SSH_KEY_NAME} already exists";
error=1
fi;
if [[ "${REPOSITORY}" == *":"* ]]; then
REMOTE_HOST=$(echo "${REPOSITORY}" | cut -d ":" -f 1);
else
echo "[!] Must set a remote host for the repository";
error=1;
fi;
# if we have an ":" in the repository, split by it and replace it with the remote host
if [[ "${REPOSITORY}" == *":"* ]]; then
REPOSITORY=$(echo "${REPOSITORY}" | cut -d ":" -f 2);
fi;
GIT_REPOSITORY_NAME=$(basename "${REPOSITORY}" .git);
if ! grep "Host ${GIT_REPOSITORY_NAME}" "${SSH_CONFIG_BASE}config"; then
echo "[!] ssh config for ${GIT_REPOSITORY_NAME} already exists";
error=1
fi;
if [ $error -eq 1 ]; then
exit;
fi;
# SUDO_COMMAND= as base
# ssh-keygen -t ed25519 -N "" -C "${GIT_REPOSITORY_NAME}" -f "${SSH_CONFIG_BASE}${SSH_KEY_NAME}"
# must add ".pem" if key name does not end in .pem
# SSH_COMMAND=("${SUDO_COMMAND[@]}" "ssh-keygen" "-t" "ed25519" "-N" "" "-C" "${GIT_REPOSITORY_NAME}" "-f" "${SSH_CONFIG_BASE}${SSH_KEY_NAME}")
# __END__

View File

@@ -4,10 +4,13 @@
# DATE: 2025/6/27
# DESC: create a new basic clone
# COMMAND: new_clone.sh <Repo.git> <branch> [<host>] [<Repo Target Name>] [<remote name>]
REPOSITORY="$1";
BRANCH="$2";
REMOTE_HOST="$3";
REMOTE_NAME="$4";
REPOSITORY_FOLDER="$4"
REMOTE_NAME="$5";
if [ -z "${REMOTE_NAME}" ]; then
REMOTE_NAME="origin"
fi;
@@ -61,7 +64,11 @@ fi;
unique_id=$(uuidgen | tr -d '-' | head -c 8);
# strip .git from the repository path
GIT_REPOSITORY_NAME=$(basename "${REPOSITORY}" .git);
if [ -z "${REPOSITORY_FOLDER}" ]; then
GIT_REPOSITORY_NAME=$(basename "${REPOSITORY}" .git);
else
GIT_REPOSITORY_NAME="${REPOSITORY_FOLDER}";
fi;
# log folder target
LOG_FILE="${GIT_WEBHOOK_BASE_FOLDER}${LOG_FOLDER}${GIT_REPOSITORY_NAME}.log";
# from the repository get the last path without the .git so we have the target folder