From ca9a43c06c3b445ecd0123cdcf3ddf36ea0694e9 Mon Sep 17 00:00:00 2001 From: "nise.moe" Date: Wed, 6 Mar 2024 22:49:36 +0100 Subject: [PATCH] Added script to help with external github repos --- external-sync.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 external-sync.sh diff --git a/external-sync.sh b/external-sync.sh new file mode 100755 index 0000000..69390b1 --- /dev/null +++ b/external-sync.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +# Argument check and validation +if [ -z "$1" ]; then + echo "Error: Please provide an action (sync or create) and a folder name." + exit 1 +fi + +action="$1" +folder_to_sync="$2" +external_base_dir="../external-nise.moe" +external_dir="$external_base_dir/$folder_to_sync" + +# Validation +if [ -z "$folder_to_sync" ]; then + echo "Error: Please provide a folder name." +elif [ ! -d "$folder_to_sync" ]; then + echo "Error: Folder '$folder_to_sync' does not exist in the monorepo." + exit 1 +fi + +# Action Handling +if [ "$action" == "sync" ]; then + # Create external directory if needed + mkdir -p "$external_dir" + + # Synchronization using rsync + echo "Synchronizing files from '$folder_to_sync' to '$external_dir'..." + rsync -av --delete --exclude-from='.gitignore' --exclude='.git' "$folder_to_sync/" "$external_dir/" + + # Change directory for committing + cd "$external_dir" || { echo "Error: Failed to change directory to $external_dir"; exit 1; } + + # Git commit + git add . + git commit -S -am "$(date +%Y%m%d)" + + echo "Synchronization complete and changes committed." +elif [ "$action" == "create" ]; then + # Create external directory + mkdir -p "$external_dir" + + # Change directory (with error handling) + cd "$external_dir" || { echo "Error: Failed to change directory to $external_dir"; exit 1; } + + # Git Initialization + git init + git config user.email "162507023+nise-moe@users.noreply.github.com" + git config user.name "nise.moe" + git config gpg.format ssh + git config commit.gpgsign true + git config user.signingkey /home/anon/.ssh/nise-moe.pub + git branch -M main + git remote add origin git@github.com:nise-moe/"$folder_to_sync".git + + echo "External folder '$external_dir' created and initialized as a Git repository." + +else + echo "Error: Invalid action. Please choose 'sync' or 'create'." + exit 1 +fi \ No newline at end of file