-
Notifications
You must be signed in to change notification settings - Fork 7
/
installer.sh
164 lines (140 loc) · 2.86 KB
/
installer.sh
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/sh
SCRIPTS="git-work git-base git-atomic git-test git-atomic-lib git-conditions-lib git-test-lib"
MANPAGES="git-work.1 git-base.1 git-atomic.1 git-test.1"
die()
{
echo "$*" 1>&2
exit 1
}
warn()
{
echo "$*" 1>&2
}
require_mkdir()
{
if test -d "$1"
then
mkdir -p "$1" || die "unable to make directory: \"$1\""
fi
}
clean_build()
{
if test -d build
then
rm -rf build && ! test -d build || die "clean failed"
fi
}
require_build()
{
require_mkdir build
}
make_package()
{
mkdir -p build/${VERSION}/libexec/git-core &&
mkdir -p build/${VERSION}/share/man/man1 || die "failed to make build directories"
for f in $SCRIPTS
do
TARGET="build/${VERSION}/libexec/git-core/$f" &&
cp git/${f}.sh "$TARGET" &&
chmod 0755 "$TARGET" || die "failed to copy $f"
done
for m in $MANPAGES
do
cp git/Documentation/$m build/${VERSION}/share/man/man1 || die "failed to copy $m"
done
cp installer.sh build/${VERSION}
pushd build 1>&2 &&
tar -cf - ${VERSION} | gzip -c > ${VERSION}.tar.gz || die "failed to create .tar.gz file"
echo build/${VERSION}.tar.gz
}
init_submodule()
{
git submodule init &&
git submodule update
}
require_git_exec_path()
{
EXECPATH=$(git --exec-path) &&
test -n "$EXECPATH" &&
test -d "$EXECPATH" &&
test -w "$EXECPATH" || die "\"$EXECPATH\" does not exist or is not a writeable directory"
MANDIR=$EXECPATH/../../share/man/man1
}
install()
{
(
cd $ROOT &&
require_git_exec_path &&
chmod 0755 $ROOT/libexec/git-core/$* &&
cp -p $ROOT/libexec/git-core/* ${EXECPATH} || die "failed to copy files to $EXECPATH"
warn gitwork installed to ${EXECPATH}
) || exit $?
}
install_man()
{
(
cd $ROOT &&
require_git_exec_path
require_mkdir "$MANDIR"
chmod 0644 $ROOT/share/man/man1/* &&
cp -p $ROOT/share/man/man1/* "${MANDIR}" || die "failed to copy files to \"$MANDIR\""
warn gitwork man pages installed to ${MANDIR}
) || exit $?
}
uninstall()
{
require_git_exec_path
for s in $SCRIPTS
do
if test -f ${EXECPATH}/$s
then
rm ${EXECPATH}/$s || die "unable to remove ${EXECPATH}/$s"
fi
done
for m in $MANPAGES
do
if test -f ${MANDIR}/$m
then
rm ${MANDIR}/$m || die "unable to remove ${MANDIR}/$m"
fi
done
warn gitwork uninstalled.
}
make_tar()
{
(
cd $ROOT &&
init_submodule &&
clean_build &&
require_build &&
pushd git/Documentation 1>&2 &&
make $MANPAGES 1>&2 &&
VERSION=$(git describe --tags) &&
popd 1>&2 &&
make_package ${VERSION}
) || exit $?
}
ROOT=$(cd $(dirname $0); pwd)
cmd=$1
test $# -gt 0 && shift
case "$cmd" in
install)
install "$@"
break;
;;
install-man)
install_man "$@"
break;
;;
make-tar)
make_tar "$@"
break;
;;
uninstall)
uninstall "$@"
break;
;;
*)
die "usage: ./installer.sh install|install-man|make-tar|uninstall";
;;
esac