blob: 5ea4d1ec613107c812a26d3a75c1ca8038ab662a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#!/bin/sh
SUDO=doas
_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]"
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
[ -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 && return 0
;;
* ) echo "upgrade is not possible" && exit 2
;;
esac
}
stop_service
}
}
stop_service() {
# i am using systemd service to run fossil server
$SUDO systemctl stop fossil
}
compile() {
echo "configuring..." && \
./configure >/dev/null && \
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" \
|| return 0
}
main() {
cd "$_fossil_co" || return
[ $_clean_build -gt 0 ] && {
echo "cleaning previous build"
[ -f Makefile ] && make distclean >/dev/null
}
fossil up trunk
[ $_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 yach opts
do
case "$opts" in
y)
_ask_upgrade=0
;;
a)
_ask_all=0
;;
c)
_clean_build=1
;;
h|*)
usage && exit 1
;;
esac
done
main
|