aboutsummaryrefslogtreecommitdiffstats
path: root/.local/bin/fossil-update
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/fossil-update')
-rwxr-xr-x.local/bin/fossil-update72
1 files changed, 38 insertions, 34 deletions
diff --git a/.local/bin/fossil-update b/.local/bin/fossil-update
index d724145..5ea4d1e 100755
--- a/.local/bin/fossil-update
+++ b/.local/bin/fossil-update
@@ -1,10 +1,11 @@
#!/bin/sh
SUDO=doas
-FOSSIL_CO=$(fossil all ls -c | grep fossil) # fossil checkout location
-ASK_UPGRADE=1
-ASK_ALL=1
-CLEAN_BUILD=0
+_fossil_co=$(fossil all ls -c | grep fossil) # fossil checkout location
+_ask_upgrade=1
+_ask_all=1
+_clean_build=0
+_make_jobs=8
usage() {
echo "usage: fossil-update [OPTIONS]"
@@ -16,20 +17,20 @@ usage() {
}
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
+ _fsl_pid=$(pgrep -u root -f "$(which fossil)") && export _fsl_pid
+ [ -n "$_fsl_pid" ] && {
+ [ "$_ask_all" -ne 0 ] && {
+ echo "fossil service is active. stop it? (Y/y)"
+ read -r _stop_fsl
case $_stop_fsl in
- [Yy] ) stop_service
+ [Yy] ) stop_service && return 0
;;
* ) echo "upgrade is not possible" && exit 2
;;
esac
- fi
- stop_service
- fi
+ }
+ stop_service
+ }
}
stop_service() {
@@ -40,46 +41,49 @@ stop_service() {
compile() {
echo "configuring..." && \
./configure >/dev/null && \
- echo "building..." && make -j8 >/dev/null && echo "build done"
+ echo "building..." && make -j "$_make_jobs" >/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"
+ [ -n "$_fsl_pid" ] && echo "don't forget to enable fossil service back" \
+ || return 0
}
main() {
- cd $FOSSIL_CO
- if (( $CLEAN_BUILD )); then
+ cd "$_fossil_co" || return
+ [ $_clean_build -gt 0 ] && {
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
+ [ $_ask_all -eq 0 ] || [ $_ask_upgrade -eq 0 ] && {
+ compile && install
+ exit
+ }
+ echo "upgrade? (Y/y)" && \
+ read -r _upgrade && \
+ case $_upgrade in
+ [Yy] ) compile && install
+ ;;
+ * ) exit 1
+ ;;
+ esac
}
-while getopts "acyh" opts
+while getopts yach opts
do
- case "${opts}" in
+ case "$opts" in
y)
- ASK_UPGRADE=0
+ _ask_upgrade=0
;;
a)
- ASK_ALL=0
+ _ask_all=0
;;
c)
- CLEAN_BUILD=1
+ _clean_build=1
;;
h|*)
usage && exit 1