#!/bin/sh 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" } install() { 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 if (( $CLEAN_BUILD )); then echo "cleaning previous build" [ -f Makefile ] && make distclean >/dev/null fi fossil up trunk 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