fossil-update: major refactoring and additions
la-ninpre leobrekalini@gmail.com
Fri, 30 Apr 2021 00:00:33 +0300
1 files changed,
75 insertions(+),
11 deletions(-)
jump to
M
.local/bin/fossil-update
→
.local/bin/fossil-update
@@ -1,27 +1,91 @@
#!/bin/sh -FOSSIL_CO=$(fossil all ls -c | grep fossil) +SUDO=doas +FOSSIL_CO=$(fossil all ls -c | grep fossil) # fossil checkout location +ASK_UPGRADE=1 +ASK_ALL=1 +CLEAN_BUILD=0 + +usage() { + echo "usage: fossil-update [OPTIONS]" + echo "options:" + echo " -y upgrade without asking" + echo " -a upgrade and turn off the fossil service(if it's running) without asking" + echo " -c clean build, run 'make distclean' before building" + echo " -h print this help message" +} + +check_service() { + _fsl_pid=$(pgrep -u root -f $(which fossil)) && export _fsl_pid + if [[ -n $_fsl_pid ]]; then + if (( $ASK_ALL )); then + echo -n "fossil service is active. stop it? (Y/y) " + read _stop_fsl + case $_stop_fsl in + [Yy] ) stop_service + ;; + * ) echo "upgrade is not possible" && exit 2 + ;; + esac + fi + stop_service + fi +} + +stop_service() { + # i am using systemd service to run fossil server + $SUDO systemctl stop fossil +} compile() { echo "configuring..." && \ - ./configure >/dev/null && \ - echo "building..." && make -j8 >/dev/null && echo "build done" + ./configure >/dev/null && \ + echo "building..." && make -j8 >/dev/null && echo "build done" } install() { - doas cp fossil $(which fossil) && echo "upgrade done" + check_service + $SUDO make install >/dev/null && echo "upgrade done" + [[ -n $_fsl_pid ]] && echo "don't forget to enable fossil service back" } main() { cd $FOSSIL_CO - [ -f Makefile ] && make distclean >/dev/null + if (( $CLEAN_BUILD )); then + echo "cleaning previous build" + [ -f Makefile ] && make distclean >/dev/null + fi fossil up trunk - echo "Upgrade? (Y/y)" - read upgrade_true - case $upgrade_true in - [Yy] ) compile && install ;; - * ) exit 1 ;; + if (( $ASK_ALL )) && (( $ASK_UPGRADE )); then + echo -n "upgrade? (Y/y) " && \ + read _upgrade && \ + case $_upgrade in + [Yy] ) compile && install + ;; + * ) exit 1 + ;; + esac + fi + compile && install +} + +while getopts "acyh" opts +do + case "${opts}" in + y) + ASK_UPGRADE=0 + ;; + a) + ASK_ALL=0 + ;; + c) + CLEAN_BUILD=1 + ;; + h|*) + usage && exit 1 + ;; esac -} +done main +