From: bochard Date: Sun, 6 Jul 2025 11:53:53 +0000 (+0800) Subject: configured sync-works.sh X-Git-Url: https://git.bochard.net/?a=commitdiff_plain;h=055452505990ef330266e726cdbc0eac3e663f66;p=mysite.git configured sync-works.sh --- diff --git a/sync-works.sh b/sync-works.sh index 10ae025..9788ecf 100755 --- a/sync-works.sh +++ b/sync-works.sh @@ -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 index 0000000..5baa390 --- /dev/null +++ b/works-list.txt @@ -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