-
Notifications
You must be signed in to change notification settings - Fork 6
/
create-tarball.sh
executable file
·95 lines (71 loc) · 2.56 KB
/
create-tarball.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
#!/bin/bash
# Create a tarball containing easybuild modules/software, compatibility layer
# files, or config files for ingestion into the CCR CVMFS software repository.
#
# This script assumes you've used start-container.sh to install software or
# create the overlay files.
# The tarball will be created with the following naming convention:
# ccr-<version>-{compat,easybuild,config}-[some tag]-<timestamp>.tar.gz
#
# This script was adopted from EESSI:
# https://github.com/EESSI/software-layer/blob/main/create_tarball.sh
set -e
function echo_green() {
echo -e "\e[32m$1\e[0m"
}
function echo_red() {
echo -e "\e[31m$1\e[0m"
}
function echo_yellow() {
echo -e "\e[33m$1\e[0m"
}
function fatal_error() {
echo_red "ERROR: $1" >&2
exit 1
}
if [[ $# -lt 2 ]]; then
fatal_error "Usage: $0 <compat|easybuild> </scratch/path/to/workdir>"
fi
content_type=$1
workdir=$2
# Check if the content-type is compat, easybuild, or config
if [ "${content_type}" != "compat" ] && [ "${content_type}" != "easybuild" ]
then
fatal_error "Content type should be either compat or easybuild"
fi
if [[ -z "$CCR_VERSION" ]]; then
fatal_error "Missing CCR_VERSION env variable."
fi
# Check if the CCR_VERSION number is valid, i.e. matches the format YYYY.DD
if ! echo "${CCR_VERSION}" | egrep -q '^20[0-9][0-9]\.(0[0-9]|1[0-2])$'
then
fatal_error "${CCR_VERSION} is not a valid CCR version."
fi
overlay_upper_dir="${workdir}/overlay-upper"
if [ ! -d ${overlay_upper_dir} ] && [ -d "${workdir}/cvmfs/soft.ccr.buffalo.edu" ]; then
overlay_upper_dir="${workdir}/cvmfs/soft.ccr.buffalo.edu"
fi
dir_overlay="${overlay_upper_dir}/versions/${CCR_VERSION}/${content_type}"
if [ ! -d ${dir_overlay} ]; then
fatal_error "CCR overlay directory ${dir_overlay} does not exist?!"
fi
tmpdir=`mktemp -d`
files_list=${tmpdir}/files.list.txt
cd ${overlay_upper_dir}/versions
echo ">> Collecting list of files/directories to include in tarball via ${PWD}..."
if [ -d ${CCR_VERSION}/${content_type} ]; then
find ${CCR_VERSION}/${content_type} -type f ! -path "*/.wh..wh..opq" >> ${files_list}
find ${CCR_VERSION}/${content_type} -type l >> ${files_list}
fi
if ! [ -s "${files_list}" ]; then
fatal_error "No files or directories found to inlcude in tarball?"
fi
outdir=`dirname $workdir`
tag=`basename $workdir`
ts=`date "+%Y-%m-%d.%H%M%S"`
target_tgz="${outdir}/ccr-${CCR_VERSION}-${content_type}-${tag}-${ts}.tar.gz"
echo ">> Creating tarball: ${target_tgz}"
tar cfz ${target_tgz} --files-from=${files_list}
echo ${target_tgz} created!
echo ">> Cleaning up tmpdir"
rm -r ${tmpdir}