===================================================================== Excited to bring V5 to life. This includes some BREAKING CHANGES to several aspects of ZSH-type scwrypts. Please refer to the readme for upgrade details (specifically docs/upgrade/v4-to-v5.md) --- New Features ------------------------- - ZSH testing library with basic mock capabilities - new scwrypts environment file format includes metadata and more advanced features like optional parent env overrides, selection inheritence, and improved structurual flexibility - speedup cache for non-CI runs of ZSH-type scwrypts - ${scwryptsmodule} syntax now allows a consistent unique-naming scheme for functions in ZSH-type scwrypts while providing better insight into origin of API calls in other modules - reusable, case-statement-driven argument parsers in ZSH-type scwrypts --- Changes ------------------------------ - several utility function renames in ZSH-type scwrypts to improve consistency - documentation comments included in ZSH libraries - ZSH-type scwrypts now allow library modules to live alongside executables (zsh/lib still supported; autodetection determines default) --- Bug Fixes ---------------------------- - hardened environment checking for REQUIRED_ENV variables; this removes the ability to overwrite variables in local function contexts
83 lines
2.3 KiB
Bash
Executable File
83 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env zsh
|
|
#####################################################################
|
|
|
|
use cloud/aws/cli
|
|
use cloud/aws/zshparse/overrides
|
|
|
|
DEPENDENCIES+=(jq mount sort sudo)
|
|
REQUIRED_ENV+=(AWS__EFS__LOCAL_MOUNT_POINT)
|
|
|
|
#####################################################################
|
|
|
|
USAGE__description='
|
|
interactively mount an AWS EFS volume to the local filesystem
|
|
'
|
|
|
|
#####################################################################
|
|
|
|
MAIN() {
|
|
local PARSERS=(cloud.aws.zshparse.overrides)
|
|
eval "$(utils.parse.autosetup)"
|
|
utils.io.getsudo || return 1
|
|
##########################################
|
|
|
|
{
|
|
mkdir -p -- "${AWS__EFS__LOCAL_MOUNT_POINT}" \
|
|
|| sudo mkdir -p -- "${AWS__EFS__LOCAL_MOUNT_POINT}"
|
|
} &>/dev/null
|
|
|
|
[ -d "${AWS__EFS__LOCAL_MOUNT_POINT}" ] \
|
|
|| echo.error "unable to create local mount point '${AWS__EFS__LOCAL_MOUNT_POINT}'" \
|
|
|| return
|
|
|
|
local FS_ID=$(\
|
|
$AWS efs describe-file-systems \
|
|
| jq -r '.[] | .[] | .FileSystemId' \
|
|
| utils.fzf 'select a filesystem to mount' \
|
|
)
|
|
[ ! ${FS_ID} ] && utils.abort
|
|
|
|
local MOUNT_POINT="${AWS__EFS__LOCAL_MOUNT_POINT}/${FS_ID}"
|
|
[ -d "${MOUNT_POINT}" ] && sudo rmdir "${MOUNT_POINT}" &>/dev/null
|
|
[ -d "${MOUNT_POINT}" ] && {
|
|
echo.status "${FS_ID} is already mounted"
|
|
return 0
|
|
}
|
|
|
|
local MOUNT_TARGETS=$($AWS efs describe-mount-targets --file-system-id ${FS_ID})
|
|
local ZONE=$(\
|
|
echo ${MOUNT_TARGETS} \
|
|
| jq -r '.[] | .[] | .AvailabilityZoneName' \
|
|
| sort -u | utils.fzf 'select availability zone'\
|
|
)
|
|
[ ! "${ZONE}" ] && utils.abort
|
|
|
|
local MOUNT_IP=$(\
|
|
echo ${MOUNT_TARGETS} \
|
|
| jq -r ".[] | .[] | select (.AvailabilityZoneName == \"${ZONE}\") | .IpAddress" \
|
|
| head -n1 \
|
|
)
|
|
|
|
echo.success 'ready to mount!'
|
|
echo.status "
|
|
file system id : ${FS_ID}
|
|
availability zone : ${ZONE}
|
|
file system ip : ${MOUNT_IP}
|
|
local mount point : ${MOUNT_POINT}
|
|
"
|
|
echo.reminder 'for private file-systems, you must be connected to the appropriate VPN'
|
|
Yn 'proceed?' || utils.abort
|
|
|
|
sudo mkdir -- "${MOUNT_POINT}" \
|
|
&& sudo mount \
|
|
-t nfs4 \
|
|
-o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport \
|
|
"${MOUNT_IP}:/" \
|
|
"${MOUNT_POINT}" \
|
|
&& echo.success "mounted at '${MOUNT_POINT}'" \
|
|
|| {
|
|
sudo rmdir -- "${MOUNT_POINT}" &>/dev/null
|
|
echo.error "unable to mount '${FS_ID}'"
|
|
}
|
|
}
|