Also moved the templates out of this repository, and into the zimfw/install repo. This is a second big change after introducing the plugin mechanism. This makes installation and upgrading of Zim straightforward. Maybe the most important aspect of having the script in a single file is not having to manage "git repos inside git repos" (see #297), since the single file exists by itself and is not version-controlled (with git). I've implemented a two-stage sourcing of the file, so most of the file is only sourced when needed (namely when calling `zimfw` with any action other than `login-init`). The two-stage process is designed to avoid compromising the startup speed, which is our top priority. In an effort to help making the script maintainable, I've broken it into small ERB templates. This also adds the ability to pre-process the Zsh code with Ruby code. To build the script, use `make`.
61 lines
1.9 KiB
Plaintext
61 lines
1.9 KiB
Plaintext
# This runs in a new shell
|
|
DIR=${1}
|
|
URL=${2}
|
|
TYPE=${3}
|
|
REV=${4}
|
|
OPT=${5}
|
|
MODULE=${DIR:t}
|
|
CLEAR_LINE="\033[2K\r"
|
|
[[ ${OPT} != -q ]] && print -n "${CLEAR_LINE}Updating ${MODULE} …"
|
|
if ! cd ${DIR} 2>/dev/null; then
|
|
print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: Not installed%f"
|
|
return 1
|
|
fi
|
|
if [[ ${PWD} != $(command git rev-parse --show-toplevel 2>/dev/null) ]]; then
|
|
# Not in repo root. Will not try to update.
|
|
return 0
|
|
fi
|
|
if [[ ${URL} != $(command git config --get remote.origin.url) ]]; then
|
|
print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: URL does not match. Expected ${URL}. Will not try to update.%f"
|
|
return 1
|
|
fi
|
|
if [[ ${TYPE} == tag ]]; then
|
|
if [[ ${REV} == $(command git describe --tags --exact-match 2>/dev/null) ]]; then
|
|
[[ ${OPT} != -q ]] && print -P "${CLEAR_LINE}%F{green}✓%f ${MODULE}: Already up to date"
|
|
return 0
|
|
fi
|
|
fi
|
|
if ! ERR=$(command git fetch -pq origin ${REV} 2>&1); then
|
|
print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: Error (1)%f\n${ERR}"
|
|
return 1
|
|
fi
|
|
if [[ ${TYPE} == branch ]]; then
|
|
LOG_REV="${REV}@{u}"
|
|
else
|
|
LOG_REV=${REV}
|
|
fi
|
|
LOG=$(command git log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..${LOG_REV} 2>/dev/null)
|
|
if ! ERR=$(command git checkout -q ${REV} -- 2>&1); then
|
|
print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: Error (2)%f\n${ERR}"
|
|
return 1
|
|
fi
|
|
if [[ ${TYPE} == branch ]]; then
|
|
if ! OUT=$(command git merge --ff-only --no-progress -n 2>&1); then
|
|
print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: Error (3)%f\n${OUT}"
|
|
return 1
|
|
fi
|
|
# keep just first line of OUT
|
|
OUT=${OUT%%($'\n'|$'\r')*}
|
|
else
|
|
OUT="Updating to ${TYPE} ${REV}"
|
|
fi
|
|
[[ -n ${LOG} ]] && OUT="${OUT}\n${LOG}"
|
|
if ERR=$(command git submodule update --init --recursive -q 2>&1); then
|
|
if [[ ${OPT} != -q ]]; then
|
|
print -P "${CLEAR_LINE}%F{green}✓%f ${MODULE}: ${OUT}"
|
|
fi
|
|
else
|
|
print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: Error (4)%f\n${ERR}"
|
|
return 1
|
|
fi
|