-
Notifications
You must be signed in to change notification settings - Fork 75
/
X11rdp-o-matic.sh
executable file
·1061 lines (948 loc) · 31.4 KB
/
X11rdp-o-matic.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
set -e
# Automatic Xrdp/X11rdp Compiler/Installer
# a.k.a. ScaryGliders X11rdp-O-Matic
#
# Version 3.11
#
# Version release date : 20140927
########################(yyyyMMDD)
#
# Will run on Debian-based systems only at the moment. RPM based distros perhaps some time in the future...
#
# Copyright (C) 2012-2014, Kevin Cave <kevin@scarygliders.net>
# With contributions and suggestions from other kind people - thank you!
#
# ISC License (ISC)
#
# Permission to use, copy, modify, and/or distribute this software for any purpose with
# or without fee is hereby granted, provided that the above copyright notice and this
# permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
# AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
LINE="----------------------------------------------------------------------"
# Use the canonical git repo by default
XRDPGIT=https://github.com/neutrinolabs/xrdp.git
# Use the master branch by default
XRDPBRANCH=master
# Get list of available branches from remote git repository
get_branches()
{
echo $LINE
echo "Obtaining list of available branches..."
echo $LINE
BRANCHES=`git ls-remote --heads "$XRDPGIT" | cut -f2 | cut -d "/" -f 3`
echo $BRANCHES
echo $LINE
}
# If first switch = --help, display the help/usage message then exit.
if [ $1 = "--help" ]
then
clear
echo "usage: $0 OPTIONS
OPTIONS
-------
--help : show this help.
--justdoit : perform a complete compile and install with sane defaults and no user interaction.
--branch <branch> : use one of the available xrdp branches listed below...
Examples:
--branch v0.8 - use the 0.8 branch.
--branch master - use the master branch. <-- Default if no --branch switch used.
--branch devel - use the devel branch (Bleeding Edge - may not work properly!)
Branches beginning with "v" are stable releases.
The master branch changes when xrdp authors merge changes from the devel branch.
--nocpuoptimize : do not change X11rdp build script to utilize more than 1 of your CPU cores.
--cleanup : remove X11rdp / xrdp source code after installation. (Default is to keep it).
--noinstall : do not install anything, just build the packages
--nox11rdp : only build xrdp, do not build the x11rdp backend
--withjpeg : build jpeg module
(uses Independent JPEG Group's JPEG runtime library)
--withturbojpeg : build turbo jpeg module
(As used by TigerVNC and other users of the past TurboJPEG library)
--withsimplesound : build the simple pulseaudio interface
--withpulse : build code to load pulse audio modules
--withdebug : build with debug enabled
--withneutrino : build the neutrinordp module
--withkerberos : build support for kerberos
--withxrdpvr : build the xrdpvr module
--withnopam : don't include PAM support
--withpamuserpass : build with pam userpass support
--withfreerdp : build the freerdp1 module
"
get_branches
exit
fi
###########################################################
# Before doing anything else, check if we're running with #
# priveleges, because from here onwards we need to be. #
###########################################################
clear
id=`id -u`
if [ $id -ne 0 ]
then
clear
echo "You tried running the Scarygliders X11rdp-O-Matic installation script as a non-priveleged user. Please run as root."
exit 1
fi
# Install dialog if it's not already installed...
if [ ! -e /usr/bin/dialog ]
then
echo "Installing the dialog package..."
apt-get -y install dialog
fi
# Install lsb_release if it's not already installed...
if [ ! -e /usr/bin/lsb_release ]
then
echo "Installing the lsb_release package..."
apt-get -y install lsb-release
fi
# Install rsync if it's not already installed...
if [ ! -e /usr/bin/rsync ]
then
echo "Installing the rsync package..."
apt-get -y install rsync
fi
#################################################################
# Initialise variables and parse any command line switches here #
#################################################################
# check if the system is using systemd or not
[ -z "$(pidof systemd)" ] && \
USING_SYSTEMD=false || \
USING_SYSTEMD=true
# change dh_make option depending on if dh_make supports -y option
dh_make_y()
{
dh_make -h | grep -q -- -y && \
DH_MAKE_Y=true || DH_MAKE_Y=false
if $DH_MAKE_Y
then
dh_make -y $@
else
echo | dh_make $@
fi
}
# set LANG so that dpkg etc. return the expected responses so the script is
# guaranteed to work under different locales
export LANG="C"
# this is the release number for the Debian packages
RELEASE=1
TMPFILE=/tmp/xrdpver
X11DIR=/opt/X11rdp
ARCH=$( dpkg --print-architecture )
BASEDIR=$(dirname $(readlink -f $0))
# Would have used /tmp for this, but some distros I tried mount /tmp as tmpfs
# and filled up.
WORKINGDIR=$BASEDIR/work
PATCHDIR=$BASEDIR/patch
CONFIGUREFLAGS=(--prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-fuse)
# Declare a list of packages required to download sources/compile them...
REQUIREDPACKAGES=(build-essential checkinstall automake git
git-core libssl-dev libpam0g-dev zlib1g-dev libtool libx11-dev libxfixes-dev
pkg-config flex bison libxml2-dev intltool xsltproc xutils-dev python-libxml2
g++ xutils libfuse-dev wget libxrandr-dev libdrm-dev libpixman-1-dev
x11proto-xf86dri-dev
x11proto-video-dev
x11proto-resource-dev
x11proto-dmx-dev
x11proto-xf86dga-dev
x11proto-xinerama-dev
x11proto-render-dev
x11proto-bigreqs-dev
x11proto-kb-dev
x11proto-randr-dev
x11proto-gl-dev
x11proto-record-dev
x11proto-input-dev
x11proto-fixes-dev
x11proto-xf86vidmode-dev
x11proto-xext-dev
x11proto-scrnsaver-dev
x11proto-damage-dev
x11proto-xf86bigfont-dev
x11proto-composite-dev
x11proto-core-dev
x11proto-xcmisc-dev
x11proto-dri2-dev
x11proto-fonts-dev
libgl1-mesa-dev libxkbfile-dev libxfont-dev libpciaccess-dev dh-make gettext
xfonts-utils)
# libtool binaries are separated to libtool-bin package since Ubuntu 15.04
# if libtool-bin package exists, add it to REQUIREDPACKAGES
apt-cache search ^libtool-bin | grep -q libtool-bin && \
REQUIREDPACKAGES+=(libtool-bin)
DIST=`lsb_release -d -s`
# Check for running on supported/tested Distros...
SUPPORTED=false
while read i
do
if [ "$DIST" = "$i" ]
then
SUPPORTED=true
break
fi
done < SupportedDistros.txt
INTERACTIVE=true # Interactive by default.
PARALLELMAKE=true # Utilise all available CPU's for compilation by default.
CLEANUP=false # Keep the x11rdp and xrdp sources by default - to remove
# requires --cleanup command line switch
INSTALL_XRDP=true # Install xrdp and x11rdp on this system
BUILD_XRDP=true # Build and package x11rdp
BLEED=false # Not bleeding-edge unless specified
USE_TURBOJPEG=false # Turbo JPEG not selected by default
# Parse the command line for any arguments
while [ $# -gt 0 ]
do
case "$1" in
--justdoit)
INTERACTIVE=false # Don't bother with fancy schmancy dialogs, just go
# through and do everything!
# Note this will override even interactive Text Mode
echo "Okay, will just do the install from start to finish with no user interaction..."
echo $LINE
;;
--branch)
get_branches
ok=0
for check in ${BRANCHES[@]}
do
if [ "$check" = "$2" ]
then
ok=1
fi
done
if [ $ok -eq 0 ]
then
echo "**** Error detected in branch selection. Argument after --branch was : $2 ."
echo "**** Available branches : "$BRANCHES
exit 1
fi
XRDPBRANCH="$2"
echo "Using branch ==>> $2 <<=="
if [ "$XRDPBRANCH" = "devel" ]
then
echo "Note : using the bleeding-edge version may result in problems :)"
BLEED=true
fi
echo $LINE
shift
;;
--nocpuoptimize)
PARALLELMAKE=false
echo "Will not utilize additional CPU's for compilation..."
echo $LINE
;;
--cleanup)
CLEANUP=true
echo "Will remove the xrdp and x11rdp sources in the working directory after compilation/installation..."
echo $LINE
;;
--noinstall)
INSTALL_XRDP=false
echo "Will not install anything on the system but will build the packages"
echo $LINE
;;
--nox11rdp)
BUILD_XRDP=false
echo "Will not build and package x11rdp"
echo $LINE
;;
--withjpeg)
CONFIGUREFLAGS+=(--enable-jpeg)
REQUIREDPACKAGES+=(libjpeg8-dev)
;;
--withturbojpeg)
CONFIGUREFLAGS+=(--enable-tjpeg)
if [[ $XRDPBRANCH = "v0.8"* ]] # branch v0.8 has a hard-coded requirement for libjpeg-turbo to be in /opt
then
REQUIREDPACKAGES+=(nasm curl) # Need these for downloading and compiling libjpeg-turbo, later.
else
REQUIREDPACKAGES+=(libturbojpeg1 libturbojpeg1-dev) # The distro packages suffice for 0.9 onwards.
fi
USE_TURBOJPEG=true
;;
--withsimplesound)
CONFIGUREFLAGS+=(--enable-simplesound)
REQUIREDPACKAGES+=(libpulse-dev)
;;
--withpulse)
CONFIGUREFLAGS+=(--enable-loadpulsemodules)
REQUIREDPACKAGES+=(libpulse-dev)
;;
--withdebug)
CONFIGUREFLAGS+=(--enable-xrdpdebug)
;;
--withneutrino)
CONFIGUREFLAGS+=(--enable-neutrinordp)
;;
--withkerberos)
CONFIGUREFLAGS+=(--enable-kerberos)
;;
--withxrdpvr)
CONFIGUREFLAGS+=(--enable-xrdpvr)
REQUIREDPACKAGES+=(libavcodec-dev libavformat-dev)
;;
--withnopam)
CONFIGUREFLAGS+=(--disable-pam)
;;
--withpamuserpass)
CONFIGUREFLAGS+=(--enable-pamuserpass)
;;
--withfreerdp)
CONFIGUREFLAGS+=(--enable-freerdp1)
REQUIREDPACKAGES+=(libfreerdp-dev)
;;
esac
shift
done
let "HEIGHT = $LINES - 3"
let "WIDTH = $COLUMNS - 8"
echo "Using the following xrdp configuration : "$CONFIGUREFLAGS
echo $LINE
#############################################
# Common function declarations begin here...#
#############################################
# Display a message box
info_window()
{
dialog --backtitle "$backtitle" --title "$title" --msgbox "$dialogtext" 0 0
}
ask_question()
{
dialog --backtitle "$backtitle" --title "$questiontitle" --yesno "$dialogtext" 0 0
Answer=$?
}
apt_update_interactive()
{
apt-get update | dialog --progressbox "Updating package databases..." 30 100
}
# Installs a package
install_package_interactive()
{
debconf-apt-progress --dlwaypoint 50 -- apt-get -y install "$1"
}
download_xrdp_interactive()
{
[ -d "$WORKINGDIR/xrdp" ] ||
git clone --depth 1 "$XRDPGIT" -b "$XRDPBRANCH" "$WORKINGDIR/xrdp" 2>&1 | \
dialog --progressbox "Downloading xrdp source..." 30 100
}
download_xrdp_noninteractive()
{
echo "Downloading xrdp source from the GIT repository..."
[ -d "$WORKINGDIR/xrdp" ] ||
git clone --depth 1 "$XRDPGIT" -b "$XRDPBRANCH" "$WORKINGDIR/xrdp"
}
compile_X11rdp_interactive()
{
cd "$WORKINGDIR/xrdp/xorg/X11R7.6/"
(sh buildx.sh "$X11DIR") 2>&1 | dialog --progressbox "Compiling and installing X11rdp. This will take a while...." 30 100
}
compile_X11rdp_noninteractive()
{
cd "$WORKINGDIR/xrdp/xorg/X11R7.6/"
sh buildx.sh "$X11DIR" && :
RC=$?
if [ $RC -ne 0 ]; then
echo "error building X11rdp"
exit $RC
fi
}
package_X11rdp_noninteractive()
{
PKGDEST="$WORKINGDIR/packages/x11rdp"
if [ ! -e "$PKGDEST" ]; then
mkdir -p "$PKGDEST"
fi
if $BLEED
then
cd "$WORKINGDIR/xrdp/xorg/debuild"
./debX11rdp.sh "$VERSION" "$RELEASE" "$X11DIR" "$PKGDEST"
else
mkdir -p "$WORKINGDIR/xrdp/xorg/debuild/x11rdp-files/DEBIAN"
cp "$BASEDIR/debian/x11rdp_control" "$WORKINGDIR/xrdp/xorg/debuild/x11rdp-files/DEBIAN/control"
cp -a "$BASEDIR/debian/x11rdp_postinst" "$WORKINGDIR/xrdp/xorg/debuild/x11rdp-files/DEBIAN/postinst"
cd "$WORKINGDIR/xrdp/xorg/debuild"
PACKDIR=x11rdp-files
DESTDIR="$PACKDIR/opt"
NAME=x11rdp
sed -i -e "s/DUMMYVERINFO/$VERSION-$RELEASE/" "$PACKDIR/DEBIAN/control"
sed -i -e "s/DUMMYARCHINFO/$ARCH/" "$PACKDIR/DEBIAN/control"
# need a different delimiter, since it has a path
sed -i -e "s,DUMMYDIRINFO,$X11DIR," "$PACKDIR/DEBIAN/postinst"
mkdir -p "$DESTDIR"
cp -Rf "$X11DIR" "$DESTDIR"
dpkg-deb --build "$PACKDIR" "$PKGDEST/${NAME}_$VERSION-${RELEASE}_${ARCH}.deb"
XORGPKGNAME="${NAME}_$VERSION-${RELEASE}_${ARCH}.deb"
# revert to initial state
rm -rf "$DESTDIR"
sed -i -e "s/$VERSION-$RELEASE/DUMMYVERINFO/" "$PACKDIR/DEBIAN/control"
sed -i -e "s/$ARCH/DUMMYARCHINFO/" "$PACKDIR/DEBIAN/control"
# need a different delimiter, since it has a path
sed -i -e "s,$X11DIR,DUMMYDIRINFO," "$PACKDIR/DEBIAN/postinst"
fi
}
package_X11rdp_interactive()
{
PKGDEST="$WORKINGDIR/packages/x11rdp"
if [ ! -e "$PKGDEST" ]
then
mkdir -p "$PKGDEST"
fi
if $BLEED
then
cd "$WORKINGDIR/xrdp/xorg/debuild"
./debX11rdp.sh "$VERSION" "$RELEASE" "$X11DIR" "$PKGDEST"
else
( mkdir -p "$WORKINGDIR/xrdp/xorg/debuild/x11rdp-files/DEBIAN"
cp "$BASEDIR/debian/x11rdp_control" "$WORKINGDIR/xrdp/xorg/debuild/x11rdp-files/DEBIAN/control"
cp -a "$BASEDIR/debian/x11rdp_postinst" "$WORKINGDIR/xrdp/xorg/debuild/x11rdp-files/DEBIAN/postinst"
cd "$WORKINGDIR/xrdp/xorg/debuild"
PACKDIR=x11rdp-files
DESTDIR="$PACKDIR/opt"
NAME=x11rdp
sed -i -e "s/DUMMYVERINFO/$VERSION-$RELEASE/" "$PACKDIR/DEBIAN/control"
sed -i -e "s/DUMMYARCHINFO/$ARCH/" "$PACKDIR/DEBIAN/control"
# need a different delimiter, since it has a path
sed -i -e "s,DUMMYDIRINFO,$X11DIR," "$PACKDIR/DEBIAN/postinst"
mkdir -p "$DESTDIR"
cp -Rf "$X11DIR" "$DESTDIR"
dpkg-deb --build "$PACKDIR" "$PKGDEST/${NAME}_$VERSION-${RELEASE}_${ARCH}.deb"
XORGPKGNAME="${NAME}_$VERSION-${RELEASE}_${ARCH}.deb"
# revert to initial state
rm -rf "$DESTDIR"
sed -i -e "s/$VERSION-$RELEASE/DUMMYVERINFO/" "$PACKDIR/DEBIAN/control"
sed -i -e "s/$ARCH/DUMMYARCHINFO/" "$PACKDIR/DEBIAN/control"
# need a different delimiter, since it has a path
sed -i -e "s,$X11DIR,DUMMYDIRINFO," "$PACKDIR/DEBIAN/postinst" ) 2>&1 | dialog --progressbox "Making X11rdp Debian Package..." 30 100
fi
}
# Interactively compile & package xrdp using dh-make...
compile_xrdp_interactive()
{
if [ ! -e "$WORKINGDIR/packages/xrdp" ]
then
mkdir -p "$WORKINGDIR/packages/xrdp"
fi
# Step 1: Link xrdp dir to xrdp-$VERSION for dh_make to work on...
rsync -a --delete -- "${WORKINGDIR}/xrdp/" "${WORKINGDIR}/xrdp-${VERSION}"
# Step 2: Run the bootstrap and configure scripts
cd "$WORKINGDIR/xrdp-$VERSION"
( ./bootstrap && ./configure "$CONFIGUREFLAGS[@]}" ) 2>&1 | dialog --progressbox "Preparing xrdp source to make a Debian package..." 50 100
# Step 3 : Use dh-make to create the debian directory package template...
( dh_make_y --single --copyright apache --createorig ) 2>&1 | dialog --progressbox "Preparing xrdp source to make a Debian package..." 50 100
# Step 4 : edit/configure the debian directory...
cd debian
rm *.ex *.EX # remove the example templates
rm README.Debian
rm README.source
cp ../COPYING copyright # use the xrdp copyright file
cp ../readme.txt README # use the xrdp readme.txt as the README file
cp "$BASEDIR/debian/postinst" postinst # postinst to create xrdp init.d defaults
cp "$BASEDIR/debian/control" control # use a generic control file
cp "$BASEDIR/debian/prerm" prerm # pre-removal script
cp "$BASEDIR/debian/docs" docs # use xrdp docs list
# Step 5 : run dpkg-buildpackage to compile xrdp and build a package...
cd ..
( dpkg-buildpackage -uc -us -tc -rfakeroot ) 2>&1 | dialog --progressbox "Building xrdp source and packaging..." 50 100
cd "$WORKINGDIR"
mv xrdp*.deb "$WORKINGDIR/packages/xrdp/"
}
# Package xrdp using dh-make...
compile_xrdp_noninteractive()
{
echo $LINE
echo "Preparing xrdp source to make a Debian package..."
echo $LINE
if [ ! -e "$WORKINGDIR/packages/xrdp" ]
then
mkdir -p "$WORKINGDIR/packages/xrdp"
fi
# Step 1: Link xrdp dir to xrdp-$VERSION for dh_make to work on...
rsync -a --delete -- "${WORKINGDIR}/xrdp/" "${WORKINGDIR}/xrdp-${VERSION}"
# Step 2: Run the bootstrap and configure scripts
cd "$WORKINGDIR/xrdp-$VERSION"
./bootstrap
./configure "${CONFIGUREFLAGS[@]}"
# Step 3 : Use dh-make to create the debian directory package template...
dh_make_y --single --copyright apache --createorig
# Step 4 : edit/configure the debian directory...
cd debian
rm *.ex *.EX # remove the example templates
rm README.Debian
rm README.source
cp ../COPYING copyright # use the xrdp copyright file
cp ../readme.txt README # use the xrdp readme.txt as the README file
cp "$BASEDIR/debian/postinst" postinst # postinst to create xrdp init.d defaults
cp "$BASEDIR/debian/control" control # use a generic control file
cp "$BASEDIR/debian/prerm" prerm # pre-removal script
cp "$BASEDIR/debian/docs" docs # use xrdp docs list
# Step 5 : run dpkg-buildpackage to compile xrdp and build a package...
echo $LINE
echo "Preparation complete. Building and packaging xrdp..."
echo $LINE
cd ..
dpkg-buildpackage -uc -us -tc -rfakeroot
cd "$WORKINGDIR"
mv xrdp*.deb "$WORKINGDIR/packages/xrdp/"
}
remove_x11rdp_packages()
{
(apt-get remove --purge x11rdp-*) 2>&1 | dialog --progressbox "Completely removing previously installed x11rdp packages..." 30 100
}
update_repositories()
{
if $INTERACTIVE
then
welcome_message
apt_update_interactive
else
echo "running apt-get update"
apt-get update >& /dev/null
fi
}
# Interrogates dpkg to find out the status of a given package name...
check_package()
{
DpkgStatus=`dpkg-query -s "$1" 2>&1` || PkgStatus=0
case "$DpkgStatus" in
*"is not installed and no info"*)
PkgStatus=0
# "Not installed."
;;
*"deinstall ok config-files"*)
PkgStatus=1
# "Deinstalled, config files are still on system."
;;
*"install ok installed"*)
PkgStatus=2
# "Installed."
;;
esac
}
# Install or re-install package and give a relatively nice-ish message whilst doing so (if interactive)
install_package()
{
if $INTERACTIVE
then
install_package_interactive "$1"
else
apt-get -y install "$1"
fi
}
# Check for necessary packages and install if necessary...
install_required_packages()
{
for PkgName in "${REQUIREDPACKAGES[@]}"
do
check_package "$PkgName"
if [ $PkgStatus -eq 0 ] || [ $PkgStatus -eq 1 ]
then
install_package "$PkgName"
fi
done
}
calc_cpu_cores()
{
Cores=`nproc`
if [ $Cores -gt 1 ]
then
let "MakesystemWorkHarder = $Cores + 1"
makeCommand="make -j $MakesystemWorkHarder"
else
PARALLELMAKE=false
fi
}
cpu_cores_interactive()
{
# See how many cpu cores we have to play with - we can speed up compilation if we have more cores ;)
if [ ! -e "$WORKINGDIR/PARALLELMAKE" ] && $PARALLELMAKE # No need to perform this if for some reason we've been here before...
then
dialogtext="Good news!\n\nYou can speed up the compilation because there are $Cores CPU cores available to this system.\n\nI can patch the X11rdp build script for you, to utilize the additional CPU cores.\nWould you like me to do this for you?\n\n(Answering Yes will add the \"-j [#cores+1]\" switch to the make command in the build script.\n\nIn this case it will be changed to \"$makeCommand\")."
ask_question
Question=$?
case "$Question" in
"0") # Yes please warm up my computer even more! ;)
# edit the buildx.sh patch file ;)
sed -i -e "s/make -j 1/$makeCommand/g" "$PATCHDIR/buildx_patch.diff"
# create a file flag to say we've already done this
touch "$WORKINGDIR/PARALLELMAKE"
dialogtext="Ok, the optimization has been made.\n\nLooks like your system is going to be working hard soon ;)\n\nClick OK to proceed with the compilation."
info_window
;;
"1") # No thanks, I like waiting ;)
dialogtext="Ok, I will not change the build script as suggested.\n\nIt will take longer to compile though :)\n\nPress OK to proceed with the compilation..."
info_window
;;
esac
fi
}
cpu_cores_noninteractive()
{
if [ ! -e "$WORKINGDIR/PARALLELMAKE" ] # No need to perform this if for some reason we've been here before...
then
if $PARALLELMAKE
then
sed -i -e "s/make -j 1/$makeCommand/g" "$PATCHDIR/buildx_patch.diff"
touch "$WORKINGDIR/PARALLELMAKE"
fi
fi
}
welcome_message()
{
case "$SUPPORTED" in
"1")
dialogtext="Welcome to the ScaryGliders X11rdp-O-Matic installation script.\n\nThe detected distribution is : $DIST.\n\nThis utility has been tested on this distribution.\n\nClick OK to continue..."
info_window
;;
"0")
dialogtext=" Welcome to the ScaryGliders X11rdp-O-Matic installation script.\n\nThe detected distribution is : $DIST .\n\nUnfortunately, no testing has been done for running this utility on this distribution.\n\nIf this is a Debian-based distro, you can try running it. It might work, it might not.\n\nIf the utility does work on this distribution, please let the author know!\n\nClick OK to continue..."
info_window
;;
esac
}
# Create a useful version number for creating Debian packages.
# Worked out from the chosen branch.
calculate_version_num()
{
README="https://raw.github.com/neutrinolabs/xrdp/$XRDPBRANCH/README.md"
wget --no-check-certificate -O "$TMPFILE" "$README" >& /dev/null
VERSION=$(grep -i version "$TMPFILE" | head -1 | cut -d " " -f3)
rm -f "$TMPFILE"
if [ "${XRDPBRANCH#v}" = "$XRDPBRANCH" ]
then
VERSION="$VERSION+$XRDPBRANCH"
fi
echo "Debian package version number will be : $VERSION"
echo $LINE
}
# Make a directory, to which the X11rdp build system will
# place all the built binaries and files.
make_X11rdp_env()
{
if [ -e "$X11DIR" ] && $BUILD_XRDP
then
rm -rf "$X11DIR"
mkdir -p "$X11DIR"
fi
if [ -e "$WORKINGDIR/xrdp" ]
then
rm -rf "$WORKINGDIR/xrdp"
fi
}
# Alter xrdp source code Makefile.am so the PID file is now in /var/run/xrdp/
# Also patch rdp Makefile to tell Ubuntu linker to include GL symbols - pesky Ubuntu...
alter_xrdp_source()
{
cd "$WORKINGDIR"
# Patch Jay's buildx.sh.
# This will patch the make command for parallel makes if that was requested,
# which should speed up compilation. It will make a backup copy of the original buildx.sh.
if $PARALLELMAKE
then
patch -b -d "$WORKINGDIR/xrdp/xorg/X11R7.6" buildx.sh < "$PATCHDIR/buildx_patch.diff"
fi
# Patch rdp Makefile
patch -b -d "$WORKINGDIR/xrdp/xorg/X11R7.6/rdp" Makefile < "$PATCHDIR/rdp_Makefile.patch"
# Patch v0.7 buildx.sh, as the file download location for Mesa has changed...
if [[ $XRDPBRANCH = "v0.7"* ]] # branch v0.7 has a moved libmesa
then
echo "Patching mesa download location..."
patch -b -d "$WORKINGDIR/xrdp/xorg/X11R7.6" buildx.sh < "$PATCHDIR/mesa.patch"
fi
}
# make the /usr/bin/X11rdp symbolic link if it doesn't exist...
make_X11rdp_symbolic_link()
{
if [ ! -e /usr/bin/X11rdp ]
then
if [ -e "$X11DIR/bin/X11rdp" ]
then
ln -s "$X11DIR/bin/X11rdp" /usr/bin/X11rdp
else
clear
echo "There was a problem... the /opt/X11rdp/bin/X11rdp binary could not be found. Did the compilation complete?"
echo "Stopped. Please investigate what went wrong."
exit
fi
fi
}
# make the doc directory if it doesn't exist...
make_doc_directory()
{
if [ ! -e /usr/share/doc/xrdp ]
then
mkdir /usr/share/doc/xrdp
fi
}
install_generated_packages()
{
ERRORFOUND=0
if $BUILD_XRDP
then
FILES=("$WORKINGDIR"/packages/x11rdp/x11rdp*.deb)
if [ ${#FILES[@]} -gt 0 ]
then
remove_currently_installed_X11rdp
dpkg -i "$WORKINGDIR"/packages/x11rdp/x11rdp*.deb
else
ERRORFOUND=1
echo "We were supposed to have built X11rdp but I couldn't find a package file."
echo "Please check that X11rdp built correctly. It probably didn't."
fi
fi
FILES=("$WORKINGDIR"/packages/xrdp/xrdp*.deb)
if [ ${#FILES[@]} -gt 0 ]
then
remove_currently_installed_xrdp
dpkg -i "$WORKINGDIR"/packages/xrdp/xrdp*.deb
else
echo "I couldn't find an xrdp Debian package to install."
echo "Please check that xrdp compiled correctly. It probably didn't."
ERRORFOUND=1
fi
if [ $ERRORFOUND -eq 1 ]
then
exit
fi
}
control_c()
{
clear
cd "$BASEDIR"
echo "*** CTRL-C was pressed - aborted ***"
exit
}
download_compile_interactively()
{
download_xrdp_interactive
if $PARALLELMAKE && [ $Cores -gt 1 ] # Ask about parallel make if requested AND if you have more than 1 CPU core...
then
cpu_cores_interactive
fi
alter_xrdp_source
if $BUILD_XRDP
then
compile_X11rdp_interactive
package_X11rdp_interactive
make_X11rdp_symbolic_link
fi
compile_xrdp_interactive
}
download_compile_noninteractively()
{
download_xrdp_noninteractive
if $PARALLELMAKE
then
cpu_cores_noninteractive
fi
alter_xrdp_source # Patches the downloaded source
if $BUILD_XRDP
then
compile_X11rdp_noninteractive
package_X11rdp_noninteractive
make_X11rdp_symbolic_link
fi
# New method...
# Compiles & packages using dh_make and dpkg-buildpackage
compile_xrdp_noninteractive
}
remove_existing_generated_packages()
{
echo "Checking for previously generated packages..."
echo $LINE
if ls "$WORKINGDIR"/packages/xrdp/X11rdp*.deb >/dev/null 2>&1
then
echo "Removing previously generated Debian X11rdp package file(s)."
echo $LINE
rm "$WORKINGDIR"/packages/Xorg/*.deb
fi
if ls "$WORKINGDIR"/packages/xrdp/xrdp*.deb >/dev/null 2>&1
then
echo "Removing previously generated Debian xrdp package file(s)."
echo $LINE
rm "$WORKINGDIR"/packages/xrdp/*.deb
fi
}
remove_currently_installed_xrdp()
{
check_package xrdp
if [ $PkgStatus -eq 2 ]
then
echo "Removing the currently installed xrdp package."
echo $LINE
apt-get -y remove xrdp
fi
}
remove_currently_installed_X11rdp()
{
check_package X11rdp
if [ $PkgStatus -eq 2 ]
then
echo "Removing the currently installed X11rdp package."
echo $LINE
apt-get -y remove X11rdp
fi
}
check_for_opt_directory()
{
if [ ! -e /opt ]
then
echo "Did not find a /opt directory... creating it."
echo $LINE
mkdir /opt
fi
}
download_and_extract_libturbojpeg()
{
cd "$WORKINGDIR"
echo "TurboJPEG library needs to be built and installed to /opt... downloading and extracting source..."
[ -d libjpeg-turbo ] && return 0
[ -s libjpeg-turbo-1.3.1.tar.gz ] ||
curl -O -J -L http://sourceforge.net/projects/libjpeg-turbo/files/1.3.1/libjpeg-turbo-1.3.1.tar.gz/download#
tar xf libjpeg-turbo-1.3.1.tar.gz
ln -s libjpeg-turbo-1.3.1 libjpeg-turbo
}
build_turbojpeg()
{
cd "$WORKINGDIR/libjpeg-turbo"
echo "Configuring Turbo JPEG..."
./configure
echo "Building TurboJPEG..."
make
echo $LINE
echo "Installing TurboJPEG to default /opt directory..."
make install
echo $LINE
if [ -e /opt/libjpeg-turbo/lib64 ] # Make symbolic link to libjpeg-turbo's lib64 if it doesn't already exist
then
if [ ! -e /opt/libjpeg-turbo/lib ]
then
echo "Making symbolic link to /opt/libjpeg-turbo/lib64..."
ln -s /opt/libjpeg-turbo/lib64 /opt/libjpeg-turbo/lib
fi
fi
if [ -e /opt/libjpeg-turbo/lib32 ] # Make symbolic link to libjpeg-turbo's lib32 if it doesn't already exist
then
if [ ! -e /opt/libjpeg-turbo/lib ]
then
echo "Making symbolic link to /opt/libjpeg-turbo/lib32..."
ln -s /opt/libjpeg-turbo/lib32 /opt/libjpeg-turbo/lib
fi
fi
echo "Continuing with building xrdp..."
echo $LINE
cd "$WORKINGDIR"
}
# if v0.8 selected and --withturbojpeg also selected, we need to build turbojpeg
check_v08_and_turbojpeg()
{
if [[ "$XRDPBRANCH" = "v0.8"* ]]
then
if $USE_TURBOJPEG
then
echo $LINE
echo "v0.8 branch selected and --withturbojpeg. Checking for existing lib in /opt ..."
echo $LINE
if [ ! -e /opt/libjpeg-turbo ] # If the library hasn't already been downloaded & built, then do so
then # Otherwise, assume it has already been built and do nothing more.
download_and_extract_libturbojpeg
build_turbojpeg
else
echo "The necessary turbojpeg lib already exists in /opt so no need to build it again. Waiting 5 seconds..."
echo $LINE
fi
fi
fi
}
cleanup()
{
rm -rf "$WORKINGDIR/xrdp-$VERSION"
}
##########################
# Main stuff starts here #
##########################
# Check for existence of a /opt directory, and create it if it doesn't exist.
check_for_opt_directory
# Figure out what version number to use for the debian packages
calculate_version_num
# trap keyboard interrupt (control-c)
trap control_c SIGINT
if $BUILD_XRDP
then
echo " *** Will remove the contents of $X11DIR and $WORKINGDIR/xrdp-$VERSION ***"
echo
fi
if $INTERACTIVE
then
echo "Press ENTER to continue or CTRL-C to abort"
read DUMMY
fi
if ! $INSTALL_XRDP
then
INSTOPT="no"
else
INSTOPT="yes"
fi
make_X11rdp_env
calc_cpu_cores # find out how many cores we have to play with, and if >1, set a possible make command
update_repositories # perform an apt update to make sure we have a current list of available packages
install_required_packages # install any packages required for xrdp/X11rdp (and libjpeg-turbo if needed) compilation