Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use variable for cvmfs_server command and check if sudo is required #167

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions scripts/ingest-tarball.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
repo=software.eessi.io
basedir=versions
decompress="gunzip -c"
cvmfs_server="cvmfs_server"
# list of supported architectures for compat and software layers
declare -A archs=(["aarch64"]= ["ppc64le"]= ["riscv64"]= ["x86_64"]=)
# list of supported operating systems for compat and software layers
Expand All @@ -40,6 +41,14 @@ function error() {
exit 1
}

function is_repo_owner() {
if [ -f "/etc/cvmfs/repositories.d/${repo}/server.conf" ]
then
. "/etc/cvmfs/repositories.d/${repo}/server.conf"
[ x"$(whoami)" = x"$CVMFS_USER" ]
fi
}

function check_repo_vars() {
if [ -z "${repo}" ]
then
Expand Down Expand Up @@ -104,8 +113,8 @@ function check_contents_type() {
function cvmfs_regenerate_nested_catalogs() {
# Use the .cvmfsdirtab to generate nested catalogs for the ingested tarball
echo "Generating the nested catalogs..."
cvmfs_server transaction "${repo}"
cvmfs_server publish -m "Generate catalogs after ingesting ${tar_file_basename}" "${repo}"
${cvmfs_server} transaction "${repo}"
${cvmfs_server} publish -m "Generate catalogs after ingesting ${tar_file_basename}" "${repo}"
ec=$?
if [ $ec -eq 0 ]
then
Expand All @@ -119,7 +128,7 @@ function cvmfs_ingest_tarball() {
# Do a regular "cvmfs_server ingest" for a given tarball,
# followed by regenerating the nested catalog
echo "Ingesting tarball ${tar_file} to ${repo}..."
${decompress} "${tar_file}" | cvmfs_server ingest -t - -b "${basedir}" "${repo}"
${decompress} "${tar_file}" | ${cvmfs_server} ingest -t - -b "${basedir}" "${repo}"
ec=$?
if [ $ec -eq 0 ]
then
Expand Down Expand Up @@ -185,16 +194,16 @@ function ingest_compat_tarball() {
then
echo_yellow "Compatibility layer for version ${version}, OS ${os}, and architecture ${arch} already exists!"
echo_yellow "Removing the existing layer, and adding the new one from the tarball..."
cvmfs_server transaction "${repo}"
${cvmfs_server} transaction "${repo}"
rm -rf "/cvmfs/${repo}/${basedir}/${version}/compat/${os}/${arch}/"
tar -C "/cvmfs/${repo}/${basedir}/" -xzf "${tar_file}"
cvmfs_server publish -m "update compat layer for ${version}, ${os}, ${arch}" "${repo}"
${cvmfs_server} publish -m "update compat layer for ${version}, ${os}, ${arch}" "${repo}"
ec=$?
if [ $ec -eq 0 ]
then
echo_green "Successfully ingested the new compatibility layer!"
else
cvmfs_server abort "${repo}"
${cvmfs_server} abort "${repo}"
error "error while updating the compatibility layer, transaction aborted."
fi
else
Expand Down Expand Up @@ -224,6 +233,9 @@ tar_first_file=$(tar tf "${tar_file}" | head -n 1)
tar_top_level_dir=$(echo "${tar_first_file}" | cut -d/ -f1)
tar_contents_type_dir=$(tar tf "${tar_file}" | head -n 2 | tail -n 1 | cut -d/ -f2)

# Check if we are running as the CVMFS repo owner, otherwise run cvmfs_server with sudo
is_repo_owner || cvmfs_server="sudo cvmfs_server"

# Do some checks, and ingest the tarball
check_repo_vars
check_version
Expand Down
Loading