aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorla-ninpre <leobrekalini@gmail.com>2021-04-30 00:00:33 +0300
committerla-ninpre <leobrekalini@gmail.com>2021-04-30 00:00:33 +0300
commitcb2b0581a1889e7d90bea7f56bb3b085f904b64e (patch)
tree3c02d35a236d9ece57f1bbaf2fb6731a9949c0e1
parentedb9e48d9b0f3f0276dee5b848e2dade85c7f8ec (diff)
downloaddotfiles-cb2b0581a1889e7d90bea7f56bb3b085f904b64e.tar.gz
dotfiles-cb2b0581a1889e7d90bea7f56bb3b085f904b64e.zip
fossil-update: major refactoring and additions
-rwxr-xr-x.local/bin/fossil-update86
1 files changed, 75 insertions, 11 deletions
diff --git a/.local/bin/fossil-update b/.local/bin/fossil-update
index 1067f4a..d724145 100755
--- a/.local/bin/fossil-update
+++ b/.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 ;;
- esac
+ 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
+