Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Unit]
- Description=home storage folder
- After=remote-fs-pre.target
- After=network.target
- After=network-online.target
- Wants=network-online.target
- BindsTo=network-online.target
- Conflicts=umount.target
- Before=umount.target
- [Mount]
- What=//172.16.100.1/storage
- Where=/home/username/Shared/storage
- Type=cifs
- Options=noauto,x-systemd.automount,noexec,noperm,iocharset=utf8,uid=1000,gid=1000,credentials=/etc/share_creds/home_samba
- [Install]
- WantedBy=remote-fs.target
- #!/bin/bash
- while read -r line; do
- [[ "$line" =~ deactivating ]] && {
- /bin/systemctl stop home-username-Shared-storage.mount
- }
- done < <(LANG=en_US nmcli monitor)
- [Unit]
- Description=automounts home storage share
- Requires=NetworkManager.service home-connection-monitor.service
- [Automount]
- Where=/home/<username>/Shared/storage
- TimeoutIdleSec=301
- [Install]
- WantedBy=remote-fs.target
- [Unit]
- Description=home storage folder
- Requires=NetworkManager.service home-connection-monitor.service
- After=home-connection-monitor.service
- [Mount]
- What=//<local-share-ip>/storage
- Where=/home/<username>/Shared/storage
- Type=cifs
- Options=nofail,_netdev,noauto,iocharset=utf8,uid=<user_uid>,gid=<user_gid>,credentials=</path/to/file/with/credentials>
- ForceUnmount=yes
- LazyUnmount=yes
- TimeoutSec=5
- [Unit]
- Description=home connection monitor
- After=home-<username>-Shared-storage.automount
- Requires=NetworkManager.service home-<username>-Shared-storage.automount
- [Service]
- Type=simple
- ExecStart=/usr/local/bin/home-connection-monitor
- Restart=on-failure
- [Install]
- WantedBy=remote-fs.target
- #!/bin/bash
- host='<local-share-ip>'
- vpn_connection_name='<yor-vpn-connection-name>'
- test_internet_host='208.67.222.222' # к примеру, можно любой доступный только через интернет.
- connect_to_home()
- {
- printf '%sn' "$(date +"%d_%m_%Y %H:%M:%S") Trying connecting to ${host}" # Задел на будущее для создания лог файла
- until ping -W2 -c1 "${test_internet_host}" &>/dev/null; do
- ping -W1 -c1 "${host}" &>/dev/null && break
- sleep 1
- done
- ping -W1 -c1 "${host}" &>/dev/null && {
- printf "$(date +"%d_%m_%Y %H:%M:%S") Connection for ${host} [ \e[32m%s\e[m ]\n" 'established'
- return 0
- }
- until ping -W1 -c1 "${host}" &>/dev/null; do
- if nmcli con up "${vpn_connection_name}"; then
- if ping -W1 -c1 "${host}" &>/dev/null; then
- printf "$(date +"%d_%m_%Y %H:%M:%S") Connection for ${host} [ \e[32m%s\e[m ]\n" 'established'
- return 0
- fi
- else
- sleep 2
- fi
- done
- }
- connect_to_home && {
- while ping -W1 -c1 "${host}" &>/dev/null; do
- sleep 1
- done
- exit 1
- }
Add Comment
Please, Sign In to add comment