-
Notifications
You must be signed in to change notification settings - Fork 0
/
_mkdist
executable file
·61 lines (52 loc) · 1.17 KB
/
_mkdist
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
#!/bin/sh
# Make distribution tarball of current directory
# Version 20141211
PROGRAM="_mkdist"
WORKDIR=$(pwd)
DISTDIR=$(basename "${WORKDIR}")
TIMESTR=$(date +%Y%m%d%H%M%S)
ARCHIVE="${DISTDIR}.${TIMESTR}.tar.gz"
SLEEP=1
if test "${1}"
then
echo "${PROGRAM} - create tarball of working directory" >&2
exit 1
fi
err()
{
printf "\033[31mError:\033[0m ${1}\n" >&2
if test "${2}"
then
printf "\n%s\n\n" "${2}"
fi
exit 1
}
# Go level UP
cd .. || err "failed to cd to parent directory"
# Archiving
ARCHIVE="${DISTDIR}.$(date +%Y%m%d%H%M%S).tar.gz"
RESULT=$(tar cpzf "${ARCHIVE}" "${DISTDIR}" 2>&1)
STATUS=${?}
# Clip name
unset CLIPPED
if which xclip
then
printf "$(pwd)/${ARCHIVE}" | xclip
CLIPPED=" (xclipped)"
fi
if test ${STATUS} -eq 0
then
# Success
printf "\033[32mtarball created%s:\033[0m\n" "${CLIPPED}"
else
if tar -tf "${ARCHIVE}" >/dev/null 2>/dev/null
then
# Warning
printf "\033[33mincomplete archive created%s:\033[0m\n" "${CLIPPED}"
else
# Error
err "failed to create archive: ${ARCHIVE}" "${RESULT}"
rm -f "${ARCHIVE}"
fi
fi
test -f "${ARCHIVE}" && ls -l "${ARCHIVE}"