nix

configuration files that power my machines
Log | Files | Refs | README | LICENSE

bum (837B)


      1 #!/usr/bin/env bash
      2 
      3 ENDPOINT="$(pass show bum/endpoint)"
      4 PROFILE="$(pass show bum/profile)"
      5 REGION="$(pass show bum/region)"
      6 
      7 BASE="$HOME/misc/mnt/puck"
      8 
      9 tailscale status >/dev/null 2>&1 || {
     10 	echo "tailscale not up" >&2
     11 	exit 1
     12 }
     13 
     14 bucket=$(
     15 	aws --profile "$PROFILE" --endpoint-url "$ENDPOINT" --region "$REGION" s3 ls 2>/dev/null |
     16 		awk '{print $NF}' |
     17 		while read -r b; do
     18 			mountpoint -q "$BASE/$b" 2>/dev/null &&
     19 				echo "$b (mounted)" || echo "$b"
     20 		done | fzf
     21 ) || exit 0
     22 bucket=${bucket% (mounted)}
     23 
     24 target="$BASE/$bucket"
     25 
     26 if mountpoint -q "$target"; then
     27 	fusermount3 -u "$target" && echo "unmounted $target"
     28 else
     29 	mkdir -p "$target"
     30 	geesefs \
     31 		--profile "$PROFILE" \
     32 		--endpoint "$ENDPOINT" \
     33 		--region "$REGION" \
     34 		--uid "$(id -u)" --gid "$(id -g)" \
     35 		"$bucket" "$target" &&
     36 		echo "mounted $bucket on $target"
     37 fi