2019-04-09 12:01:42 +00:00
|
|
|
#!/bin/bash
|
2020-08-22 12:40:53 +00:00
|
|
|
#
|
|
|
|
# s3fs - FUSE-based file system backed by Amazon S3
|
|
|
|
#
|
|
|
|
# Copyright 2007-2008 Randy Rizun <rrizun@gmail.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#
|
2019-04-09 12:01:42 +00:00
|
|
|
|
2016-02-05 12:24:13 +00:00
|
|
|
#### Test utils
|
|
|
|
|
|
|
|
set -o errexit
|
2019-07-03 05:31:48 +00:00
|
|
|
set -o pipefail
|
2016-02-05 12:24:13 +00:00
|
|
|
|
2022-01-15 17:08:46 +00:00
|
|
|
#
|
2016-02-05 12:24:13 +00:00
|
|
|
# Configuration
|
2022-01-15 17:08:46 +00:00
|
|
|
#
|
2016-02-05 12:24:13 +00:00
|
|
|
TEST_TEXT="HELLO WORLD"
|
|
|
|
TEST_TEXT_FILE=test-s3fs.txt
|
|
|
|
TEST_DIR=testdir
|
2022-01-15 17:08:46 +00:00
|
|
|
# shellcheck disable=SC2034
|
2016-02-05 12:24:13 +00:00
|
|
|
ALT_TEST_TEXT_FILE=test-s3fs-ALT.txt
|
2022-01-15 17:08:46 +00:00
|
|
|
# shellcheck disable=SC2034
|
2016-02-05 12:24:13 +00:00
|
|
|
TEST_TEXT_FILE_LENGTH=15
|
2022-01-15 17:08:46 +00:00
|
|
|
# shellcheck disable=SC2034
|
2016-02-05 12:24:13 +00:00
|
|
|
BIG_FILE=big-file-s3fs.txt
|
2022-01-15 17:08:46 +00:00
|
|
|
# shellcheck disable=SC2034
|
|
|
|
TEMP_DIR="${TMPDIR:-"/var/tmp"}"
|
|
|
|
|
2021-02-07 03:50:02 +00:00
|
|
|
# /dev/urandom can only return 32 MB per block maximum
|
|
|
|
BIG_FILE_BLOCK_SIZE=$((25 * 1024 * 1024))
|
|
|
|
BIG_FILE_COUNT=1
|
2022-01-15 17:08:46 +00:00
|
|
|
|
2021-02-07 03:50:02 +00:00
|
|
|
# This should be greater than the multipart size
|
2022-01-15 17:08:46 +00:00
|
|
|
# shellcheck disable=SC2034
|
|
|
|
BIG_FILE_LENGTH=$((BIG_FILE_BLOCK_SIZE * BIG_FILE_COUNT))
|
|
|
|
|
2021-06-20 10:27:25 +00:00
|
|
|
# Set locale because some tests check for English expressions
|
|
|
|
export LC_ALL=en_US.UTF-8
|
2016-02-05 12:24:13 +00:00
|
|
|
export RUN_DIR
|
|
|
|
|
2020-12-23 10:34:04 +00:00
|
|
|
# [NOTE]
|
|
|
|
# stdbuf, truncate and sed installed on macos do not work as
|
|
|
|
# expected(not compatible with Linux).
|
|
|
|
# Therefore, macos installs a brew package such as coreutils
|
|
|
|
# and uses gnu commands(gstdbuf, gtruncate, gsed).
|
|
|
|
# Set your PATH appropriately so that you can find these commands.
|
|
|
|
#
|
2022-01-15 17:08:46 +00:00
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
2020-12-23 10:34:04 +00:00
|
|
|
export STDBUF_BIN="gstdbuf"
|
|
|
|
export TRUNCATE_BIN="gtruncate"
|
|
|
|
export SED_BIN="gsed"
|
2021-05-06 13:52:54 +00:00
|
|
|
export BASE64_BIN="gbase64"
|
2019-07-03 05:12:59 +00:00
|
|
|
else
|
2020-12-23 10:34:04 +00:00
|
|
|
export STDBUF_BIN="stdbuf"
|
|
|
|
export TRUNCATE_BIN="truncate"
|
|
|
|
export SED_BIN="sed"
|
2021-05-06 13:52:54 +00:00
|
|
|
export BASE64_BIN="base64"
|
2019-07-03 05:12:59 +00:00
|
|
|
fi
|
2020-12-23 10:34:04 +00:00
|
|
|
export SED_BUFFER_FLAG="--unbuffered"
|
2019-07-03 05:12:59 +00:00
|
|
|
|
2023-09-24 09:32:07 +00:00
|
|
|
# [NOTE]
|
|
|
|
# Specifying cache disable option depending on stat(coreutils) version
|
|
|
|
# TODO: investigate why this is necessary #2327
|
|
|
|
#
|
2023-09-24 11:47:50 +00:00
|
|
|
if stat --cached=never / >/dev/null 2>&1; then
|
2023-09-24 09:32:07 +00:00
|
|
|
STAT_BIN=(stat --cache=never)
|
2023-09-24 11:47:50 +00:00
|
|
|
else
|
|
|
|
STAT_BIN=(stat)
|
2023-09-24 09:32:07 +00:00
|
|
|
fi
|
|
|
|
|
2019-07-03 09:54:01 +00:00
|
|
|
function get_xattr() {
|
2022-01-15 17:08:46 +00:00
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
2019-07-03 09:54:01 +00:00
|
|
|
xattr -p "$1" "$2"
|
|
|
|
else
|
|
|
|
getfattr -n "$1" --only-values "$2"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_xattr() {
|
2022-01-15 17:08:46 +00:00
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
2019-07-03 09:54:01 +00:00
|
|
|
xattr -w "$1" "$2" "$3"
|
|
|
|
else
|
|
|
|
setfattr -n "$1" -v "$2" "$3"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function del_xattr() {
|
2022-01-15 17:08:46 +00:00
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
2019-07-03 09:54:01 +00:00
|
|
|
xattr -d "$1" "$2"
|
|
|
|
else
|
|
|
|
setfattr -x "$1" "$2"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-09-10 03:50:18 +00:00
|
|
|
function get_inode() {
|
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
2023-09-24 09:32:07 +00:00
|
|
|
"${STAT_BIN[@]}" -f "%i" "$1"
|
2023-09-10 03:50:18 +00:00
|
|
|
else
|
2023-09-24 09:32:07 +00:00
|
|
|
"${STAT_BIN[@]}" --format "%i" "$1"
|
2023-09-10 03:50:18 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-08-21 01:19:25 +00:00
|
|
|
function get_size() {
|
2022-01-15 17:08:46 +00:00
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
2023-09-24 09:32:07 +00:00
|
|
|
"${STAT_BIN[@]}" -f "%z" "$1"
|
2019-08-21 01:19:25 +00:00
|
|
|
else
|
2023-09-24 09:32:07 +00:00
|
|
|
"${STAT_BIN[@]}" --format "%s" "$1"
|
2019-08-21 01:19:25 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_file_size() {
|
2022-01-09 04:03:36 +00:00
|
|
|
local FILE_NAME="$1"
|
|
|
|
local EXPECTED_SIZE="$2"
|
2019-08-21 01:19:25 +00:00
|
|
|
|
2024-10-14 09:31:37 +00:00
|
|
|
# Verify file length via metadata
|
2022-01-15 17:08:46 +00:00
|
|
|
local size
|
|
|
|
size=$(get_size "${FILE_NAME}")
|
|
|
|
if [ "${size}" -ne "${EXPECTED_SIZE}" ]
|
2019-08-21 01:19:25 +00:00
|
|
|
then
|
2024-10-14 09:31:37 +00:00
|
|
|
echo "error: expected ${FILE_NAME} to be ${EXPECTED_SIZE} length but was ${size} via metadata"
|
2019-08-21 01:19:25 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2024-10-14 09:31:37 +00:00
|
|
|
# Verify file length via data
|
|
|
|
# shellcheck disable=SC2002
|
|
|
|
size=$(cat "${FILE_NAME}" | wc -c)
|
2022-01-15 17:08:46 +00:00
|
|
|
if [ "${size}" -ne "${EXPECTED_SIZE}" ]
|
2019-08-21 01:19:25 +00:00
|
|
|
then
|
2024-10-14 09:31:37 +00:00
|
|
|
echo "error: expected ${FILE_NAME} to be ${EXPECTED_SIZE} length, got ${size} via data"
|
2019-08-21 01:19:25 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-02-05 12:24:13 +00:00
|
|
|
function mk_test_file {
|
2022-01-14 03:40:55 +00:00
|
|
|
if [ $# = 0 ]; then
|
2022-01-15 17:08:46 +00:00
|
|
|
local TEXT="${TEST_TEXT}"
|
2016-02-05 12:24:13 +00:00
|
|
|
else
|
2022-01-15 17:08:46 +00:00
|
|
|
local TEXT="$1"
|
2016-02-05 12:24:13 +00:00
|
|
|
fi
|
2022-01-15 17:08:46 +00:00
|
|
|
echo "${TEXT}" > "${TEST_TEXT_FILE}"
|
|
|
|
if [ ! -e "${TEST_TEXT_FILE}" ]
|
2016-02-05 12:24:13 +00:00
|
|
|
then
|
|
|
|
echo "Could not create file ${TEST_TEXT_FILE}, it does not exist"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function rm_test_file {
|
2022-01-14 03:40:55 +00:00
|
|
|
if [ $# = 0 ]; then
|
2022-01-15 17:08:46 +00:00
|
|
|
local FILE="${TEST_TEXT_FILE}"
|
2016-02-05 12:24:13 +00:00
|
|
|
else
|
2022-01-15 17:08:46 +00:00
|
|
|
local FILE="$1"
|
2016-02-05 12:24:13 +00:00
|
|
|
fi
|
2022-01-15 17:08:46 +00:00
|
|
|
rm -f "${FILE}"
|
2016-02-05 12:24:13 +00:00
|
|
|
|
2022-01-15 17:08:46 +00:00
|
|
|
if [ -e "${FILE}" ]
|
2016-02-05 12:24:13 +00:00
|
|
|
then
|
|
|
|
echo "Could not cleanup file ${TEST_TEXT_FILE}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function mk_test_dir {
|
2022-01-15 17:08:46 +00:00
|
|
|
mkdir "${TEST_DIR}"
|
2016-02-05 12:24:13 +00:00
|
|
|
|
2022-01-15 17:08:46 +00:00
|
|
|
if [ ! -d "${TEST_DIR}" ]; then
|
2016-02-05 12:24:13 +00:00
|
|
|
echo "Directory ${TEST_DIR} was not created"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function rm_test_dir {
|
2022-01-15 17:08:46 +00:00
|
|
|
rmdir "${TEST_DIR}"
|
|
|
|
if [ -e "${TEST_DIR}" ]; then
|
2016-02-05 12:24:13 +00:00
|
|
|
echo "Could not remove the test directory, it still exists: ${TEST_DIR}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create and cd to a unique directory for this test run
|
|
|
|
# Sets RUN_DIR to the name of the created directory
|
|
|
|
function cd_run_dir {
|
2022-01-15 17:08:46 +00:00
|
|
|
if [ "${TEST_BUCKET_MOUNT_POINT_1}" = "" ]; then
|
2021-02-10 19:44:44 +00:00
|
|
|
echo "TEST_BUCKET_MOUNT_POINT_1 variable not set"
|
2016-02-05 12:24:13 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2022-01-15 17:08:46 +00:00
|
|
|
local RUN_DIR="${TEST_BUCKET_MOUNT_POINT_1}/${1}"
|
|
|
|
mkdir -p "${RUN_DIR}"
|
|
|
|
cd "${RUN_DIR}"
|
2017-08-11 14:09:43 +00:00
|
|
|
}
|
2016-02-05 12:24:13 +00:00
|
|
|
|
|
|
|
function clean_run_dir {
|
2022-01-15 17:08:46 +00:00
|
|
|
if [ -d "${RUN_DIR}" ]; then
|
|
|
|
rm -rf "${RUN_DIR}" || echo "Error removing ${RUN_DIR}"
|
2016-02-05 12:24:13 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Resets test suite
|
|
|
|
function init_suite {
|
|
|
|
TEST_LIST=()
|
|
|
|
TEST_FAILED_LIST=()
|
|
|
|
TEST_PASSED_LIST=()
|
|
|
|
}
|
|
|
|
|
|
|
|
# Report a passing test case
|
|
|
|
# report_pass TEST_NAME
|
|
|
|
function report_pass {
|
|
|
|
echo "$1 passed"
|
2022-01-15 17:08:46 +00:00
|
|
|
TEST_PASSED_LIST+=("$1")
|
2016-02-05 12:24:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Report a failing test case
|
|
|
|
# report_fail TEST_NAME
|
|
|
|
function report_fail {
|
|
|
|
echo "$1 failed"
|
2022-01-15 17:08:46 +00:00
|
|
|
TEST_FAILED_LIST+=("$1")
|
2016-02-05 12:24:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Add tests to the suite
|
|
|
|
# add_tests TEST_NAME...
|
|
|
|
function add_tests {
|
|
|
|
TEST_LIST+=("$@")
|
|
|
|
}
|
|
|
|
|
|
|
|
# Log test name and description
|
|
|
|
# describe [DESCRIPTION]
|
|
|
|
function describe {
|
2019-04-09 12:01:42 +00:00
|
|
|
echo "${FUNCNAME[1]}: \"$*\""
|
2016-02-05 12:24:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Runs each test in a suite and summarizes results. The list of
|
|
|
|
# tests added by add_tests() is called with CWD set to a tmp
|
|
|
|
# directory in the bucket. An attempt to clean this directory is
|
|
|
|
# made after the test run.
|
|
|
|
function run_suite {
|
2022-01-15 17:08:46 +00:00
|
|
|
orig_dir="${PWD}"
|
|
|
|
key_prefix="testrun-${RANDOM}"
|
|
|
|
cd_run_dir "${key_prefix}"
|
2016-02-05 12:24:13 +00:00
|
|
|
for t in "${TEST_LIST[@]}"; do
|
2021-10-26 14:19:14 +00:00
|
|
|
# Ensure test input name differs every iteration
|
2022-02-23 13:59:21 +00:00
|
|
|
TEST_TEXT_FILE="test-s3fs-${RANDOM}.txt"
|
2022-01-15 17:08:46 +00:00
|
|
|
TEST_DIR="testdir-${RANDOM}"
|
2022-02-23 13:59:21 +00:00
|
|
|
# shellcheck disable=SC2034
|
|
|
|
ALT_TEST_TEXT_FILE="test-s3fs-ALT-${RANDOM}.txt"
|
|
|
|
# shellcheck disable=SC2034
|
|
|
|
BIG_FILE="big-file-s3fs-${RANDOM}.txt"
|
2022-07-16 17:13:06 +00:00
|
|
|
# The following sequence runs tests in a subshell to allow continuation
|
|
|
|
# on test failure, but still allowing errexit to be in effect during
|
|
|
|
# the test.
|
|
|
|
#
|
|
|
|
# See:
|
|
|
|
# https://groups.google.com/d/msg/gnu.bash.bug/NCK_0GmIv2M/dkeZ9MFhPOIJ
|
|
|
|
# Other ways of trying to capture the return value will also disable
|
|
|
|
# errexit in the function due to bash... compliance with POSIX?
|
|
|
|
set +o errexit
|
|
|
|
(set -o errexit; $t $key_prefix)
|
|
|
|
# shellcheck disable=SC2181
|
|
|
|
if [ $? == 0 ]; then
|
2022-01-15 17:08:46 +00:00
|
|
|
report_pass "${t}"
|
2016-02-05 12:24:13 +00:00
|
|
|
else
|
2022-01-15 17:08:46 +00:00
|
|
|
report_fail "${t}"
|
2016-02-05 12:24:13 +00:00
|
|
|
fi
|
2022-07-16 17:13:06 +00:00
|
|
|
set -o errexit
|
2016-02-05 12:24:13 +00:00
|
|
|
done
|
2022-01-15 17:08:46 +00:00
|
|
|
cd "${orig_dir}"
|
2016-02-05 12:24:13 +00:00
|
|
|
clean_run_dir
|
|
|
|
|
|
|
|
for t in "${TEST_PASSED_LIST[@]}"; do
|
2022-01-15 17:08:46 +00:00
|
|
|
echo "PASS: ${t}"
|
2016-02-05 12:24:13 +00:00
|
|
|
done
|
|
|
|
for t in "${TEST_FAILED_LIST[@]}"; do
|
2022-01-15 17:08:46 +00:00
|
|
|
echo "FAIL: ${t}"
|
2016-02-05 12:24:13 +00:00
|
|
|
done
|
|
|
|
|
2022-01-15 17:08:46 +00:00
|
|
|
local passed=${#TEST_PASSED_LIST[@]}
|
|
|
|
local failed=${#TEST_FAILED_LIST[@]}
|
2016-02-05 12:24:13 +00:00
|
|
|
|
2022-01-15 17:08:46 +00:00
|
|
|
echo "SUMMARY for $0: ${passed} tests passed. ${failed} tests failed."
|
2016-02-05 12:24:13 +00:00
|
|
|
|
2022-01-15 17:08:46 +00:00
|
|
|
if [[ "${failed}" != 0 ]]; then
|
2016-02-05 12:24:13 +00:00
|
|
|
return 1
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
2019-01-07 01:51:42 +00:00
|
|
|
|
|
|
|
function get_ctime() {
|
2023-05-30 09:52:55 +00:00
|
|
|
# ex: "1657504903.019784214"
|
2022-01-15 17:08:46 +00:00
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
2023-09-24 09:32:07 +00:00
|
|
|
"${STAT_BIN[@]}" -f "%Fc" "$1"
|
2019-01-07 01:51:42 +00:00
|
|
|
else
|
2023-09-24 09:32:07 +00:00
|
|
|
"${STAT_BIN[@]}" --format "%.9Z" "$1"
|
2019-01-07 01:51:42 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_mtime() {
|
2023-05-30 09:52:55 +00:00
|
|
|
# ex: "1657504903.019784214"
|
2022-01-15 17:08:46 +00:00
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
2023-09-24 09:32:07 +00:00
|
|
|
"${STAT_BIN[@]}" -f "%Fm" "$1"
|
2019-01-07 01:51:42 +00:00
|
|
|
else
|
2023-09-24 09:32:07 +00:00
|
|
|
"${STAT_BIN[@]}" --format "%.9Y" "$1"
|
2019-01-07 01:51:42 +00:00
|
|
|
fi
|
|
|
|
}
|
2020-08-01 10:29:17 +00:00
|
|
|
|
2020-10-03 02:14:23 +00:00
|
|
|
function get_atime() {
|
2023-05-30 09:52:55 +00:00
|
|
|
# ex: "1657504903.019784214"
|
2022-01-15 17:08:46 +00:00
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
2023-09-24 09:32:07 +00:00
|
|
|
"${STAT_BIN[@]}" -f "%Fa" "$1"
|
2020-10-03 02:14:23 +00:00
|
|
|
else
|
2023-09-24 09:32:07 +00:00
|
|
|
"${STAT_BIN[@]}" --format "%.9X" "$1"
|
2020-10-03 02:14:23 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-08-01 10:29:17 +00:00
|
|
|
function get_permissions() {
|
2022-01-15 17:08:46 +00:00
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
2023-09-24 09:32:07 +00:00
|
|
|
"${STAT_BIN[@]}" -f "%p" "$1"
|
2020-08-01 10:29:17 +00:00
|
|
|
else
|
2023-09-24 09:32:07 +00:00
|
|
|
"${STAT_BIN[@]}" --format "%a" "$1"
|
2023-09-25 15:04:24 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_user_and_group() {
|
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
|
|
|
stat -f "%u:%g" "$1"
|
|
|
|
else
|
|
|
|
"${STAT_BIN[@]}" --format "%u:%g" "$1"
|
2020-08-01 10:29:17 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-08-29 05:25:09 +00:00
|
|
|
function check_content_type() {
|
2022-01-15 17:08:46 +00:00
|
|
|
local INFO_STR
|
2023-08-15 12:23:59 +00:00
|
|
|
INFO_STR=$(aws_cli s3api head-object --bucket "${TEST_BUCKET_1}" --key "$1" | jq -r .ContentType)
|
|
|
|
if [ "${INFO_STR}" != "$2" ]
|
2019-08-29 05:25:09 +00:00
|
|
|
then
|
2023-08-15 12:23:59 +00:00
|
|
|
echo "Expected Content-Type: $2 but got: ${INFO_STR}"
|
|
|
|
return 1
|
2019-08-29 05:25:09 +00:00
|
|
|
fi
|
|
|
|
}
|
2019-08-01 23:09:34 +00:00
|
|
|
|
2019-09-07 06:23:05 +00:00
|
|
|
function get_disk_avail_size() {
|
2022-01-15 17:08:46 +00:00
|
|
|
local DISK_AVAIL_SIZE
|
|
|
|
DISK_AVAIL_SIZE=$(BLOCKSIZE=$((1024 * 1024)) df "$1" | awk '{print $4}' | tail -n 1)
|
|
|
|
echo "${DISK_AVAIL_SIZE}"
|
2019-09-07 06:23:05 +00:00
|
|
|
}
|
|
|
|
|
2019-08-01 23:09:34 +00:00
|
|
|
function aws_cli() {
|
2022-01-04 16:59:31 +00:00
|
|
|
local FLAGS=""
|
2020-05-24 02:43:12 +00:00
|
|
|
if [ -n "${S3FS_PROFILE}" ]; then
|
|
|
|
FLAGS="--profile ${S3FS_PROFILE}"
|
|
|
|
fi
|
2023-07-25 14:31:20 +00:00
|
|
|
|
|
|
|
if [ "$1" = "s3" ] && [ "$2" != "ls" ] && [ "$2" != "mb" ]; then
|
2023-09-03 13:03:45 +00:00
|
|
|
if s3fs_args | grep -q use_sse=custom; then
|
2023-07-25 14:31:20 +00:00
|
|
|
FLAGS="${FLAGS} --sse-c AES256 --sse-c-key fileb:///tmp/ssekey.bin"
|
|
|
|
fi
|
|
|
|
elif [ "$1" = "s3api" ] && [ "$2" != "head-bucket" ]; then
|
2023-09-03 13:03:45 +00:00
|
|
|
if s3fs_args | grep -q use_sse=custom; then
|
2023-07-25 14:31:20 +00:00
|
|
|
FLAGS="${FLAGS} --sse-customer-algorithm AES256 --sse-customer-key $(cat /tmp/ssekey) --sse-customer-key-md5 $(cat /tmp/ssekeymd5)"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-04-17 06:06:11 +00:00
|
|
|
# [NOTE]
|
|
|
|
# AWS_EC2_METADATA_DISABLED for preventing the metadata service(to 169.254.169.254).
|
2022-01-15 17:08:46 +00:00
|
|
|
# shellcheck disable=SC2086,SC2068
|
2022-04-21 12:58:18 +00:00
|
|
|
AWS_EC2_METADATA_DISABLED=true aws $@ --endpoint-url "${S3_URL}" --ca-bundle /tmp/keystore.pem ${FLAGS}
|
2019-08-01 23:09:34 +00:00
|
|
|
}
|
2020-08-22 12:40:53 +00:00
|
|
|
|
2021-01-04 14:32:04 +00:00
|
|
|
function wait_for_port() {
|
2022-01-15 17:08:46 +00:00
|
|
|
local PORT="$1"
|
|
|
|
for _ in $(seq 30); do
|
2021-01-04 14:32:04 +00:00
|
|
|
if exec 3<>"/dev/tcp/127.0.0.1/${PORT}";
|
|
|
|
then
|
|
|
|
exec 3<&- # Close for read
|
|
|
|
exec 3>&- # Close for write
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2021-02-20 13:20:46 +00:00
|
|
|
function make_random_string() {
|
|
|
|
if [ -n "$1" ]; then
|
2022-01-15 17:08:46 +00:00
|
|
|
local END_POS="$1"
|
2021-02-20 13:20:46 +00:00
|
|
|
else
|
2022-01-09 04:03:36 +00:00
|
|
|
local END_POS=8
|
2021-02-20 13:20:46 +00:00
|
|
|
fi
|
2023-06-25 10:11:36 +00:00
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
|
|
|
local BASE64_OPT="--break=0"
|
|
|
|
else
|
|
|
|
local BASE64_OPT="--wrap=0"
|
|
|
|
fi
|
|
|
|
"${BASE64_BIN}" "${BASE64_OPT}" < /dev/urandom 2>/dev/null | tr -d /+ | head -c "${END_POS}"
|
2021-05-06 13:52:54 +00:00
|
|
|
|
|
|
|
return 0
|
2021-02-20 13:20:46 +00:00
|
|
|
}
|
|
|
|
|
2023-09-03 13:03:45 +00:00
|
|
|
function s3fs_args() {
|
2023-06-25 10:11:36 +00:00
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
|
|
|
ps -o args -p "${S3FS_PID}" | tail -n +2
|
|
|
|
else
|
|
|
|
ps -o args -p "${S3FS_PID}" --no-headers
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# $1: sleep seconds
|
|
|
|
# $2: OS type(ex. 'Darwin', unset(means all os type))
|
|
|
|
#
|
|
|
|
# [NOTE] macos fuse-t
|
|
|
|
# macos fuse-t mounts over NFS, and the mtime/ctime/atime attribute
|
|
|
|
# values are in seconds(not m/u/n-sec).
|
|
|
|
# Therefore, unlike tests on other OSs, we have to wait at least 1
|
|
|
|
# second.
|
|
|
|
# This function is called primarily for this purpose.
|
|
|
|
#
|
|
|
|
function wait_ostype() {
|
|
|
|
if [ -z "$2" ] || uname | grep -q "$2"; then
|
|
|
|
if [ -n "$1" ] && ! (echo "$1" | grep -q '[^0-9]'); then
|
|
|
|
sleep "$1"
|
|
|
|
fi
|
|
|
|
fi
|
2023-09-03 13:03:45 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
#
|
|
|
|
# Local variables:
|
|
|
|
# tab-width: 4
|
|
|
|
# c-basic-offset: 4
|
|
|
|
# End:
|
2020-09-15 13:11:14 +00:00
|
|
|
# vim600: expandtab sw=4 ts=4 fdm=marker
|
|
|
|
# vim<600: expandtab sw=4 ts=4
|
2020-08-22 12:40:53 +00:00
|
|
|
#
|