Advertisement
J2897

[Cygwin] Deploy TightVNC

Feb 19th, 2015
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 7.08 KB | None | 0 0
  1. #!/bin/bash
  2. # Released under the GNU General Public License version 3 by J2897.
  3. set -e
  4.  
  5. #################### README #################### > BEGIN
  6. # Filename:     deploy-vnc.sh
  7. # Version:      1.4
  8. # SSH-PF:       https://db.tt/82fJYgdS
  9. # Latest:       https://pastebin.com/2WjW7jbc
  10. # Contact:      https://pastebin.com/message_compose?to=J2897
  11. #
  12. # Before executing this, ensure the line endings (EOL) are in Unix format,
  13. # otherwise "set" is shown as an "invalid option" and the script will fail. To
  14. # convert the EOL to Unix format in Notepad++, simply select Edit from the File Menu.
  15. #
  16. # This script is meant to be run remotely after deploying Cygwin and OpenSSH.
  17. # After change the port, and/or both passwords, just upload it to the server
  18. # and then execute it from your SSH client, e.g. PuTTY.
  19. #
  20. # Instead of opening a port in the firewall, you should use SSH Port Forwarding
  21. # to connect locally. If you enable SERVER_ADD_FIREWALL_EXCEPTION, the port won't
  22. # be open until you launch the TightVNC program on the server, even though the
  23. # service is already up and running perfectly fine. I have included code below
  24. # which will open the port. But you should only connect directly via the LAN when
  25. # testing. After testing, remove the entire firewall section of this code and add
  26. # the SET_LOOPBACKONLY option to the install options section. You can then
  27. # connect to the port securely by bypassing the firewall completely using SSH Port
  28. # Forwarding.
  29. #
  30. # To silently install the DFMirage Driver...
  31. # wget http://www.demoforge.com/tightvnc/dfmirage-setup-2.0.301.exe
  32. # chmod u+x "dfmirage-setup-2.0.301.exe"
  33. # cygstart "dfmirage-setup-2.0.301.exe" /verysilent
  34. #
  35. # A good VNC Client for Android which supports SSH tunneling...
  36. # https://play.google.com/store/apps/details?id=com.iiordanov.freebVNC
  37. #################### README #################### > END
  38.  
  39. PORT="5900"
  40. #--------------------------------------------------
  41. # Is wget installed?
  42. if !(cygcheck -cd wget | grep -q wget)
  43. then
  44.     echo Please install the \'wget\' package for Cygwin.
  45.     exit 1
  46. fi
  47. #--------------------------------------------------
  48. # Detect the Windows OS architecture.
  49. PF86=$(cygpath "$SYSTEMDRIVE\Program Files (x86)")
  50. if [ -d "$PF86" ]
  51. then
  52.     ARCHITECTURE="64bit"
  53. else
  54.     ARCHITECTURE="32bit"
  55. fi
  56. #--------------------------------------------------
  57. # Get the Site Version Numbers.
  58. SITE_VER_NUM="$(wget -q http://tightvnc.com/download.php -O - | grep -o '<h3>Download TightVNC for Windows.*</h3>' | awk '{print $2}' FS='(' | awk '{print $1}' FS=')' | awk '{print $2}')"
  59. #--------------------------------------------------
  60. # Select the appropriate Setup File.
  61. SETUP_FILE="tightvnc-$SITE_VER_NUM-gpl-setup-$ARCHITECTURE.msi"
  62. #--------------------------------------------------
  63. # Download the Setup File.
  64. echo Downloading...
  65. wget --output-document="$TMP/$SETUP_FILE" "http://www.tightvnc.com/download/$SITE_VER_NUM/$SETUP_FILE"
  66. #--------------------------------------------------
  67. # Set the TightVNC install options.
  68. OPTIONS="/quiet /norestart \
  69. ADDLOCAL=\"Server\" \
  70. SERVER_REGISTER_AS_SERVICE=1 \
  71. SET_RFBPORT=1 \
  72. VALUE_OF_RFBPORT=$PORT \
  73. SET_USEVNCAUTHENTICATION=1 \
  74. VALUE_OF_USEVNCAUTHENTICATION=1 \
  75. SET_PASSWORD=1 \
  76. VALUE_OF_PASSWORD=c0nn3cT \
  77. SET_USECONTROLAUTHENTICATION=1 \
  78. VALUE_OF_USECONTROLAUTHENTICATION=1 \
  79. SET_CONTROLPASSWORD=1 \
  80. VALUE_OF_CONTROLPASSWORD=C0nTr0l"
  81. # SET_ALLOWLOOPBACK=1
  82. # VALUE_OF_ALLOWLOOPBACK=1
  83. # SET_LOOPBACKONLY=1
  84. # VALUE_OF_LOOPBACKONLY=1
  85. #--------------------------------------------------
  86. # Install TightVNC.
  87. echo Deploying TightVNC...
  88. WIN_PATH_SF=$(cygpath --windows "$TMP/$SETUP_FILE")
  89. cygstart --wait msiexec.exe /i \"$WIN_PATH_SF\" $OPTIONS
  90. #--------------------------------------------------
  91. # Detect the Windows NT version.
  92. if (uname | grep -q "CYGWIN_NT-6.")
  93. then
  94.     OS_VERSION="Windows 7"
  95. elif (uname | grep -q "CYGWIN_NT-5.")
  96. then
  97.     OS_VERSION="Windows XP"
  98. fi
  99. #--------------------------------------------------
  100. # Punch a hole through Windows Firewall.
  101. # *** Don't use SERVER_ADD_FIREWALL_EXCEPTION because the port won't be open. ***
  102. # *** Close this port when you use SET_LOOPBACKONLY with SSH Port Forwarding. ***
  103. echo "Openning TCP port $PORT in Windows Firewall..."
  104. if [ "$OS_VERSION" = "Windows XP" ]
  105. then
  106.     netsh firewall add portopening protocol=TCP port=$PORT name=TightVNC
  107. elif [ "$OS_VERSION" = "Windows 7" ]
  108. then
  109.     netsh advfirewall firewall add rule name=TightVNC dir=in action=allow protocol=tcp localport=$PORT
  110. fi
  111. #--------------------------------------------------
  112. # Move the 'All Users' Start Menu entry to the 'User' Start Menu.
  113. ALLUSERS_7=$(cygpath "$ALLUSERSPROFILE\Microsoft\Windows\Start Menu\Programs\TightVNC")
  114. USER_7=$(cygpath "$APPDATA\Microsoft\Windows\Start Menu\Programs\TightVNC")
  115. ALLUSERS_XP=$(cygpath "$ALLUSERSPROFILE\Start Menu\Programs\TightVNC")
  116. USER_XP=$(cygpath "$USERPROFILE\Start Menu\Programs\TightVNC")
  117. if [ "$OS_VERSION" = "Windows 7" ]
  118. then
  119.     mv -f "$ALLUSERS_7" "$USER_7"
  120. elif [ "$OS_VERSION" = "Windows XP" ]
  121. then
  122.     mv -f "$ALLUSERS_XP" "$USER_XP"
  123. fi
  124. #--------------------------------------------------
  125. # Delete the Setup File.
  126. rm -f "$TMP/$SETUP_FILE"
  127. #--------------------------------------------------
  128. # End.
  129. echo Finished!
  130. exit 0
  131.  
  132.  
  133.  
  134. #--------------------------------------------------
  135. # All available options...
  136. # http://www.tightvnc.com/doc/win/TightVNC_2.7_for_Windows_Installing_from_MSI_Packages.pdf
  137.  
  138. # Install options:
  139.  
  140. VIEWER_ASSOCIATE_VNC_EXTENSION
  141. SERVER_REGISTER_AS_SERVICE
  142. SERVER_ADD_FIREWALL_EXCEPTION
  143. VIEWER_ADD_FIREWALL_EXCEPTION
  144. SERVER_ALLOW_SAS
  145.  
  146. # Server options:
  147.  
  148. SET_ACCEPTHTTPCONNECTIONS
  149. VALUE_OF_ACCEPTHTTPCONNECTIONS
  150.  
  151. SET_ACCEPTRFBCONNECTIONS
  152. VALUE_OF_ACCEPTRFBCONNECTIONS
  153.  
  154. SET_ALLOWLOOPBACK
  155. VALUE_OF_ALLOWLOOPBACK
  156.  
  157. SET_ALWAYSSHARED
  158. VALUE_OF_ALWAYSSHARED
  159.  
  160. SET_BLOCKLOCALINPUT
  161. VALUE_OF_BLOCKLOCALINPUT
  162.  
  163. SET_BLOCKREMOTEINPUT
  164. VALUE_OF_BLOCKREMOTEINPUT
  165.  
  166. SET_DISCONNECTACTION
  167. VALUE_OF_DISCONNECTACTION
  168.  
  169. SET_DISCONNECTCLIENTS
  170. VALUE_OF_DISCONNECTCLIENTS
  171.  
  172. SET_EXTRAPORTS
  173. VALUE_OF_EXTRAPORTS
  174.  
  175. SET_GRABTRANSPARENTWINDOWS
  176. VALUE_OF_GRABTRANSPARENTWINDOWS
  177.  
  178. SET_HTTPPORT
  179. VALUE_OF_HTTPPORT
  180.  
  181. SET_IPACCESSCONTROL
  182. VALUE_OF_IPACCESSCONTROL
  183.  
  184. SET_LOCALINPUTPRIORITY
  185. VALUE_OF_LOCALINPUTPRIORITY
  186.  
  187. SET_LOCALINPUTPRIORITYTIMEOUT
  188. VALUE_OF_LOCALINPUTPRIORITYTIMEOUT
  189.  
  190. SET_LOGLEVEL
  191. VALUE_OF_LOGLEVEL
  192.  
  193. SET_LOOPBACKONLY
  194. VALUE_OF_LOOPBACKONLY
  195.  
  196. SET_NEVERSHARED
  197. VALUE_OF_NEVERSHARED
  198.  
  199. SET_POLLINGINTERVAL
  200. VALUE_OF_POLLINGINTERVAL
  201.  
  202. SET_QUERYACCEPTONTIMEOUT
  203. VALUE_OF_QUERYACCEPTONTIMEOUT
  204.  
  205. SET_QUERYTIMEOUT
  206. VALUE_OF_QUERYTIMEOUT
  207.  
  208. SET_REMOVEWALLPAPER
  209. VALUE_OF_REMOVEWALLPAPER
  210.  
  211. SET_REPEATCONTROLAUTHENTICATION
  212. VALUE_OF_REPEATCONTROLAUTHENTICATION
  213.  
  214. SET_RFBPORT
  215. VALUE_OF_RFBPORT
  216.  
  217. SET_RUNCONTROLINTERFACE
  218. VALUE_OF_RUNCONTROLINTERFACE
  219.  
  220. SET_SAVELOGTOALLUSERSPATH
  221. VALUE_OF_SAVELOGTOALLUSERSPATH
  222.  
  223. SET_USEMIRRORDRIVER
  224. VALUE_OF_USEMIRRORDRIVER
  225.  
  226. # Password options:
  227.  
  228. SET_USECONTROLAUTHENTICATION
  229. VALUE_OF_USECONTROLAUTHENTICATION
  230.  
  231. SET_USEVNCAUTHENTICATION
  232. VALUE_OF_USEVNCAUTHENTICATION
  233.  
  234. SET_CONTROLPASSWORD
  235. VALUE_OF_CONTROLPASSWORD
  236.  
  237. SET_PASSWORD
  238. VALUE_OF_PASSWORD
  239.  
  240. SET_VIEWONLYPASSWORD
  241. VALUE_OF_VIEWONLYPASSWORD
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement