-
Notifications
You must be signed in to change notification settings - Fork 41
/
tarball_one_version.sh
executable file
·97 lines (74 loc) · 2.15 KB
/
tarball_one_version.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
#!/bin/sh
set -e
if [ "$(uname)" = 'Darwin' ]; then
find() { # for -xtype
gfind "$@" # brew install findutils
}
fi
usage()
{
cat <<EOF
1. Creates a complete git archive from HEAD
2. Removes all but the selected version from it
3. Moves that selected version one level up, to the top-level in the archive
Sample usage:
$0 v1.7.x/v1.7 [ v1.7 ]
Synopsis:
$0 directory/version_number optional_git_tag
The git tag is optional because most files are immutable. It's used by
some tests/.
EOF
exit 1
}
main()
{
{ [ "$#" -ge 1 ] && [ "$#" -le 2 ]; } || usage
local path; path=$(dirname "$1")
local ver; ver=$(basename "$1")
local archive_name=sof-bin-"$ver"
local git_tag="${2:-HEAD}"
local gittop; gittop="$(git rev-parse --show-toplevel)"
if test -e "$archive_name"; then
die "%s already exists\n" "$archive_name"
fi
set -x
# Start with a clean git archive
#
( set -e; local _pwd; _pwd=$(pwd)
cd "${gittop}" # git archive is painful like this
git archive -o "$_pwd"/_.tar --prefix="$archive_name"/ "$git_tag" "${gittop}"
)
tar xf _.tar; rm _.tar
# Save the selected version
rm -rf _selected_version; mkdir _selected_version
mv "$archive_name"/"$path"/*"$ver" _selected_version/
# Select ancillary files
( set -e
local _pwd; _pwd=$(pwd)
cd "${archive_name:?}"
rm -f README-before-1.7.md
mv install.sh README* LICENCE* Notice* "${_pwd}"/_selected_version/
)
# Delete everything else
rm -rf "${archive_name:?}"/* "${archive_name:?}"/.github/
# Restore the selected version
mv _selected_version/* "$archive_name"/
rmdir _selected_version
( set +x
if find "${archive_name}"/ -xtype l | grep -q . ; then
find "${archive_name}"/ -xtype l -exec file {} \;
die "Found some broken symbolic links\n"
fi
)
tar cfz "$archive_name".tar.gz "$archive_name"/
rm -r "${archive_name:?}"/
}
die()
{
>&2 printf '%s ERROR: ' "$0"
# We want die() to be usable exactly like printf
# shellcheck disable=SC2059
>&2 printf "$@"
exit 1
}
main "$@"