Debian Codegraph @

testscripts/run-nxproxy2nxproxy-over-sockets

raw
1 #!/bin/bash
2
3 set -e
4
5 #/**************************************************************************/
6 #/* */
7 #/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */
8 #/* Copyright (c) 2015-2016 Mike Gabriel <[email protected]>*/
9 #/* */
10 #/* NXSCRIPTS, NX protocol compression and NX extensions to this software */
11 #/* are copyright of the aforementioned persons and companies. */
12 #/* */
13 #/* Redistribution and use of the present software is allowed according */
14 #/* to terms specified in the file LICENSE.nxcomp which comes in the */
15 #/* source distribution. */
16 #/* */
17 #/* All rights reserved. */
18 #/* */
19 #/* NOTE: This software has received contributions from various other */
20 #/* contributors, only the core maintainers and supporters are listed as */
21 #/* copyright holders. Please contact us, if you feel you should be listed */
22 #/* as copyright holder, as well. */
23 #/* */
24 #/**************************************************************************/
25
26 #
27 # Uncomment this to enable echo.
28 #
29 set -x
30 #
31
32 ulimit -c "unlimited"
33
34 NX_PORT="6"
35
36 NX_SYSTEM="${HOME}/.nx"
37
38 NX_ROOT="${HOME}/.nx"
39
40 mkdir -p "${NX_ROOT}"
41
42 #
43 # This should be randomly generated.
44 #
45
46 NX_COOKIE="$(xauth -n list |grep "${HOSTNAME}/unix:${NX_PORT}" | grep 'MIT' | cut -f '5' -d ' ' | head -n1)"
47 [[ -z "$NX_COOKIE" ]] && NX_COOKIE="$(mcookie)"
48
49 #
50 # Create the directories for the NX session.
51 #
52
53 rm -rf "${NX_ROOT}/C-${NX_PORT}" || exit
54 mkdir -p "${NX_ROOT}/C-${NX_PORT}" || exit
55
56 rm -rf "${NX_ROOT}/S-${NX_PORT}" || exit
57 mkdir -p "${NX_ROOT}/S-${NX_PORT}" || exit
58
59 #
60 # Set the path to libraries and NX executables.
61 #
62
63 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${HOME}/NX/nxcomp:${HOME}/NX/nxcompext:${HOME}/NX/nx-X11/exports/lib"
64 export LD_LIBRARY_PATH
65
66 PATH="${PATH}:${HOME}/NX/nxclient/nxclient:${HOME}/NX/nx-X11/programs/Xserver/"
67 export PATH
68
69 #
70 # Create the fake cookie for this display.
71 #
72
73 echo "Creating the X authorization cookie."
74
75 xauth add "${HOSTNAME}/unix:${NX_PORT}" "MIT-MAGIC-COOKIE-1" "${NX_COOKIE}"
76 xauth add "${HOSTNAME}:${NX_PORT}" "MIT-MAGIC-COOKIE-1" "${NX_COOKIE}"
77
78 function urlencode() {
79 echo "$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$1")"
80 }
81
82 #
83 # Options are written in a file 'options' in the session
84 # directory. The agent will use the DISPLAY settings, so
85 # we pass in the DISPLAY the name of the options file.
86 #
87 # cache=8M,images=32M,link=modem,type=unix-kde,cleanup=0,
88 # accept=62.98.198.1,cookie=${NX_COOKIE},
89 # id=giulietta.nomachine.com-1098-6A4649FD0FCA57FAC275AF3F1C45B10F,
90 # media=1:1098
91 #
92
93 #NX_HOST="nx/nx,link=lan,pack=no-pack,keybd=1,samba=1,cups=1,limit=0,\
94 #accept=127.0.0.1,cookie=${NX_COOKIE},errors=${NX_ROOT}/C-${NX_PORT}/session"
95
96 #NX_HOST="nx/nx,link=lan,pack=16m-jpeg-9,keybd=1,samba=1,cups=1,limit=0,\
97 #accept=127.0.0.1,cookie=${NX_COOKIE},errors=${NX_ROOT}/C-${NX_PORT}/session"
98
99 #NX_HOST="nx/nx,cache=8192k,link=modem,keybd=1,samba=1,cups=1,limit=0,\
100 #connect=127.0.0.1,cookie=${NX_COOKIE},errors=${NX_ROOT}/C-${NX_PORT}/session"
101
102 #NX_HOST="nx/nx,link=lan,pack=16m-jpeg-9,keybd=1,samba=1,cups=1,limit=0,\
103 #accept=127.0.0.1,cookie=${NX_COOKIE},errors=${NX_ROOT}/C-${NX_PORT}/session"
104
105 NX_HOST="nx/nx,link=lan,pack=16m-jpeg-9,keybd=1,samba=1,cups=1,limit=0,\
106 listen=$(urlencode "unix:${NX_SYSTEM}/C-${NX_PORT}/proxy.socket"),cookie=${NX_COOKIE},errors=${NX_ROOT}/C-${NX_PORT}/session"
107
108 echo "${NX_HOST}:${NX_PORT}" >"${NX_ROOT}/C-${NX_PORT}/options"
109
110 #
111 # Run the local proxy impersonating the X display.
112 #
113
114 echo "Running the X client side NX proxy."
115
116 #valgrind -v --num-callers=8 --error-limit=no --trace-children=no \
117 #valgrind --tool=memcheck --track-fds=yes \
118 nxproxy -C "nx/nx,options=${NX_ROOT}/C-${NX_PORT}/options:${NX_PORT}" \
119 2>>"${NX_ROOT}/C-${NX_PORT}/session" &
120
121 #
122 # The X server side proxy will forward the connection
123 # to the original DISPLAY.
124 #
125
126 #
127 # These are the nxproxy options used to run a typical session.
128 #
129 # cookie=${NX_COOKIE},root=/home/pinzari/.nx,media=32824,
130 # session=kde_on_giulietta,id=giulietta.nomachine.com-1098-6A4649FD0FCA57FAC275AF3F1C45B10F,
131 # connect=giulietta.nomachine.com:1098
132 #
133
134 NX_HOST="nx/nx,keybd=1,samba=1,cups=1,connect=$(urlencode "unix:${NX_SYSTEM}/C-${NX_PORT}/proxy.socket"),cookie=${NX_COOKIE},errors=${NX_ROOT}/S-${NX_PORT}/session"
135
136 echo "${NX_HOST}:${NX_PORT}" >"${NX_ROOT}/S-${NX_PORT}/options"
137
138 echo "Running the X server side NX proxy."
139
140 #cachegrind -v --dumps=100000000 \
141 #cachegrind -v \
142 #valgrind -v --leak-check=yes --leak-resolution=high --show-reachable=yes \
143 # --show-reachable=yes --suppressions=nxproxy/nxproxy.supp \
144 # --weird-hacks=lax-ioctls --num-callers=8 --logfile-fd=2 \
145 nxproxy -S "nx/nx,options=${NX_ROOT}/S-${NX_PORT}/options:${NX_PORT}" \
146 2>>"${NX_ROOT}/S-${NX_PORT}/session" &
147
148 echo "Session running on display :${NX_PORT}."