qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

update_chibios_mirror.sh (3107B)


      1 #!/bin/bash
      2 
      3 ################################
      4 # Configuration
      5 
      6 # The ChibiOS branches to mirror
      7 chibios_branches="trunk stable_21.11.x"
      8 
      9 # The ChibiOS-Contrib branches to mirror
     10 contrib_branches="chibios-21.11.x"
     11 
     12 ################################
     13 # Actions
     14 
     15 set -eEuo pipefail
     16 umask 022
     17 
     18 this_script="$(realpath "${BASH_SOURCE[0]}")"
     19 script_dir="$(realpath "$(dirname "$this_script")")"
     20 qmk_firmware_dir="$(realpath "$script_dir/../")"
     21 chibios_dir="$qmk_firmware_dir/lib/chibios"
     22 contrib_dir="$qmk_firmware_dir/lib/chibios-contrib"
     23 
     24 chibios_git_location=$(realpath "$chibios_dir/$(cat "$chibios_dir/.git" | awk '/gitdir:/ {print $2}')")
     25 chibios_git_config=$(realpath "$chibios_git_location/config")
     26 contrib_git_location=$(realpath "$contrib_dir/$(cat "$contrib_dir/.git" | awk '/gitdir:/ {print $2}')")
     27 contrib_git_config=$(realpath "$contrib_git_location/config")
     28 
     29 cd "$chibios_dir"
     30 
     31 if [[ -z "$(cat "$chibios_git_config" | grep '\[svn-remote "svn"\]')" ]] ; then
     32     git svn init --stdlayout --prefix='svn/' https://svn.code.sf.net/p/chibios/code/
     33 fi
     34 
     35 if [[ -z "$(cat "$chibios_git_config" | grep '\[remote "qmk"\]')" ]] ; then
     36     git remote add qmk git@github.com:qmk/ChibiOS.git
     37     git remote set-url qmk git@github.com:qmk/ChibiOS.git --push
     38 else
     39     git remote set-url qmk git@github.com:qmk/ChibiOS.git
     40     git remote set-url qmk git@github.com:qmk/ChibiOS.git --push
     41 fi
     42 
     43 echo "Updating remotes..."
     44 git fetch --all --tags --prune
     45 
     46 echo "Ensure refs actually match up..."
     47 for branch in $chibios_branches ; do
     48     echo "Matching $branch..."
     49     git update-ref refs/remotes/svn/$branch refs/remotes/qmk/svn-mirror/$branch
     50 done
     51 
     52 echo "Fetching latest from subversion..."
     53 git svn fetch
     54 
     55 echo "Updating ChibiOS branches..."
     56 for branch in $chibios_branches ; do
     57     echo "Creating branch 'svn-mirror/$branch' from 'svn/$branch'..."
     58     git branch -f svn-mirror/$branch svn/$branch \
     59         && git push qmk svn-mirror/$branch
     60 done
     61 
     62 cd "$contrib_dir"
     63 
     64 if [[ -z "$(cat "$contrib_git_config" | grep '\[remote "qmk"\]')" ]] ; then
     65     git remote add qmk git@github.com:qmk/ChibiOS-Contrib.git
     66     git remote set-url qmk git@github.com:qmk/ChibiOS-Contrib.git --push
     67 else
     68     git remote set-url qmk git@github.com:qmk/ChibiOS-Contrib.git
     69     git remote set-url qmk git@github.com:qmk/ChibiOS-Contrib.git --push
     70 fi
     71 
     72 if [[ -z "$(cat "$contrib_git_config" | grep '\[remote "upstream"\]')" ]] ; then
     73     git remote add upstream git@github.com:ChibiOS/ChibiOS-Contrib.git
     74     git remote set-url upstream git@github.com:ChibiOS/ChibiOS-Contrib.git --push
     75 else
     76     git remote set-url upstream git@github.com:ChibiOS/ChibiOS-Contrib.git
     77     git remote set-url upstream git@github.com:ChibiOS/ChibiOS-Contrib.git --push
     78 fi
     79 
     80 echo "Updating remotes..."
     81 git fetch --all --tags --prune
     82 
     83 echo "Updating ChibiOS-Contrib branches..."
     84 for branch in $contrib_branches ; do
     85     echo "Creating branch 'mirror/$branch' from 'upstream/$branch'..."
     86     git branch -f mirror/$branch upstream/$branch \
     87         && git push qmk mirror/$branch || true # Allow for nonexistent ChibiOS-Contrib branches -- they'll turn up eventually.
     88 done