]> git.bochard.net Git - mysite.git/commitdiff
bash script to automate getting content from submodules
authorbochard <mail@bochard.net>
Sat, 5 Jul 2025 13:24:42 +0000 (21:24 +0800)
committerbochard <mail@bochard.net>
Sat, 5 Jul 2025 13:24:42 +0000 (21:24 +0800)
.gitignore
sync-works.sh [new file with mode: 0755]

index 445383f5928333125085dc693a4a23b0789d5bfa..7dd37150bdd8c5b1458f70afa82e3efaf03599d2 100644 (file)
@@ -1 +1,3 @@
-robots.txt
\ No newline at end of file
+robots.txt
+works-tmp/
+.gitmodules
\ No newline at end of file
diff --git a/sync-works.sh b/sync-works.sh
new file mode 100755 (executable)
index 0000000..53e407d
--- /dev/null
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+declare -A submodules=(
+  ['roman-numeral-converter']='git@github.com:b0chard/roman-numeral-converter.git'
+  ['palindrome-checker']='git@github.com:b0chard/palindrome-checker.git'
+  ['temperature-converter']='git@github.com:b0chard/temperature-converter.git'
+)
+
+tmpBase='works-tmp'
+worksBase='works'
+
+mkdir -p "$tmpBase" "$worksBase"
+
+echo "Checking and adding missing submodules in $tmpBase..."
+for submodule in "${!submodules[@]}"; do
+  tmpPath="$tmpBase/$submodule"
+  destPath="$worksBase/$submodule"
+
+  if [ ! -d "$tmpPath" ]; then
+    echo "Adding submodule $submodule to $tmpBase..."
+    git submodule add -f "${submodules[$submodule]}" "$tmpPath"
+    echo "Submodule $submodule added successfully to $tmpPath."
+  else
+    echo "Submodule $submodule already exists in $tmpBase."
+  fi
+done
+
+echo "Uploading all submodules in $tmpBase to latest remote commits..."
+git submodule update --remote --merge
+echo "Submodules has been successfully updated to latest remote commits."
+
+echo "Synchronizing submodules content from $tmpBase to $worksBase..."
+for submodule in "${!submodules[@]}"; do
+  src="$tmpBase/$submodule"
+  dest="$worksBase/$submodule"
+
+  if [ -d "$src" ]; then
+    mkdir -p "$dest"
+    rsync -av --delete --exclude='.git' "$src/" "$dest/"
+    echo "Synchronized submodule $submodule successfully."
+  else
+    echo "Warning: $src does not exist, skipping synchronization!"
+  fi
+done
+
+echo "Staging changes in $worksBase..."
+git add "$worksBase/"
+
+echo "Committing changes..."
+git commit -m "Sync latest updates from submodules to works/ directory." || echo "Nothing to commit."
+
+echo "done."
\ No newline at end of file