Guest User

Untitled

a guest
Aug 20th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. [Unit]
  2. Description=home storage folder
  3. After=remote-fs-pre.target
  4. After=network.target
  5. After=network-online.target
  6. Wants=network-online.target
  7. BindsTo=network-online.target
  8. Conflicts=umount.target
  9. Before=umount.target
  10.  
  11. [Mount]
  12. What=//172.16.100.1/storage
  13. Where=/home/username/Shared/storage
  14. Type=cifs
  15. Options=noauto,x-systemd.automount,noexec,noperm,iocharset=utf8,uid=1000,gid=1000,credentials=/etc/share_creds/home_samba
  16.  
  17. [Install]
  18. WantedBy=remote-fs.target
  19.  
  20. #!/bin/bash
  21. while read -r line; do
  22. [[ "$line" =~ deactivating ]] && {
  23. /bin/systemctl stop home-username-Shared-storage.mount
  24. }
  25. done < <(LANG=en_US nmcli monitor)
  26.  
  27. [Unit]
  28. Description=automounts home storage share
  29. Requires=NetworkManager.service home-connection-monitor.service
  30.  
  31. [Automount]
  32. Where=/home/<username>/Shared/storage
  33. TimeoutIdleSec=301
  34.  
  35. [Install]
  36. WantedBy=remote-fs.target
  37.  
  38. [Unit]
  39. Description=home storage folder
  40. Requires=NetworkManager.service home-connection-monitor.service
  41. After=home-connection-monitor.service
  42.  
  43. [Mount]
  44. What=//<local-share-ip>/storage
  45. Where=/home/<username>/Shared/storage
  46. Type=cifs
  47. Options=nofail,_netdev,noauto,iocharset=utf8,uid=<user_uid>,gid=<user_gid>,credentials=</path/to/file/with/credentials>
  48. ForceUnmount=yes
  49. LazyUnmount=yes
  50. TimeoutSec=5
  51.  
  52. [Unit]
  53. Description=home connection monitor
  54. After=home-<username>-Shared-storage.automount
  55. Requires=NetworkManager.service home-<username>-Shared-storage.automount
  56.  
  57. [Service]
  58. Type=simple
  59. ExecStart=/usr/local/bin/home-connection-monitor
  60. Restart=on-failure
  61.  
  62. [Install]
  63. WantedBy=remote-fs.target
  64.  
  65. #!/bin/bash
  66. host='<local-share-ip>'
  67. vpn_connection_name='<yor-vpn-connection-name>'
  68. test_internet_host='208.67.222.222' # к примеру, можно любой доступный только через интернет.
  69.  
  70. connect_to_home()
  71. {
  72. printf '%sn' "$(date +"%d_%m_%Y %H:%M:%S") Trying connecting to ${host}" # Задел на будущее для создания лог файла
  73. until ping -W2 -c1 "${test_internet_host}" &>/dev/null; do
  74. ping -W1 -c1 "${host}" &>/dev/null && break
  75. sleep 1
  76. done
  77. ping -W1 -c1 "${host}" &>/dev/null && {
  78. printf "$(date +"%d_%m_%Y %H:%M:%S") Connection for ${host} [ \e[32m%s\e[m ]\n" 'established'
  79. return 0
  80. }
  81. until ping -W1 -c1 "${host}" &>/dev/null; do
  82.  
  83. if nmcli con up "${vpn_connection_name}"; then
  84. if ping -W1 -c1 "${host}" &>/dev/null; then
  85. printf "$(date +"%d_%m_%Y %H:%M:%S") Connection for ${host} [ \e[32m%s\e[m ]\n" 'established'
  86. return 0
  87. fi
  88. else
  89. sleep 2
  90. fi
  91.  
  92. done
  93. }
  94.  
  95. connect_to_home && {
  96. while ping -W1 -c1 "${host}" &>/dev/null; do
  97. sleep 1
  98. done
  99. exit 1
  100. }
Add Comment
Please, Sign In to add comment