From 02055b8f6ed6f932ea0db98ba417d08e357a53b4 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Thu, 21 Sep 2023 01:27:28 +0200 Subject: [PATCH] MT#58014 encrypt: Avoid remove leading / messages from tar We are prepending an extra / to the pathnames passed to tar, and calling tar from a directory other than the root directory while not telling it to use absolute names so it complains about these two things with the following messages: ,--- tar: Removing leading `/' from member names tar: Removing leading `/' from hard link targets tar: Removing leading `//' from member names tar: Removing leading `//' from hard link targets `--- which is something the user cannot do much about, and it's rather annoying. Change-Id: I9e9c853f26363e451b8883d3c74c5508ba3049dc --- scripts/decrypt | 6 ++++-- scripts/encrypt | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/decrypt b/scripts/decrypt index 92e5af58..df551378 100755 --- a/scripts/decrypt +++ b/scripts/decrypt @@ -102,8 +102,10 @@ if ! gpg -d "${TARGZ}".gpg > "${TARGZ}" ; then log_error "Error while decrypting ${TARGZ}.gpg" RC=1 else - cd / # important to extract files at according place - if tar zxf "${TARGZ}" ; then + # For backwards compatibility we switch to the root directory, for old + # encrypted tarballs that stripped the leading /. + cd / + if tar zxPf "${TARGZ}" ; then log_info "Successfully restored configuration archive ${TARGZ}.gpg" log_info "Now you should be able to run 'ngcpcfg apply' again." else diff --git a/scripts/encrypt b/scripts/encrypt index 1edd145f..6e49b074 100755 --- a/scripts/encrypt +++ b/scripts/encrypt @@ -30,8 +30,8 @@ get_config_file_list() { # if the file does not exist (e.g. because "ngcpcfg apply" # hasn't been executed yet for whatever reason, then don't # report missing files, otherwise tar will complain - if [ -r "/${y}" ] ; then - echo "/${y}" + if [ -r "${y}" ] ; then + echo "${y}" fi done done @@ -61,7 +61,7 @@ fi TARGZ=/etc/ngcp-config-crypted.tgz -tar zcf "${TARGZ}" /etc/ngcp-config/ "${FILES[@]}" /etc/.git +tar zcPf "${TARGZ}" /etc/ngcp-config/ "${FILES[@]}" /etc/.git if gpg --symmetric "${TARGZ}" ; then log_info "Successfully created encrypted ngcpcfg configuration archive ${TARGZ}.gpg" # ensure we don't leave the unencrypted version behind