Skip to content

Instantly share code, notes, and snippets.

@sapslaj
Last active November 7, 2021 21:52
Show Gist options
  • Save sapslaj/a07d78178c495da39e491600fdeedf47 to your computer and use it in GitHub Desktop.
Save sapslaj/a07d78178c495da39e491600fdeedf47 to your computer and use it in GitHub Desktop.
complicatedly automount sshfs mounts
# /home/sapslaj/.config/systemd/user/automount-server.service
# sudo systemctl daemon-reload && systemctl --user enable --now automount-server.service
[Unit]
Description=automount sshfs
StartLimitIntervalSec=60
StartLimitBurst=4
[Service]
ExecStart=/home/sapslaj/.local/bin/automount_sshfs
Restart=on-failure
RestartSec=1
[Install]
WantedBy=default.target
#!/bin/bash -eux
# /home/sapslaj/.local/bin/automount_sshfs
set -o pipefail
SERVER=server
while :; do
if ! mount | grep -q "$SERVER:/"; then
if ping -c 1 "$SERVER"; then
fusermount -u "/run/media/$USER/$SERVER" || true
sudo mkdir -p "/run/media/$USER/$SERVER"
sudo chown "$USER:$USER" "/run/media/$USER/$SERVER"
sshfs "$SERVER:/" "/run/media/$USER/$SERVER"
fi
fi
sleep 300
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment