Files
scripts/vaultwarden-backup-helpers/mount-smb.sh
2026-10-18 19:01:07 -07:00

42 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
# Copyright 2026 Umbra Tools (umbratools.com)
# SPDX-License-Identifier: Apache-2.0
# Mount the NetBackup SMB share so old backups can be pruned.
#
# Run as root via a NOPASSWD sudoers rule. The mount has to be done as root
# because /root/.smbcredentials is root-only.
#
# Install to /usr/local/sbin/vw-mount-smb owned by root, mode 755.
set -euo pipefail
MNT="/mnt/netbackup"
SMB_HOST="192.168.123.2"
SMB_SHARE="NetBackup"
CRED="/root/.smbcredentials"
if [ ! -f "$CRED" ]; then
echo "vw-mount-smb: credentials missing at ${CRED}" >&2
exit 1
fi
mkdir -p "$MNT"
if mountpoint -q "$MNT"; then
echo "vw-mount-smb: already mounted"
exit 0
fi
# Default to the invoking user's ids rather than hardcoding 1000.
uid="${SUDO_UID:-0}"
gid="${SUDO_GID:-0}"
mount -t cifs "//${SMB_HOST}/${SMB_SHARE}" "$MNT" \
-o "credentials=${CRED},iocharset=utf8,vers=3.0,uid=${uid},gid=${gid},file_mode=0666,dir_mode=0777"
if ! mountpoint -q "$MNT"; then
echo "vw-mount-smb: mount did not take effect" >&2
exit 1
fi