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