.local/bin/fossil-update (view raw)
1#!/bin/sh
2
3SUDO=doas
4_fossil_co=$(fossil all ls -c | grep fossil) # fossil checkout location
5_ask_upgrade=1
6_ask_all=1
7_clean_build=0
8_make_jobs=8
9
10usage() {
11 echo "usage: fossil-update [OPTIONS]"
12 echo "options:"
13 echo " -y upgrade without asking"
14 echo " -a upgrade and turn off the fossil service(if it's running) without asking"
15 echo " -c clean build, run 'make distclean' before building"
16 echo " -h print this help message"
17}
18
19check_service() {
20 _fsl_pid=$(pgrep -u root -f "$(which fossil)") && export _fsl_pid
21 [ -n "$_fsl_pid" ] && {
22 [ "$_ask_all" -ne 0 ] && {
23 echo "fossil service is active. stop it? (Y/y)"
24 read -r _stop_fsl
25 case $_stop_fsl in
26 [Yy] ) stop_service && return 0
27 ;;
28 * ) echo "upgrade is not possible" && exit 2
29 ;;
30 esac
31 }
32 stop_service
33 }
34}
35
36stop_service() {
37 # i am using systemd service to run fossil server
38 $SUDO systemctl stop fossil
39}
40
41compile() {
42 echo "configuring..." && \
43 ./configure >/dev/null && \
44 echo "building..." && make -j "$_make_jobs" >/dev/null \
45 && echo "build done"
46}
47
48install() {
49 check_service
50 $SUDO make install >/dev/null && echo "upgrade done"
51 [ -n "$_fsl_pid" ] && echo "don't forget to enable fossil service back" \
52 || return 0
53}
54
55main() {
56 cd "$_fossil_co" || return
57 [ $_clean_build -gt 0 ] && {
58 echo "cleaning previous build"
59 [ -f Makefile ] && make distclean >/dev/null
60 }
61 fossil up trunk
62 [ $_ask_all -eq 0 ] || [ $_ask_upgrade -eq 0 ] && {
63 compile && install
64 exit
65 }
66 echo "upgrade? (Y/y)" && \
67 read -r _upgrade && \
68 case $_upgrade in
69 [Yy] ) compile && install
70 ;;
71 * ) exit 1
72 ;;
73 esac
74}
75
76while getopts yach opts
77do
78 case "$opts" in
79 y)
80 _ask_upgrade=0
81 ;;
82 a)
83 _ask_all=0
84 ;;
85 c)
86 _clean_build=1
87 ;;
88 h|*)
89 usage && exit 1
90 ;;
91 esac
92done
93
94main
95