]> git.bochard.net Git - mysite.git/commitdiff
updated sync-works.sh to use git clone
authorbochard <mail@bochard.net>
Sun, 6 Jul 2025 03:42:38 +0000 (11:42 +0800)
committerbochard <mail@bochard.net>
Sun, 6 Jul 2025 03:42:38 +0000 (11:42 +0800)
sync-works.sh
works-list.txt [new file with mode: 0644]

index 10ae0258de2924deec36c126f29028c605ef19e0..a75e64fccac2c3a97bee196e62ad5f66477b9d16 100755 (executable)
@@ -1,52 +1,43 @@
 #!/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'
-  ['drum-ka-dum']='git@github.com:b0chard/drum-ka-dum.git'
-  ['tick-clock']='git@github.com:b0chard/tick-clock.git'
-  ['simple-cash-register']='git@github.com:b0chard/simple-cash-register.git'
-  ['circle']='git@github.com:b0chard/circle.git'
-  ['basic-calc']='git@github.com:b0chard/basic-calc.git'
-  ['signup-login-system']='git@github.com:b0chard/signup-login-system.git'
-  ['number-guessing-game-in-c']='git@github.com:b0chard/number-guessing-game-in-c.git'
-  ['rock-paper-scissors-in-c']='git@github.com:b0chard/rock-paper-scissors-in-c.git'
-  ['atm-program-in-c']='git@github.com:b0chard/atm-program-in-c.git'
-)
+declare -A works
+
+echo "Reading works-list.txt file...";
+while IFS=' ' read name url || [ -n "$name" ]; do
+  works[$name]="$url"
+done < works-list.txt
 
 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"
+echo "Cloning or updating repos in $tmpBase..."
+for work in "${!works[@]}"; do
+  tmpPath="$tmpBase/$work"
+  destPath="$worksBase/$work"
 
   if [ ! -d "$tmpPath" ]; then
-    echo "Adding submodule $submodule to $tmpBase..."
-    git submodule add -f "${submodules[$submodule]}" "$tmpPath"
-    echo "Submodule $submodule added successfully to $tmpPath."
+    echo "Cloning $work to $tmpBase..."
+    git clone "${works[$work]}" "$tmpPath"
+    echo "$work cloned successfully to $tmpPath."
   else
-    echo "Submodule $submodule already exists in $tmpBase."
+    echo "$work already exists in $tmpBase. Fetching and resetting to latest remote commit..."
+    branch=$(git -C "$tmpPath" rev-parse --abbrev-ref HEAD)
+    git -C "$tmpPath" fetch origin
+    git -C "$tmpPath" reset --hard "origin/$branch"
+    echo "$work updated to latest commit on $branch."
   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"
+echo "Synchronizing content from $tmpBase to $worksBase..."
+for work in "${!works[@]}"; do
+  src="$tmpBase/$work"
+  dest="$worksBase/$work"
 
   if [ -d "$src" ]; then
     mkdir -p "$dest"
     rsync -av --delete --exclude='.git' "$src/" "$dest/"
-    echo "Synchronized submodule $submodule successfully."
+    echo "Synchronized $work successfully."
   else
     echo "Warning: $src does not exist, skipping synchronization!"
   fi
@@ -55,7 +46,7 @@ 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 "Committing changes..."
+# git commit -m "Sync latest updates from $tmpBase to $worksBase directory." || echo "Nothing to commit."
 
 echo "done."
\ No newline at end of file
diff --git a/works-list.txt b/works-list.txt
new file mode 100644 (file)
index 0000000..5baa390
--- /dev/null
@@ -0,0 +1,12 @@
+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
+drum-ka-dum git@github.com:b0chard/drum-ka-dum.git
+tick-clock git@github.com:b0chard/tick-clock.git
+simple-cash-register git@github.com:b0chard/simple-cash-register.git
+circle git@github.com:b0chard/circle.git
+basic-calc git@github.com:b0chard/basic-calc.git
+signup-login-system git@github.com:b0chard/signup-login-system.git
+number-guessing-game-in-c git@github.com:b0chard/number-guessing-game-in-c.git
+rock-paper-scissors-in-c git@github.com:b0chard/rock-paper-scissors-in-c.git
+atm-program-in-c git@github.com:b0chard/atm-program-in-c.git
\ No newline at end of file