Update remote URLs
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
e1ce2ddd33
commit
44d001279c
1 changed files with 43 additions and 43 deletions
|
@ -2,8 +2,8 @@
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
[ ${BASH_VERSINFO[0]:-0} -lt 4 ] && {
|
[ ${BASH_VERSINFO[0]:-0} -lt 4 ] && {
|
||||||
echo "Bash too old, update to >=4.0"
|
echo "Bash too old, update to >=4.0"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
SYSTEM=$(uname -s | tr 'A-Z' 'a-z')
|
SYSTEM=$(uname -s | tr 'A-Z' 'a-z')
|
||||||
|
@ -11,18 +11,18 @@ SYSTEM=$(uname -s | tr 'A-Z' 'a-z')
|
||||||
FORCE=0
|
FORCE=0
|
||||||
typeset -A REPOS
|
typeset -A REPOS
|
||||||
REPOS=(
|
REPOS=(
|
||||||
[public]='git@github.com:Luzifer/cfg.git#master'
|
[public]='https://git.luzifer.io/luzifer/cfg.git#master'
|
||||||
[secret]='git@github.com:Luzifer/cfg-secret.git#master'
|
[secret]='https://git.luzifer.io/luzifer/cfg-secret.git#master'
|
||||||
)
|
)
|
||||||
|
|
||||||
# --- OPT parsing ---
|
# --- OPT parsing ---
|
||||||
|
|
||||||
while getopts "f" opt; do
|
while getopts "f" opt; do
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
f)
|
f)
|
||||||
FORCE=1
|
FORCE=1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
shift $((OPTIND - 1))
|
shift $((OPTIND - 1))
|
||||||
|
@ -31,52 +31,52 @@ shift $((OPTIND - 1))
|
||||||
# --- OPT parsing ---
|
# --- OPT parsing ---
|
||||||
|
|
||||||
if [ -e ${HOME}/bin/script_framework.sh ]; then
|
if [ -e ${HOME}/bin/script_framework.sh ]; then
|
||||||
source ${HOME}/bin/script_framework.sh
|
source ${HOME}/bin/script_framework.sh
|
||||||
else
|
else
|
||||||
function step() { echo "$@"; }
|
function step() { echo "$@"; }
|
||||||
function fatal() {
|
function fatal() {
|
||||||
echo "$@"
|
echo "$@"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function config() {
|
function config() {
|
||||||
git --git-dir="${HOME}/.cfg/${repo_name}" --work-tree="${HOME}" $@
|
git --git-dir="${HOME}/.cfg/${repo_name}" --work-tree="${HOME}" $@
|
||||||
}
|
}
|
||||||
|
|
||||||
for repo_name in "${!REPOS[@]}"; do
|
for repo_name in "${!REPOS[@]}"; do
|
||||||
clone_url=$(echo ${REPOS[$repo_name]} | cut -d '#' -f 1)
|
clone_url=$(echo ${REPOS[$repo_name]} | cut -d '#' -f 1)
|
||||||
branch=$(echo ${REPOS[$repo_name]} | cut -d '#' -f 2)
|
branch=$(echo ${REPOS[$repo_name]} | cut -d '#' -f 2)
|
||||||
|
|
||||||
step "Working on '${repo_name}' (remote: '${clone_url}', branch: '${branch}'..."
|
step "Working on '${repo_name}' (remote: '${clone_url}', branch: '${branch}'..."
|
||||||
|
|
||||||
# Clone repo if it's not already available
|
# Clone repo if it's not already available
|
||||||
if ! [ -d "${HOME}/.cfg/${repo_name}" ]; then
|
if ! [ -d "${HOME}/.cfg/${repo_name}" ]; then
|
||||||
git clone --bare "${clone_url}" --branch "${branch}" "${HOME}/.cfg/${repo_name}"
|
git clone --bare "${clone_url}" --branch "${branch}" "${HOME}/.cfg/${repo_name}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set basic git options for the repo
|
# Set basic git options for the repo
|
||||||
config config status.showUntrackedFiles no
|
config config status.showUntrackedFiles no
|
||||||
|
|
||||||
# Do not overwrite local changes
|
# Do not overwrite local changes
|
||||||
if (! config diff --exit-code 2>&1 >/dev/null) && [ ${FORCE} -eq 0 ]; then
|
if (! config diff --exit-code 2>&1 >/dev/null) && [ ${FORCE} -eq 0 ]; then
|
||||||
error "Repo '${repo_name}' has unsaved changes and force-flag is not set"
|
error "Repo '${repo_name}' has unsaved changes and force-flag is not set"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Refresh latest master
|
# Refresh latest master
|
||||||
config fetch -q origin ${branch} || { fatal "Failed to fetch '${repo_name}'"; }
|
config fetch -q origin ${branch} || { fatal "Failed to fetch '${repo_name}'"; }
|
||||||
|
|
||||||
# Apply latest master
|
# Apply latest master
|
||||||
COMMITS_AHEAD=$(config rev-list --left-right --count FETCH_HEAD...HEAD | awk '{ print $2 }')
|
COMMITS_AHEAD=$(config rev-list --left-right --count FETCH_HEAD...HEAD | awk '{ print $2 }')
|
||||||
if [ ${COMMITS_AHEAD} -gt 0 ]; then
|
if [ ${COMMITS_AHEAD} -gt 0 ]; then
|
||||||
echo "Local commits found, trying to rebase..."
|
echo "Local commits found, trying to rebase..."
|
||||||
config rebase FETCH_HEAD
|
config rebase FETCH_HEAD
|
||||||
else
|
else
|
||||||
echo "No local commits, resetting to remote master..."
|
echo "No local commits, resetting to remote master..."
|
||||||
config reset --hard FETCH_HEAD
|
config reset --hard FETCH_HEAD
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Update submodules
|
# Update submodules
|
||||||
config submodule update --init --recursive
|
config submodule update --init --recursive
|
||||||
done
|
done
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue