-
Notifications
You must be signed in to change notification settings - Fork 1
/
nomadbsd-update.in
120 lines (99 loc) · 1.64 KB
/
nomadbsd-update.in
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/sh
. @PATH_CONFIG@
self_path="@SELF_PATH@"
bail()
{
echo $* >&2
exit 1
}
install_git()
{
if ! which git >/dev/null; then
pkg install -y "${git_pkg}" || bail "Failed to install ${git_pkg}"
fi
}
_git()
{
git $* || bail "git command failed"
}
git_pull()
{
local repo_dir=$1
(cd "${repo_dir}"; _git checkout ${main_branch}; _git pull)
}
get_last_local_commit()
{
(cd "${repo_dir}" && \
_git log -n 1 --pretty=format:%H origin/"${repo_branch}")
}
get_last_remote_commit()
{
_git ls-remote -h "${repo_url}" | \
grep "refs/heads/${repo_branch}" | cut -f 1
}
self_update_available()
{
local local_commit remote_commit
local_commit=$(get_last_local_commit)
remote_commit=$(get_last_remote_commit)
[ "${local_commit}" != "${remote_commit}" ]
}
install_self()
{
(cd "${repo_dir}" && make install) || bail "Failed to install ${repo_name}"
}
update_self()
{
install_git
[ ! -d "${repo_dir}" ] && _git clone "${repo_url}" "${repo_dir}"
if self_update_available; then
git_pull "${repo_dir}"
(cd "${repo_dir}" && _git checkout ${repo_branch})
install_self "${repo_dir}"
fi
}
#
# Make sure all components for the next stages are ready.
#
bootstrap()
{
return 0
}
do_update()
{
exit 0
}
usage()
{
echo "Usage: $(basename $0) [options] command"
echo "Options:"
echo "-h Show this message."
echo ""
echo "Commands:"
echo "update Run the update."
exit 1
}
self_updated=0
while [ $# -gt 0 ]; do
case "$1" in
-_)
self_updated=1
;;
-*)
usage
;;
update)
if [ ${self_updated} -ne 1 ]; then
update_self
exec ${self_path} -_ update
fi
bootstrap
do_update
;;
*)
usage
;;
esac
shift
done
usage