run-nxproxy2nxproxy 4.91 KB
Newer Older
1 2 3 4 5 6 7
#!/bin/bash

set -e

#/**************************************************************************/
#/*                                                                        */
#/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/.         */
8
#/* Copyright (c) 2015-2016 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>*/
9 10
#/*                                                                        */
#/* NXSCRIPTS, NX protocol compression and NX extensions to this software  */
11
#/* are copyright of the aforementioned persons and companies.             */
12
#/*                                                                        */
13 14 15
#/* Redistribution and use of the present software is allowed according    */
#/* to terms specified in the file LICENSE.nxcomp which comes in the       */
#/* source distribution.                                                   */
16 17 18
#/*                                                                        */
#/* All rights reserved.                                                   */
#/*                                                                        */
19 20 21 22 23
#/* NOTE: This software has received contributions from various other      */
#/* contributors, only the core maintainers and supporters are listed as   */
#/* copyright holders. Please contact us, if you feel you should be listed */
#/* as copyright holder, as well.                                          */
#/*                                                                        */
24 25 26 27 28 29 30 31
#/**************************************************************************/

#
# Uncomment this to enable echo.
#
# set -x
#

32
ulimit -c "unlimited"
33

34
NX_PORT="8"
35

36
NX_SYSTEM="${HOME}/.nx"
37

38
NX_ROOT="${HOME}/.nx"
39 40 41 42

mkdir -p "${NX_ROOT}"

#
43
# This should be randomly generated.
44 45
#

46 47
NX_COOKIE="$(xauth -n list |grep "${HOSTNAME}/unix:${NX_PORT}" | grep 'MIT' | cut -f '5' -d ' ' | head -n1)"
[[ -z "$NX_COOKIE" ]] && NX_COOKIE="$(mcookie)"
48 49 50 51 52

#
# Create the directories for the NX session.
#

53 54
rm -rf "${NX_ROOT}/C-${NX_PORT}" || exit
mkdir -p "${NX_ROOT}/C-${NX_PORT}" || exit
55

56 57
rm -rf "${NX_ROOT}/S-${NX_PORT}" || exit
mkdir -p "${NX_ROOT}/S-${NX_PORT}" || exit
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

#
# Set the path to libraries and NX executables.
#

LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${HOME}/NX/nxcomp:${HOME}/NX/nxcompext:${HOME}/NX/nx-X11/exports/lib"
export LD_LIBRARY_PATH

PATH="${PATH}:${HOME}/NX/nxclient/nxclient:${HOME}/NX/nx-X11/programs/Xserver/"
export PATH

#
# Create the fake cookie for this display.
#

73
echo "Creating the X authorization cookie."
74

75 76
xauth add "${HOSTNAME}/unix:${NX_PORT}" "MIT-MAGIC-COOKIE-1" "${NX_COOKIE}"
xauth add "${HOSTNAME}:${NX_PORT}" "MIT-MAGIC-COOKIE-1" "${NX_COOKIE}"
77 78 79 80 81 82 83

#
# Options are written in a file 'options' in the session
# directory. The agent will use the DISPLAY settings, so
# we pass in the DISPLAY the name of the options file.
#
# cache=8M,images=32M,link=modem,type=unix-kde,cleanup=0,
84
# accept=62.98.198.1,cookie=${NX_COOKIE},
85 86 87 88
# id=giulietta.nomachine.com-1098-6A4649FD0FCA57FAC275AF3F1C45B10F,
# media=1:1098
#

89 90
#NX_HOST="nx/nx,link=lan,pack=no-pack,keybd=1,samba=1,cups=1,limit=0,\
#accept=127.0.0.1,cookie=${NX_COOKIE},errors=${NX_ROOT}/C-${NX_PORT}/session"
91

92 93
#NX_HOST="nx/nx,link=lan,pack=16m-jpeg-9,keybd=1,samba=1,cups=1,limit=0,\
#accept=127.0.0.1,cookie=${NX_COOKIE},errors=${NX_ROOT}/C-${NX_PORT}/session"
94

95 96
#NX_HOST="nx/nx,cache=8192k,link=modem,keybd=1,samba=1,cups=1,limit=0,\
#connect=127.0.0.1,cookie=${NX_COOKIE},errors=${NX_ROOT}/C-${NX_PORT}/session"
97

98 99
NX_HOST="nx/nx,link=lan,pack=16m-jpeg-9,keybd=1,samba=1,cups=1,limit=0,\
accept=127.0.0.1,cookie=${NX_COOKIE},errors=${NX_ROOT}/C-${NX_PORT}/session"
100

101
echo "${NX_HOST}:${NX_PORT}" >"${NX_ROOT}/C-${NX_PORT}/options"
102 103 104 105 106

#
# Run the local proxy impersonating the X display.
#

107
echo "Running the X client side NX proxy."
108 109 110

#valgrind -v --num-callers=8 --error-limit=no --trace-children=no \
#valgrind --tool=memcheck --track-fds=yes \
111 112
nxproxy -C "nx/nx,options=${NX_ROOT}/C-${NX_PORT}/options:${NX_PORT}" \
2>>"${NX_ROOT}/C-${NX_PORT}/session" &
113 114 115 116 117 118 119 120 121

#
# The X server side proxy will forward the connection
# to the original DISPLAY.
#

#
# These are the nxproxy options used to run a typical session.
#
122
# cookie=${NX_COOKIE},root=/home/pinzari/.nx,media=32824,
123 124 125 126
# session=kde_on_giulietta,id=giulietta.nomachine.com-1098-6A4649FD0FCA57FAC275AF3F1C45B10F,
# connect=giulietta.nomachine.com:1098
#

127
NX_HOST="nx/nx,keybd=1,samba=1,cups=1,connect=localhost,cookie=${NX_COOKIE},errors=${NX_ROOT}/S-${NX_PORT}/session"
128

129
echo "${NX_HOST}:${NX_PORT}" >"${NX_ROOT}/S-${NX_PORT}/options"
130

131
echo "Running the X server side NX proxy."
132 133 134 135 136 137

#cachegrind -v --dumps=100000000 \
#cachegrind -v \
#valgrind -v --leak-check=yes --leak-resolution=high --show-reachable=yes \
#            --show-reachable=yes --suppressions=nxproxy/nxproxy.supp \
#            --weird-hacks=lax-ioctls --num-callers=8 --logfile-fd=2 \
138 139
nxproxy -S "nx/nx,options=${NX_ROOT}/S-${NX_PORT}/options:${NX_PORT}" \
2>>"${NX_ROOT}/S-${NX_PORT}/session" &
140

141
echo "Session running on display :${NX_PORT}."