-
Notifications
You must be signed in to change notification settings - Fork 4
/
update-crosware-from-tar.sh
43 lines (37 loc) · 1.12 KB
/
update-crosware-from-tar.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
#!/usr/bin/env bash
#
# update crosware from a tarball
#
set -eu
set -o pipefail
function failexit() {
echo "${BASH_SOURCE[0]}: ${@}" 1>&2
exit 1
}
reqs=( 'tar' )
for req in ${reqs[@]} ; do
command -v ${req} >/dev/null 2>&1 || failexit "req ${req} not found"
done
: ${version:="master"}
: ${tarfile:="${version}.tgz"}
: ${vendor:="ryanwoodsmall"}
: ${project:="crosware"}
: ${tarurl:="https://github.com/${vendor}/${project}/tarball/${version}"}
: ${cwtop:="/usr/local/crosware"}
: ${cwtmp:="${cwtop}/tmp"}
if [ ! -e "${cwtmp}" ] ; then
mkdir -p "${cwtmp}" || failexit "could not ${cwtmp} or it does not exist"
fi
pushd "${cwtmp}"
rm -f "${tarfile}"
curl -fkLo "${tarfile}" "${tarurl}" || wget -O "${tarfile}" "${tarurl}"
extdir="$(tar -ztvf ${tarfile} | grep '/$' | awk '{print $NF}' | sort | grep ^${vendor}-${project}- | grep -v '/.*/' | head -1 || true)"
if [[ ! ${extdir} =~ ^${vendor}-${project}- ]] ; then
failexit "extraction directory '${extdir}' doesn't look right"
fi
rm -rf "${extdir}"
tar -zxf "${tarfile}"
( cd "${extdir}" ; tar -cf - . | ( cd "${cwtop}" ; tar -xvf - ) )
rm -f "${tarfile}"
rm -rf "${extdir}"
popd