| 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 |
### Adapt to your needs: NXAGENT_HOST, NXPROXY_HOST |
| 37 |
### |
| 38 |
### This script launches nxagent and has to be executed on the NXAGENT_HOST. |
| 39 |
### On the NXPROXY_HOST you will have to execute nxproxy by copy+pasting |
| 40 |
### some command lines... |
| 41 |
### |
| 42 |
### (Instructions for copy+pasting are given when this script has been launched). |
| 43 |
### |
| 44 |
NXAGENT_HOST="127.0.0.1" # (e.g., 192.168.1.1, this scripts is launched on the NXAGENT_HOST machine) |
| 45 |
NXPROXY_HOST="127.0.0.1" # (e.g., 192.168.1.2, you want to connect nxproxy -> nxagent from the NXPROXY_HOST machine) |
| 46 |
|
| 47 |
NX_PORT="9" |
| 48 |
|
| 49 |
NX_SYSTEM="${HOME}/.nx" |
| 50 |
|
| 51 |
NX_ROOT="${HOME}/.nx" |
| 52 |
|
| 53 |
# |
| 54 |
# This should be randomly generated. |
| 55 |
# |
| 56 |
#NX_COOKIE="$(xauth list |grep "${HOSTNAME}/unix:\<${NX_PORT}\>" | grep 'MIT' | cut -f '5' -d ' ')" |
| 57 |
NX_COOKIE="123efa980d2cba234ef6f73deac810ff" |
| 58 |
|
| 59 |
# |
| 60 |
# Create the directories for the NX session. |
| 61 |
# |
| 62 |
|
| 63 |
rm -rf "${NX_ROOT}/C-${NX_PORT}" || exit |
| 64 |
mkdir -p "${NX_ROOT}/C-${NX_PORT}" || exit |
| 65 |
|
| 66 |
rm -rf "${NX_ROOT}/S-${NX_PORT}" || exit |
| 67 |
mkdir -p "${NX_ROOT}/S-${NX_PORT}" || exit |
| 68 |
|
| 69 |
# |
| 70 |
# Set the path to libraries and NX executables. |
| 71 |
# |
| 72 |
|
| 73 |
LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${HOME}/NX/nxcomp:${HOME}/NX/nxcompext:${HOME}/NX/nx-X11/exports/lib" |
| 74 |
export LD_LIBRARY_PATH |
| 75 |
|
| 76 |
PATH="${PATH}:${HOME}/NX/nxclient/nxclient:${HOME}/NX/nx-X11/programs/Xserver/" |
| 77 |
export PATH |
| 78 |
|
| 79 |
# |
| 80 |
# Create the fake cookie for this display. |
| 81 |
# |
| 82 |
|
| 83 |
echo "Creating the X authorization cookie." |
| 84 |
|
| 85 |
xauth add "${NXPROXY_HOST}/unix:${NX_PORT}" "MIT-MAGIC-COOKIE-1" "${NX_COOKIE}" |
| 86 |
xauth add "${NXPROXY_HOST}:${NX_PORT}" "MIT-MAGIC-COOKIE-1" "${NX_COOKIE}" |
| 87 |
|
| 88 |
# |
| 89 |
# Options are written in a file 'options' in the session |
| 90 |
# directory. The agent will use the DISPLAY settings, so |
| 91 |
# we pass in the DISPLAY the name of the options file. |
| 92 |
# |
| 93 |
# cache=8M,images=32M,link=modem,type=unix-kde,cleanup=0, |
| 94 |
# accept=62.98.198.1,cookie=${NX_COOKIE}, |
| 95 |
# id=giulietta.nomachine.com-1098-6A4649FD0FCA57FAC275AF3F1C45B10F, |
| 96 |
# media=1:1098 |
| 97 |
# |
| 98 |
|
| 99 |
NX_HOST="nx/nx,cache=8192k,link=modem,menu=1,keybd=1,samba=0,cups=0,limit=0,\ |
| 100 |
accept=${NXPROXY_HOST},cookie=${NX_COOKIE},errors=${NX_ROOT}/C-${NX_PORT}/session" |
| 101 |
|
| 102 |
echo "${NX_HOST}:${NX_PORT}" >"${NX_ROOT}/C-${NX_PORT}/options" |
| 103 |
|
| 104 |
# |
| 105 |
# Run the agent. if you don't have a font server running, |
| 106 |
# remove the argument "-fp unix/:7100" |
| 107 |
# |
| 108 |
|
| 109 |
NX_AGENT=":${NX_PORT}" |
| 110 |
|
| 111 |
echo "Running the X client side NX agent." |
| 112 |
|
| 113 |
SAVED_DISPLAY="${DISPLAY}" |
| 114 |
|
| 115 |
DISPLAY="nx/nx,options=${NX_ROOT}/C-${NX_PORT}/options:${NX_PORT}" |
| 116 |
export DISPLAY |
| 117 |
|
| 118 |
#valgrind -v --num-callers=8 --error-limit=no --trace-children=no \ |
| 119 |
#valgrind --num-callers=8 --tool=memcheck --leak-check=yes --show-reachable=yes --track-fds=yes \ |
| 120 |
#ldd "${NXAGENTBIN}" |
| 121 |
"${NXAGENTBIN}" -name 'NX' -geometry "800x600+100+100" "${@}" \ |
| 122 |
"${NX_AGENT}" 2>>"${NX_ROOT}/C-${NX_PORT}/session" & |
| 123 |
|
| 124 |
# |
| 125 |
# The X server side proxy will forward the connection |
| 126 |
# to the original DISPLAY. |
| 127 |
# |
| 128 |
|
| 129 |
DISPLAY="${SAVED_DISPLAY}" |
| 130 |
export DISPLAY |
| 131 |
|
| 132 |
# |
| 133 |
# These are the nxproxy options used to run a typical session. |
| 134 |
# |
| 135 |
# cookie=${NX_COOKIE},root=/home/pinzari/.nx,media=32824, |
| 136 |
# session=kde_on_giulietta,id=giulietta.nomachine.com-1098-6A4649FD0FCA57FAC275AF3F1C45B10F, |
| 137 |
# connect=giulietta.nomachine.com:1098 |
| 138 |
# |
| 139 |
|
| 140 |
printf '\n%s\n\n' 'Now... COPY+PASTE the below lines to your local system' |
| 141 |
echo '--------------8<---------' |
| 142 |
|
| 143 |
#NX_HOST="nx/nx,keybd=1,samba=1,cups=1,connect=${NXAGENT_HOST},cookie=${NX_COOKIE},errors=${NX_ROOT}/S-${NX_PORT}/session" |
| 144 |
NX_HOST="nx/nx,keybd=1,samba=0,cups=0,connect=tcp:${NXAGENT_HOST}:4009,cookie=${NX_COOKIE},errors=${NX_ROOT}/S-${NX_PORT}/session" |
| 145 |
echo "NX_HOST=${NX_HOST}" |
| 146 |
|
| 147 |
echo "echo \"${NX_HOST}:${NX_PORT}\" >\"${NX_ROOT}/S-${NX_PORT}/options\"" |
| 148 |
|
| 149 |
echo "\"${NXPROXYBIN}\" -S \"nx/nx,options=${NX_ROOT}/S-${NX_PORT}/options:${NX_PORT}\" 2>>\"${NX_ROOT}/S-${NX_PORT}/session\"" |
| 150 |
printf '%s\n\n' '-------------->8---------' |