]> git.bochard.net Git - mysite.git/commitdiff
configured sync-works.sh
authorbochard <mail@bochard.net>
Sun, 6 Jul 2025 11:53:53 +0000 (19:53 +0800)
committerbochard <mail@bochard.net>
Sun, 6 Jul 2025 11:53:53 +0000 (19:53 +0800)
sync-works.sh
works-list.txt [new file with mode: 0644]

index 10ae0258de2924deec36c126f29028c605ef19e0..9788ecf648aa3a5bc59092f230fcac7230984e87 100755 (executable)
@@ -1,61 +1,64 @@
 #!/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'
-)
+RED='\033[0;31m'
+GREEN='\033[0;32m'
+YELLOW='\033[0;33m'
+BLUE='\033[0;34m'
+NC='\033[0m'
+
+declare -A works
+
+echo -e "${BLUE}Reading works-list.txt file...${NC}";
+while IFS=' ' read -r 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 -e "${BLUE}Checking and adding missing submodules in $tmpBase...${NC}"
+for work in "${!works[@]}"; do
+  tmpPath="$tmpBase/$works"
+  destPath="$worksBase/$works"
 
   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 -e "${BLUE}Adding submodule $work to $tmpBase...${NC}"
+    git submodule add -f "${works[$work]}" "$tmpPath"
+    echo -e "${GREEN}Submodule $work added successfully to $tmpPath.${NC}"
   else
-    echo "Submodule $submodule already exists in $tmpBase."
+    echo -e "${YELLOW}Submodule $work already exists in $tmpBase.${NC}"
   fi
 done
 
-echo "Uploading all submodules in $tmpBase to latest remote commits..."
+echo -e "${BLUE}Uploading all submodules in $tmpBase to latest remote commits...${NC}"
 git submodule update --remote --merge
-echo "Submodules has been successfully updated to latest remote commits."
+echo -e "${GREEN}Submodules has been successfully updated to latest remote commits.${NC}"
 
-echo "Synchronizing submodules content from $tmpBase to $worksBase..."
-for submodule in "${!submodules[@]}"; do
-  src="$tmpBase/$submodule"
-  dest="$worksBase/$submodule"
+echo -e "${BLUE}Synchronizing submodules content from $tmpBase to $worksBase...${NC}"
+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 -e "${GREEN}Synchronized submodule $work successfully.${NC}"
   else
-    echo "Warning: $src does not exist, skipping synchronization!"
+    echo -e "${RED}Warning: $src does not exist, skipping synchronization!${NC}"
   fi
 done
 
-echo "Staging changes in $worksBase..."
+echo -e "${BLUE}Staging changes in $worksBase...${NC}"
 git add "$worksBase/"
+echo -e "${GREEN}Changes staged.${NC}"
 
-echo "Committing changes..."
-git commit -m "Sync latest updates from submodules to works/ directory." || echo "Nothing to commit."
+echo -e "${BLUE}Committing changes...${NC}"
+if git commit -m "Sync latest updates from submodules to works/ directory."
+  echo -e "${GREEN}Changes committed.${NC}"
+else
+  echo -e "${RED}Nothing to commit.${NC}"
+fi
 
-echo "done."
\ No newline at end of file
+echo -e "${GREEN}done.${NC}"
\ 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