Debian Codegraph @

testscripts/run-nxproxy2nxagent-over-sockets

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