File: install

package info (click to toggle)
povray 1%3A3.7.0.10-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 147,232 kB
  • sloc: cpp: 845,011; ansic: 122,118; sh: 34,204; pascal: 6,420; asm: 3,355; ada: 1,681; makefile: 1,389; cs: 879; awk: 590; perl: 245; xml: 95
file content (1723 lines) | stat: -rwxr-xr-x 54,031 bytes parent folder | download | duplicates (6)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
#! /bin/sh
# ==================================================================
# POV-Ray 3.7 - binary Linux version - install script
# ==================================================================
# written July 2003 - October 2006 by Christoph Hormann
# based on very basic install script by Mark Gordon
# This file is part of POV-Ray and subject to the POV-Ray licence
# see POVLEGAL.DOC for details.
# ------------------------------------------------------------------
# for documentation of available options see the
# README/README.bin file.
# ==================================================================

# @@KDE_BEGIN@@

POVRAY=POV-Ray
POV_DIR=povray
VERSION_FULL=3.7.0
VERSION=3.7
VER_DIR=$POV_DIR-$VERSION
TARGET_PLATFORM=x86
TARGET_PLATFORM_NAME="x86 Linux"
#TARGET_PLATFORM=x86_64
#TARGET_PLATFORM_NAME="x86_64 (AMD64) Linux"
DEFAULT_DIR=/usr/local
SYSCONFDIR=$DEFAULT_DIR/etc
POVLINUX_DIR=`dirname $0`
CDIR=`pwd`

if [ -z "$TMPDIR" ] ; then
	TMPDIR="/tmp"
fi

if [ ! -w  "$TMPDIR" ] ; then
	TMPDIR=$CDIR
fi

TMP_LOG="$TMPDIR/${VER_DIR}_`date +%s`.log"
test -w "$TMP_LOG" && rm -f "$TMP_LOG"

if [ ! -z "$DISPLAY" ] ; then
	KDIALOG=`which kdialog`
fi

TEXT_MODE=
test "$1" = "text" && TEXT_MODE=on
test "$2" = "text" && TEXT_MODE=on
test "$3" = "text" && TEXT_MODE=on
test "$4" = "text" && TEXT_MODE=on
test "$5" = "text" && TEXT_MODE=on
test "$6" = "text" && TEXT_MODE=on
test "$7" = "text" && TEXT_MODE=on
test "$8" = "text" && TEXT_MODE=on
test "$9" = "text" && TEXT_MODE=on

if [ ! -z "$TEXT_MODE" ] ; then
	KDIALOG=
fi

QUIET_MODE=
test "$1" = "quiet" && QUIET_MODE=on
test "$2" = "quiet" && QUIET_MODE=on
test "$3" = "quiet" && QUIET_MODE=on
test "$4" = "quiet" && QUIET_MODE=on
test "$5" = "quiet" && QUIET_MODE=on
test "$6" = "quiet" && QUIET_MODE=on
test "$7" = "quiet" && QUIET_MODE=on
test "$8" = "quiet" && QUIET_MODE=on
test "$9" = "quiet" && QUIET_MODE=on


# [NC] POSIX-compliant read from terminal
read_input()
{
	# print a message before reading input
	if test x"`printf %s check 2> /dev/null`" = x"check"; then
		printf %s "$2"
	else	# will print a newline
		echo "$2"
	fi
	read $1
}


# ==================================================================
#    messages - alternatively console or kdialog
# ==================================================================

info_message()
{
	echo "$1" 2>&1 | tee -a "$TMP_LOG"
	if [ ! -z "$KDIALOG" ] ; then
		kdialog --caption "$POVRAY $VERSION_FULL installation" --msgbox "$1"
	fi
}

error_message()
{
	echo "------------------------------------------------------" 2>&1 | tee -a "$TMP_LOG"
	echo "Error: $1" 2>&1 | tee -a "$TMP_LOG"
	echo "------------------------------------------------------" 2>&1 | tee -a "$TMP_LOG"
	if [ ! -z "$KDIALOG" ] ; then
		kdialog --caption "$POVRAY $VERSION_FULL installation" --error "$1"
	fi
}

# ==================================================================
#    abort install and display log if requested
# ==================================================================

abort_install()
{
	echo "Installation aborted!" 2>&1 | tee -a "$TMP_LOG"

	if [ ! -z "$KDIALOG" ] ; then
		kdialog --caption "$POVRAY $VERSION_FULL installation" --yesno "The installation of $POVRAY $VERSION_FULL has been aborted due to an error or user request.  Do you want to view the installation log?"
		if [ $? -ne 0 ] ; then
			exit
		else
			kdialog --caption "$POVRAY $VERSION_FULL installation - Installation log" --textbox "$TMP_LOG" 800 600
			exit
		fi
	else
		echo "" 2>&1 | tee -a "$TMP_LOG"
		exit
	fi

}

# ==================================================================
#    finish and display log if requested
# ==================================================================

finish_install()
{
	echo "Installation finished successfully!" 2>&1 | tee -a "$TMP_LOG"

	if [ ! -z "$KDIALOG" ] ; then
		kdialog --caption "$POVRAY $VERSION_FULL installation" --yesno "The installation of $POVRAY $VERSION_FULL has been finished successfully.  Do you want to view the installation log?"
		if [ $? -ne 0 ] ; then
			exit
		else
			kdialog --caption "$POVRAY $VERSION_FULL installation" --textbox "$TMP_LOG" 800 600
			exit
		fi
	else
		echo "" 2>&1 | tee -a "$TMP_LOG"
		exit
	fi

}

# ==================================================================
#    check system and package content
# ==================================================================

prepare_bin_install()
{

	INCOMPLETE=
	test ! -r "$POVLINUX_DIR/povray" && INCOMPLETE=true
	test ! -r "$POVLINUX_DIR/povray.ini" && INCOMPLETE=true
	test ! -r "$POVLINUX_DIR/povray.conf" && INCOMPLETE=true
	test ! -d "$POVLINUX_DIR/scenes" && INCOMPLETE=true
	test ! -d "$POVLINUX_DIR/include" && INCOMPLETE=true
	test ! -d "$POVLINUX_DIR/doc" && INCOMPLETE=true
	test ! -d "$POVLINUX_DIR/ini" && INCOMPLETE=true
	test ! -d "$POVLINUX_DIR/scripts" && INCOMPLETE=true

	if [ ! -z "$INCOMPLETE" ] ; then
		error_message "files required for installation not found -
make sure you correctly downloaded and unpacked 
the installation package"
		abort_install
	fi

	if [ -z "$QUIET_MODE" ] ; then
		if [ ! -z "$KDIALOG" ] ; then
			kdialog --caption "$POVRAY $VERSION_FULL installation" --yesno "welcome to the $POVRAY $VERSION_FULL installation.\nThe install script has detected a KDE installation on this system and will use kdialog.  If you prefer a text mode install use 'install text'.  Start installation now?"
			if [ $? -ne 0 ] ; then
				abort_install
			fi
		fi
	fi

	echo "installation preparation successful" >> "$TMP_LOG"

}

# ==================================================================
#    select sys/user install and obtain install dir
# ==================================================================

select_target_dir()
{
	POVRAY_BINARY=`which povray`

	if [ ! -w "$DEFAULT_DIR" ] ; then
		if [ ! -z "$KDIALOG" ] ; then
			if [ ! -z "$POVRAY_BINARY" ] ; then
				ADD_MESSAGE="
Note there is currently a $POVRAY binary installed on the system ($POVRAY_BINARY).  You need to set the PATH environment variable or rename this or the new binary to make sure the correct version is called when running 'povray'."
			else
				ADD_MESSAGE=
			fi
			kdialog --caption "$POVRAY $VERSION_FULL installation" --yesno "You need to have root privileges to install $POVRAY $VERSION_FULL in the default location ($DEFAULT_DIR).\nYou can also install $POVRAY on user level at a custom location but this requires additional manual setup steps.  Do you want to login as root now to perform a system install?  If you select 'no' you will be asked for a custom location for a user install instead.  $ADD_MESSAGE"

			if [ $? -eq 0 ] ; then
				OPTS=
				test -z "$TEXT_MODE" || OPTS="text"
				test -z "$SKIP_ARCH" || OPTS="-no-arch-check $OPTS"
				kdesu -t -c $0 $OPTS quiet
				exit
			else
				BASEDIR=`kdialog --inputbox "Please specify the base directory you want to install in.
This directory has to be writable from this user account.
You will probably want to speciafy a location in your home
directory (like $HOME/usr):" "$HOME/usr" --title "$POVRAY $VERSION_FULL installation"` 2> /dev/null

				if [ $? -ne 0 ] ; then
					abort_install
				fi

				BASEDIR=`echo "$BASEDIR" | sed "s?~?$HOME?g"`

				if [ ! -d "$BASEDIR" ] ; then
					mkdir -p "$BASEDIR"
				fi

				if [ ! -w "$BASEDIR" ] ; then
					error_message "The chosen install directory is not writable, 
either login as root or specify a different location."
					abort_install
				fi
			fi
		else
			if [ -z "$POVRAY_BINARY" ]  ; then
				ADD_MESSAGE=
			else
				if [ "$POVRAY_BINARY" = "$DEFAULT_DIR/bin/povray" ]  ; then
					ADD_MESSAGE=
				else
					ADD_MESSAGE="
Note there is currently a $POVRAY binary installed on 
the system ($POVRAY_BINARY).  You need to set the PATH
environment variable or rename this or the new binary
to make sure the correct version is called when 
running 'povray'.
"
				fi
			fi
			echo "You need to have root privileges to install $POVRAY $VERSION_FULL"
			echo "in the default location ($DEFAULT_DIR)."
			echo ""
			echo "You can also install $POVRAY on user level at a custom location"
			echo "but this requires additional manual setup steps."
			echo "$ADD_MESSAGE"
			echo "  Type 'R'  to login as root and install in $DEFAULT_DIR"
			echo "            (recommended method)."
			echo "  Type 'U'  to make a user level installation at a custom location."
			echo "  Type anything else to abort."
			echo ""
			read_input INPUT "Your choice (R/U, default: abort): "

			echo ""

			case $INPUT in
				"r" | "R")                 # login as root
					echo ""
					echo "Enter root password to install in $DEFAULT_DIR:"
					OPTS=
					test -z "$TEXT_MODE" || OPTS="text"
					test -z "$SKIP_ARCH" || OPTS="-no-arch-check $OPTS"
					su -c $0 $OPTS quiet
					exit
					;;
				"u" | "U")                 # ask for location and continue
					echo ""
					echo "Please specify the base directory you want to install in."
					echo "This directory has to be writable from this user account."
					echo "You will probably want to speciafy a location in your home"
					echo "directory (like $HOME/usr):"

					read_input BASEDIR "directory name: "

					echo ""

					BASEDIR=`echo "$BASEDIR" | sed "s?~?$HOME?g"`

					if [ ! -d "$BASEDIR" ] ; then
						mkdir -p "$BASEDIR"
					fi

					if [ ! -w "$BASEDIR" ] ; then

						echo ""
						echo "This directory is not writable, either login as root"
						echo "or specify a different location."
						echo ""
						echo "Installation aborted!"
						exit
					fi
					;;
				*)                         # abort
					abort_install
					;;
			esac
		fi
	else
		echo "installing $POVRAY in default location ($DEFAULT_DIR)" 2>&1 | tee -a "$TMP_LOG"
		BASEDIR=$DEFAULT_DIR
	fi

	echo "installation directory selected: $BASE_DIR" >> "$TMP_LOG"
}

# ==================================================================
#    Add read+write path to user povray.conf file
# ==================================================================

add_readwrite_conf()
{
	DIR_NAME=$1
	CONF_FILE="$HOME/.$POV_DIR/$VERSION/povray.conf"

	echo "  checking conf file $CONF_FILE" 2>&1 | tee -a "$TMP_LOG"

	if [ ! -r "$CONF_FILE" ] ; then
		cp -f "$SYSCONFDIR/$POV_DIR/$VERSION/povray.conf" "$CONF_FILE" 2>&1 | tee -a "$TMP_LOG"
	fi

	if [ -w "$CONF_FILE" ] ; then

		if grep -E -i "$DIR_NAME" "$CONF_FILE" > /dev/null ; then
			echo "    - file does not need to be modified" 2>&1 | tee -a "$TMP_LOG"
		else
			echo "    - adding new read+write path" 2>&1 | tee -a "$TMP_LOG"

			cp -f "$CONF_FILE" "$CONF_FILE.bak" 2>&1 | tee -a "$TMP_LOG"

			grep -B 1000 -E -i "^\[Permitted Paths\]" "$CONF_FILE.bak" > "$CONF_FILE" 2> /dev/null

			echo ";--- Lines added by $POVRAY $VERSION_FULL install script ---" >> "$CONF_FILE"
			echo "read+write* =  \"$DIR_NAME\"" >> "$CONF_FILE"
			echo ";---------------------------------------------------" >> "$CONF_FILE"

			grep -A 1000 -E -i "^\[Permitted Paths\]" "$CONF_FILE.bak" | sed "/^\[Permitted Paths\]/d" >> "$CONF_FILE" 2> /dev/null

			rm -f "$CONF_FILE.bak" 2>&1 | tee -a "$TMP_LOG"

		fi

	else
		echo "Error: could not modify povray.conf" 2>&1 | tee -a "$TMP_LOG"
	fi
}

# ==================================================================
#    Add read path to user povray.conf file
# ==================================================================

add_read_conf()
{
	DIR_NAME=$1
	CONF_FILE="$HOME/.$POV_DIR/$VERSION/povray.conf"

	echo "  checking conf file $CONF_FILE" 2>&1 | tee -a "$TMP_LOG"

	if [ ! -r "$CONF_FILE" ] ; then
		cp -f "$SYSCONFDIR/$POV_DIR/$VERSION/povray.conf" "$CONF_FILE" 2>&1 | tee -a "$TMP_LOG"
	fi

	if [ -w "$CONF_FILE" ] ; then

		if grep -E -i "$DIR_NAME" "$CONF_FILE" > /dev/null ; then
			echo "    - file does not need to be modified" 2>&1 | tee -a "$TMP_LOG"
		else
			echo "    - adding new read path" 2>&1 | tee -a "$TMP_LOG"

			cp -f "$CONF_FILE" "$CONF_FILE.bak" 2>&1 | tee -a "$TMP_LOG"

			grep -B 1000 -E -i "^\[Permitted Paths\]" "$CONF_FILE.bak" > "$CONF_FILE" 2> /dev/null

			echo ";--- Lines added by $POVRAY $VERSION_FULL install script ---" >> "$CONF_FILE"
			echo "read* =  \"$DIR_NAME\"" >> "$CONF_FILE"
			echo ";---------------------------------------------------" >> "$CONF_FILE"

			grep -A 1000 -E -i "^\[Permitted Paths\]" "$CONF_FILE.bak" | sed "/^\[Permitted Paths\]/d" >> "$CONF_FILE" 2> /dev/null

			rm -f "$CONF_FILE.bak" 2>&1 | tee -a "$TMP_LOG"

		fi

	else
		echo "Error: could not modify povray.conf" 2>&1 | tee -a "$TMP_LOG"
	fi
}

# ==================================================================
#    Determine installation dir from Library_path settings in ini
# ==================================================================

install_dir()
{
  if [ -z "$POVINI" ] ; then
    test -r "$SYSCONFDIR/povray.ini" && POVINI="$SYSCONFDIR/povray.ini"
    test -r "$HOME/.povrayrc" && POVINI="$HOME/.povrayrc"
    test -r "$SYSCONFDIR/$POV_DIR/$VERSION/povray.ini" && POVINI="$SYSCONFDIR/$POV_DIR/$VERSION/povray.ini"
    test -r "$HOME/.$POV_DIR/$VERSION/povray.ini" && POVINI="$HOME/.$POV_DIR/$VERSION/povray.ini"
  fi

  if [ ! -z "$POVINI" ] ; then
    # this is not a completely failsafe method but it should work in most cases
    INSTALL_DIR=`grep -E -i "^library_path=.*share/$VER_DIR" "$POVINI" | head -n 1 | sed "s?[^=]*=\"*??;s?/share/$VER_DIR.*??"`
    echo "$INSTALL_DIR"
  fi
}

# ==================================================================
#    Add file name to install log
# ==================================================================

log_install()
{
	if [ -w "$DEFAULT_DIR" ] ; then
		if [ ! -d "$DEFAULT_DIR/share/$VER_DIR/" ] ; then
			mkdir -p "$DEFAULT_DIR/share/$VER_DIR/" 2>&1 | tee -a "$TMP_LOG"
		fi
		LOG_NAME="$DEFAULT_DIR/share/$VER_DIR/install.log"
	else
		if [ ! -d "$HOME/.$POV_DIR/$VERSION/" ] ; then
			mkdir -p "$HOME/.$POV_DIR/$VERSION/" 2>&1 | tee -a "$TMP_LOG"
		fi
		if [ -w "$HOME/.$POV_DIR/$VERSION/" ] ; then
			LOG_NAME="$HOME/.$POV_DIR/$VERSION/install.log"
		else
			echo "could not write install log - check permissions!" | tee -a "$TMP_LOG"
			return 0
		fi
	fi

	if [ -z "$1$2" ] ; then
		echo "clearing install log." | tee -a "$TMP_LOG"
		rm -f "$LOG_NAME"
	fi

	if [ ! -r "$LOG_NAME" ] ; then
		echo "# $POVRAY version $VERSION_FULL install log" > "$LOG_NAME"
		echo "# started `date`" >> "$LOG_NAME"
	fi

	if [ "$1" = "B" ] ; then
		FILE_NAME=`echo "$2" | sed "s? ?%?g"`
		FILE_NAME="$FILE_NAME $3"
	else 
		FILE_NAME=`echo "$2" | sed "s? ?%?g"`
	fi

	echo "$1 $FILE_NAME" >> "$LOG_NAME"
}

# ==================================================================
#    install KDE icons and file types (system wide if possible)
# ==================================================================

kde_install()
{
  KDECONFIG=kde${KDE_SESSION_VERSION}-config

  if [ -z "$KDECONFIG" ] ; then
    return 0
  fi

  if [ -z "$1" ] ; then
    INSTALL_DIR=`install_dir`
  else
    INSTALL_DIR="$1"
  fi

  if [ -z "$INSTALL_DIR" ] ; then
    error_message "KDE integration NOT successful.  The directory 
where $POVRAY is installed could not be determined.
Make sure $POVRAY is correctly installed 
on this computer."
    return 0
  fi

  echo "------------------------------------------------------" 2>&1 | tee -a "$TMP_LOG"
  echo "installing basic KDE integration..." 2>&1 | tee -a "$TMP_LOG"

  KDE_INSTALL_DIR=`$KDECONFIG --prefix`
  if [ -z "$KDE_INSTALL_DIR" ] ; then
    error_message "KDE integration NOT successful.  
KDE installation on this computer does not exist or seems incomplete."
    return 0
  else
    if [ ! -w "$KDE_INSTALL_DIR" ] ; then
      if [ -z "$KDEHOME" ] ; then 
        if [ -d "$HOME/.kde" ] ; then 
          KDEHOME="$HOME/.kde"
        else
          error_message "could not determine user KDEHOME directory.
Make sure KDE is correctly installed"
          return 0
        fi
      else
        if [ ! -d "$KDEHOME" ] ; then
          error_message "user KDEHOME directory ($KDEHOME) does not exist"
          return 0
        fi
      fi
      if [ ! -w "$KDEHOME" ] ; then
        error_message "no write permission for user KDEHOME directory ($KDEHOME)"
        return 0
      fi
      KDE_INSTALL_DIR="$KDEHOME"
      echo "  kde integration for user $USER" 2>&1 | tee -a "$TMP_LOG"
    else
      echo "  kde integration system wide" 2>&1 | tee -a "$TMP_LOG"
    fi
  fi

  test -d "$KDE_INSTALL_DIR/share" || mkdir "$KDE_INSTALL_DIR/share" 2>&1 | tee -a "$TMP_LOG"

  if [ -d "$INSTALL_DIR/share/$VER_DIR/icons" ] ; then

    echo "  copying $POVRAY icons..." 2>&1 | tee -a "$TMP_LOG"

    test -d "$KDE_INSTALL_DIR/share/icons" || mkdir "$KDE_INSTALL_DIR/share/icons" 2>&1 | tee -a "$TMP_LOG"

		ICON_SETS="hicolor crystalsvg slick"

		for ICON_SET in $ICON_SETS ; do

			ICON_PREFIX="$KDE_INSTALL_DIR/share/icons/$ICON_SET"

			case $ICON_SET in
				"hicolor")
					ICON_SET_INTERN="classic"
					;;
				"crystalsvg")
					ICON_SET_INTERN="crystal"
					;;
				"slick")
					ICON_SET_INTERN="slick"
					;;
			esac

			test -d "$ICON_PREFIX" || mkdir "$ICON_PREFIX" 2>&1 | tee -a "$TMP_LOG"

			ICON_SIZES="16 32 48 64"

			for ICON_SIZE in $ICON_SIZES ; do

				test -d "$ICON_PREFIX/${ICON_SIZE}x${ICON_SIZE}" || mkdir "$ICON_PREFIX/${ICON_SIZE}x${ICON_SIZE}" 2>&1 | tee -a "$TMP_LOG"
				test -d "$ICON_PREFIX/${ICON_SIZE}x${ICON_SIZE}/mimetypes" || mkdir "$ICON_PREFIX/${ICON_SIZE}x${ICON_SIZE}/mimetypes" 2>&1 | tee -a "$TMP_LOG"

				if [ "$ICON_SET" = "hicolor" ] ; then
					test -d "$ICON_PREFIX/${ICON_SIZE}x${ICON_SIZE}/apps" || mkdir "$ICON_PREFIX/${ICON_SIZE}x${ICON_SIZE}/apps" 2>&1 | tee -a "$TMP_LOG"
					cp -f "$INSTALL_DIR/share/$VER_DIR/icons/povray_${ICON_SIZE}.png" "$KDE_INSTALL_DIR/share/icons/hicolor/${ICON_SIZE}x${ICON_SIZE}/apps/povray.png" 2>&1 | tee -a "$TMP_LOG"
					log_install "F" "$KDE_INSTALL_DIR/share/icons/hicolor/${ICON_SIZE}x${ICON_SIZE}/apps/povray.png"
				fi

				cp -f "$INSTALL_DIR/share/$VER_DIR/icons/file_pov_${ICON_SET_INTERN}_${ICON_SIZE}.png" "$ICON_PREFIX/${ICON_SIZE}x${ICON_SIZE}/mimetypes/povsdl_pov.png" 2>&1 | tee -a "$TMP_LOG"
				cp -f "$INSTALL_DIR/share/$VER_DIR/icons/file_inc_${ICON_SET_INTERN}_${ICON_SIZE}.png" "$ICON_PREFIX/${ICON_SIZE}x${ICON_SIZE}/mimetypes/povsdl_inc.png" 2>&1 | tee -a "$TMP_LOG"
				log_install "F" "$ICON_PREFIX/${ICON_SIZE}x${ICON_SIZE}/mimetypes/povsdl_pov.png"
				log_install "F" "$ICON_PREFIX/${ICON_SIZE}x${ICON_SIZE}/mimetypes/povsdl_inc.png"

			done

		done

    ICON_FILE="povray.png"

    echo "  generating $POVRAY file types..." 2>&1 | tee -a "$TMP_LOG"

    if [ ! -d "$KDE_INSTALL_DIR/share/mimelnk/text" ]; then
      mkdir -p "$KDE_INSTALL_DIR/share/mimelnk/text"
    fi

    echo "[Desktop Entry]
Comment=POV-Ray script file
Icon=povsdl_pov
Type=MimeType
MimeType=text/x-povray-script
Patterns=*.pov;*.POV;
" > "$KDE_INSTALL_DIR/share/mimelnk/text/x-povray-script.desktop"

		log_install "F" "$KDE_INSTALL_DIR/share/mimelnk/text/x-povray-script.desktop"

    echo "[Desktop Entry]
Comment=POV-Ray include file
Icon=povsdl_inc
Type=MimeType
MimeType=text/x-povray-include
Patterns=*.inc;*.INC;
" > "$KDE_INSTALL_DIR/share/mimelnk/text/x-povray-include.desktop"

		log_install "F" "$KDE_INSTALL_DIR/share/mimelnk/text/x-povray-include.desktop"

  else

    error_message "Could not find required files, make sure $POVRAY $VERSION_FULL is correctly installed
"

  fi

  echo "Finished basic KDE integration" 2>&1 | tee -a "$TMP_LOG"
  echo "------------------------------------------------------" 2>&1 | tee -a "$TMP_LOG"
  echo "" 2>&1 | tee -a "$TMP_LOG"

  return 1

}

# ==================================================================
#    install KDE panel entries
# ==================================================================

kde_install_user()
{
  if [ -z "$1" ] ; then
    INSTALL_DIR=`install_dir`
  else
    INSTALL_DIR="$1"
  fi

  if [ -z "$INSTALL_DIR" ] ; then
    error_message "KDE integration NOT successful.  The directory 
where $POVRAY is installed could not be determined.
Make sure $POVRAY is correctly installed 
on this computer."
    return 0
  fi

  if [ -z "$KDEHOME" ] ; then 
    if [ -d "$HOME/.kde" ] ; then 
      KDEHOME="$HOME/.kde"
    else
      error_message "could not determine user KDEHOME directory.  
Make sure KDE is correctly installed"
      return 0
    fi
  else
    if [ ! -d "$KDEHOME" ] ; then
      error_message "user KDEHOME directory ($KDEHOME) does not exist"
      return 0
    fi
  fi
  if [ ! -w "$KDEHOME" ] ; then
    error_message "no write permission for user KDEHOME directory ($KDEHOME)"
    return 0
  fi

  echo "------------------------------------------------------" 2>&1 | tee -a "$TMP_LOG"
  echo "installing KDE integration for user '$USER'..." 2>&1 | tee -a "$TMP_LOG"
  echo "  installing main $POVRAY $VERSION_FULL submenu..." 2>&1 | tee -a "$TMP_LOG"

  if [ ! -d "$KDEHOME/share/applnk" ] ; then
    mkdir -p "$KDEHOME/share/applnk" 2>&1 | tee -a "$TMP_LOG"
    KDE_PANEL_DIR="$KDEHOME/share/applnk/$VER_DIR"
  else
    KDE_PANEL_DIR="$KDEHOME/share/applnk/$VER_DIR"
  fi

  if [ -d "$KDE_PANEL_DIR" ] ; then 
    rm -rf $KDE_PANEL_DIR/* 2>&1 | tee -a "$TMP_LOG"
  else
    mkdir "$KDE_PANEL_DIR" 2>&1 | tee -a "$TMP_LOG"
  fi

  log_install "F" "$KDE_PANEL_DIR"

  echo "[Desktop Entry]
Name=POV-Ray $VERSION_FULL
Icon=povray
" > "$KDE_PANEL_DIR/.directory"

  echo "  installing ini file link..." 2>&1 | tee -a "$TMP_LOG"

  if [ -f "$HOME/.povray/$VERSION/povray.ini" ] ; then
    POVINI="$HOME/.povray/$VERSION/povray.ini"
    echo "[Desktop Entry]
Type=Application
Exec=kwrite $POVINI
Icon=txt
Name=edit user povray ini file (~/.povray/$VERSION/povray.ini)
" > "$KDE_PANEL_DIR/ini.desktop"
  else
    POVINI="$SYSCONFDIR/povray/$VERSION/povray.ini"
    echo "[Desktop Entry]
Type=Application
Exec=kdesu kwrite $POVINI
Icon=txt
Name=edit global povray.ini file
" > "$KDE_PANEL_DIR/ini.desktop"
  fi

  echo "  installing configuration file link..." 2>&1 | tee -a "$TMP_LOG"

  if [ -f "$HOME/.povray/$VERSION/povray.conf" ] ; then
    POVCONF="$HOME/.povray/$VERSION/povray.conf"
    echo "[Desktop Entry]
Type=Application
Exec=kwrite $POVCONF
Icon=txt
Name=edit IO-restrictions configuration file (~/.povray/$VERSION/povray.conf)
" > "$KDE_PANEL_DIR/conf_user.desktop"
  fi

  if [ -f "$SYSCONFDIR/povray/$VERSION/povray.conf" ] ; then
    POVCONF="$SYSCONFDIR/povray/$VERSION/povray.conf"
    echo "[Desktop Entry]
Type=Application
Exec=kdesu kwrite $POVCONF
Icon=txt
Name=edit global IO-restrictions configuration file
" > "$KDE_PANEL_DIR/conf_sys.desktop"
  fi

  echo "  installing documentation link..." 2>&1 | tee -a "$TMP_LOG"

  echo "[Desktop Entry]
Type=Application
Exec=konqueror $INSTALL_DIR/share/doc/$VER_DIR/html/index.html
Icon=html
Name=Documentation
" > "$KDE_PANEL_DIR/docu.desktop"

  echo "[Desktop Entry]
Type=Application
Exec=konqueror $INSTALL_DIR/share/doc/$VER_DIR/html/povlegal.html
Icon=html
Name=The POV-Ray licence (POVLEGAL.DOC)
" > "$KDE_PANEL_DIR/povlegal.desktop"

  echo "[Desktop Entry]
Type=Application
Exec=povray -benchmark ; read
Icon=exec
Name=run benchmark
Terminal=1
" > "$KDE_PANEL_DIR/benchmark.desktop"

  if [ -d "$INSTALL_DIR/share/$VER_DIR/scripts/" ] ; then

    echo "  installing sample scene render links..." 2>&1 | tee -a "$TMP_LOG"

    if [ -w "$INSTALL_DIR/share/$VER_DIR" ] ; then 
      SAMPLE_RESULTS_DIR="$INSTALL_DIR/share/$VER_DIR"
    else
      SAMPLE_RESULTS_DIR="$HOME/$VER_DIR"
      test -d "$SAMPLE_RESULTS_DIR" || mkdir "$SAMPLE_RESULTS_DIR"
      echo "This directory is generated by the $POVRAY $VERSION_FULL install script 
to contain the sample scene renders generated by the corresponding
entries in the KDE panel menu." > "$SAMPLE_RESULTS_DIR/README" 
    fi

    test -d "$SAMPLE_RESULTS_DIR/samples" || mkdir "$SAMPLE_RESULTS_DIR/samples"
    test -d "$SAMPLE_RESULTS_DIR/portfolio" || mkdir "$SAMPLE_RESULTS_DIR/portfolio"

    echo "Here you can find the rendered sample animations after running the sample animations render script" > "$SAMPLE_RESULTS_DIR/samples/animations.html"
    echo "Here you can find the rendered sample scenes after running the sample scenes render script" > "$SAMPLE_RESULTS_DIR/samples/stills.html"
    echo "Here you can find the portfolio after running the portfolio render script" > "$SAMPLE_RESULTS_DIR/portfolio/index.html"

    if [ -d "$KDE_PANEL_DIR/samples" ] ; then 
      rm -rf $KDE_PANEL_DIR/samples* 2>&1 | tee -a "$TMP_LOG"
    else
      mkdir "$KDE_PANEL_DIR/samples" 2>&1 | tee -a "$TMP_LOG"
    fi

    echo "[Desktop Entry]
Name=Sample scenes
Icon=folder
" > "$KDE_PANEL_DIR/samples/.directory"

    echo "[Desktop Entry]
Type=Application
Exec=$INSTALL_DIR/share/$VER_DIR/scripts/allscene.sh -o $SAMPLE_RESULTS_DIR/samples -h $SAMPLE_RESULTS_DIR/samples/stills.html
Icon=exec
Name=render sample scenes (stills)
Terminal=1
" > "$KDE_PANEL_DIR/samples/render_stills.desktop"

    echo "[Desktop Entry]
Type=Application
Exec=$INSTALL_DIR/share/$VER_DIR/scripts/allanim.sh -o $SAMPLE_RESULTS_DIR/samples -h $SAMPLE_RESULTS_DIR/samples/animations.html
Icon=exec
Name=render sample scenes (animations)
Terminal=1
" > "$KDE_PANEL_DIR/samples/render_animations.desktop"

    echo "[Desktop Entry]
Type=Application
Exec=$INSTALL_DIR/share/$VER_DIR/scripts/portfolio.sh -o $SAMPLE_RESULTS_DIR/portfolio
Icon=exec
Name=render portfolio
Terminal=1
" > "$KDE_PANEL_DIR/samples/render_portfolio.desktop"

    echo "[Desktop Entry]
Type=Application
Exec=konqueror $SAMPLE_RESULTS_DIR/portfolio/index.html
Icon=html
Name=View portfolio
" > "$KDE_PANEL_DIR/samples/view_portfolio.desktop"

    echo "[Desktop Entry]
Type=Application
Exec=konqueror $SAMPLE_RESULTS_DIR/samples/animations.html
Icon=imagegallery
Name=Sample scene gallery (animations)
" > "$KDE_PANEL_DIR/samples/animations.desktop"

    echo "[Desktop Entry]
Type=Application
Exec=konqueror $SAMPLE_RESULTS_DIR/samples/stills.html
Icon=imagegallery
Name=Sample scene gallery (stills)
" > "$KDE_PANEL_DIR/samples/stills.desktop"

    echo "  modifying povray.conf..." 2>&1 | tee -a "$TMP_LOG"
		add_readwrite_conf "$SAMPLE_RESULTS_DIR"

  else

    error_message "Could not find required files, make sure $POVRAY $VERSION_FULL is correctly installed
"
  fi

  # needs an extra invitation
	if [ -d "$KDEHOME/share/applnk-redhat" ] ; then 
		KDE_RH_PANEL_DIR="$KDEHOME/share/applnk-redhat/$VER_DIR"
		if [ -L "$KDE_RH_PANEL_DIR" ] ; then 
			rm "$KDE_RH_PANEL_DIR" 2>&1 | tee -a "$TMP_LOG"
		fi
		if [ -d "$KDE_RH_PANEL_DIR" ] ; then 
			rm -rf "$KDE_RH_PANEL_DIR" 2>&1 | tee -a "$TMP_LOG"
		fi
		ln -s "$KDE_PANEL_DIR" "$KDE_RH_PANEL_DIR" 2>&1 | tee -a "$TMP_LOG"
		log_install "F" "$KDE_RH_PANEL_DIR"
  fi

  echo "Finished installing KDE panel entries" 2>&1 | tee -a "$TMP_LOG"
  echo "------------------------------------------------------" 2>&1 | tee -a "$TMP_LOG"
  echo "" 2>&1 | tee -a "$TMP_LOG"

  return 1
}

# @@KDE_END@@

# ==================================================================
#    Add Library_Path lines to ini file when necessary
# ==================================================================

add_libpath_ini()
{
  DIR_NAME=$1
  INI_FILE=$2

  echo "  checking ini file $INI_FILE" 2>&1 | tee -a "$TMP_LOG"

  if grep -E -i "^library_path=\"*$DIR_NAME/share/$VER_DIR" "$INI_FILE" > /dev/null ; then
    echo "    - file does not need to be modified" 2>&1 | tee -a "$TMP_LOG"
  else
    echo "    - adding new Library_Path settings" 2>&1 | tee -a "$TMP_LOG"

    cp -f "$INI_FILE" "$INI_FILE.bak" 2>&1 | tee -a "$TMP_LOG"

    grep -B 1000 -E -i "^library_path" "$INI_FILE.bak" | sed '/^[Ll][Ii][Bb][Rr][Aa][Rr][Yy]_[Pp][Aa][Tt][Hh]=/,$ { d; }'  > "$INI_FILE" 2> /dev/null

    echo ";--- Lines added by $POVRAY $VERSION_FULL install script ---" >> "$INI_FILE"
    echo "Library_Path=\"$DIR_NAME/share/$VER_DIR\"" >> "$INI_FILE"
    echo "Library_Path=\"$DIR_NAME/share/$VER_DIR/ini\"" >> "$INI_FILE"
    echo "Library_Path=\"$DIR_NAME/share/$VER_DIR/include\"" >> "$INI_FILE"
    echo ";---------------------------------------------------" >> "$INI_FILE"
    echo "" >> "$INI_FILE"

    grep -A 1000 -E -i "^library_path" "$INI_FILE.bak" >> "$INI_FILE" 2> /dev/null

    rm -f "$INI_FILE.bak" 2>&1 | tee -a "$TMP_LOG"

  fi
}

# ==================================================================
#    uninstall - delete all files listed in install log
#                try to restore backups made during install
# ==================================================================

uninstall()
{
	if [ -w "$DEFAULT_DIR/share/$VER_DIR/install.log" ] ; then
		LOG_NAME="$DEFAULT_DIR/share/$VER_DIR/install.log"
	else
		if [ -w "$HOME/.$POV_DIR/$VERSION/install.log" ] ; then
			LOG_NAME="$HOME/.$POV_DIR/$VERSION/install.log"
		else
			error_message "Could not find the install log.
Make sure you run uninstall as the 
same user who installed $POVRAY $VERSION_FULL."
			return 0
		fi
	fi

	if [ ! -z "$KDIALOG" ] ; then
		kdialog --caption "$POVRAY $VERSION_FULL uninstall" --yesno "The uninstall function will remove $POVRAY $VERSION_FULL from this computer.  Make sure you run it as the same user who installed $POVRAY.

Any changes made to the installed files (sample scenes, include files etc. will get lost, the configuration files will not be removed.

Uninstall now?"
		if [ $? -ne 0 ] ; then
			echo "Uninstall aborted!" 2>&1 | tee -a "$TMP_LOG"
			return 0
		fi
	else
		echo "  The uninstall function will remove $POVRAY $VERSION_FULL"
		echo "  from this computer.  Make sure you run it as the"
		echo "  same user who installed $POVRAY."
		echo ""
		echo "  Any changes made to the installed files (sample scenes,"
		echo "  include files etc. will get lost, the configuration"
		echo "  files will not be removed."
		echo ""
		read_input INPUT "Press CTRL-C to abort or any other key to start "
	fi

	echo "" 2>&1 | tee -a "$TMP_LOG"
	echo "------------------------------------------------------" 2>&1 | tee -a "$TMP_LOG"
	echo "uninstalling $POVRAY $VERSION_FULL..." 2>&1 | tee -a "$TMP_LOG"

	echo "  removing created files..." 2>&1 | tee -a "$TMP_LOG"

	FILE_LIST=`cat "$LOG_NAME" | sed "/^#/d" | sed "/^[^F]/d" | cut -d " " -f 2 | xargs`

	for FILE_NAME in $FILE_LIST ; do
		FILE_NAME2=`echo "$FILE_NAME" | sed "s?%? ?g"`
		echo "    - $FILE_NAME2"
		if [ -z "$1" ] ; then
			rm -r -f "$FILE_NAME2"
		fi
	done

	echo "  restoring backups made during install..." 2>&1 | tee -a "$TMP_LOG"

	FILE_LIST=`cat "$LOG_NAME" | sed "/^#/d" | sed "/^[^B]/d" | cut -d " " -f 2- | sed "s? ?#?g" | xargs`

	for FILE_NAME in $FILE_LIST ; do
		FILE_NAME2=`echo "$FILE_NAME" | sed "s?%? ?g"`
		FILE_NAME3=`echo "$FILE_NAME2" | sed "s?#? -> ?g"`
		FILE_NAME4=`echo "$FILE_NAME2" | sed "s?#? ?g"`
		FILE_NAME5=`echo "$FILE_NAME2" | cut -d "#" -f 1`
		echo "    - $FILE_NAME3"
		if [ -z "$1" ] ; then
			cp -r -f $FILE_NAME4
			rm -r -f $FILE_NAME5 
		fi
	done

	if [ -z "$1" ] ; then
		rm -f "$LOG_NAME"
	fi

	info_message "Finished uninstalling $POVRAY $VERSION_FULL" 2>&1 | tee -a "$TMP_LOG"
	echo "------------------------------------------------------" 2>&1 | tee -a "$TMP_LOG"

	return 1

}

# ==================================================================
#    run a test render to verify installation
# ==================================================================
test_render()
{
	DIR=`pwd`
	VER_STRING=`povray -version 2>&1`
	if echo "$VER_STRING" | grep "3.7.0" > /dev/null ; then
		cp scenes/advanced/biscuit.pov "$HOME/"
		cd "$HOME"
		povray -ibiscuit.pov -f +v +p -w320 -h240 +a0.3 $1 2>&1 | tee -a "$TMP_LOG"
		rm -f ./biscuit.pov
		cd "$DIR"
	else
		error_message "the test render was not successful since the 
program 'povray' (`which povray`) is not a $POVRAY 
executable.  If you did a user install make sure 
the directory where $POVRAY $VERSION_FULL is installed 
is included in PATH prior to other povray 
executables on this system."
	fi
	return 1
}

# ==================================================================
#    update user configuration
# ==================================================================

user_install()
{
  if [ -z "$1" ] ; then
    INSTALL_DIR=`install_dir`
  else
    INSTALL_DIR="$1"
  fi

  INI_MODE=
  CONF_MODE=
  POVINI=

  if [ -z "$INSTALL_DIR" ] ; then
    error_message "user configuration update NOT successful.
The directory where $POVRAY is installed could not be
determined.  Make sure $POVRAY is correctly installed
on this computer"
    return 0
  fi

  echo "------------------------------------------------------"
  echo "updating configuration for user '$USER'..."

  if [ -r "$HOME/.$POV_DIR/$VERSION/povray.ini" ] ; then
    echo "  creating backup of old povray.ini file as povray.ini.old.`date +%Y-%m-%d`" 2>&1 | tee -a "$TMP_LOG"
    cp "$HOME/.$POV_DIR/$VERSION/povray.ini" "$HOME/.$POV_DIR/$VERSION/povray.ini.old.`date +%Y-%m-%d`" 2>&1 | tee -a "$TMP_LOG"
    INI_MODE=1
  else
    test -d "$HOME/.$POV_DIR" || mkdir "$HOME/.$POV_DIR" 2>&1 | tee -a "$TMP_LOG"
    test -d "$HOME/.$POV_DIR/$VERSION" || mkdir "$HOME/.$POV_DIR/$VERSION" 2>&1 | tee -a "$TMP_LOG"

    if [ -r "$HOME/.povrayrc" ] ; then
      echo "  copying .povrayrc file from older version of $POVRAY" 2>&1 | tee -a "$TMP_LOG"
      cp "$HOME/.povrayrc" "$HOME/.$POV_DIR/$VERSION/povray.ini" 2>&1 | tee -a "$TMP_LOG"
      INI_MODE=2
    else
      if [ -r "$SYSCONFDIR/$POV_DIR/$VERSION/povray.ini" ] ; then
        echo "  copying system povray.ini" 2>&1 | tee -a "$TMP_LOG"
        cp "$SYSCONFDIR/$POV_DIR/$VERSION/povray.ini" "$HOME/.$POV_DIR/$VERSION/povray.ini" 2>&1 | tee -a "$TMP_LOG"
        INI_MODE=3
      else
        if [ -r "$SYSCONFDIR/povray.ini" ] ; then
          echo "  copying old system povray.ini" 2>&1 | tee -a "$TMP_LOG"
          cp "$SYSCONFDIR/povray.ini" "$HOME/.$POV_DIR/$VERSION/povray.ini" 2>&1 | tee -a "$TMP_LOG"
          INI_MODE=4
        else
          if [ -r "./povray.ini" ] ; then
            echo "  installing new povray.ini" 2>&1 | tee -a "$TMP_LOG"
            cat ./povray.ini | sed "s?Library_Path=$DEFAULT_DIR/share/$VER_DIR?Library_Path=$BASEDIR/share/$VER_DIR?g" > "$HOME/.$POV_DIR/$VERSION/povray.ini" 2>&1 | tee -a "$TMP_LOG"
            INI_MODE=5
          else
            # should not happen
            INI_MODE=0
            return 0
          fi
        fi
      fi
    fi
  fi

  echo "  updating povray.ini file..." 2>&1 | tee -a "$TMP_LOG"

  add_libpath_ini "$INSTALL_DIR" "$HOME/.$POV_DIR/$VERSION/povray.ini"

  echo "  updating povray.conf file..." 2>&1 | tee -a "$TMP_LOG"

  if [ ! -r "$HOME/.$POV_DIR/$VERSION/povray.conf" ] ; then
    if [ -r "$SYSCONFDIR/$POV_DIR/$VERSION/povray.conf" ] ; then
      echo "  copying system povray.conf" 2>&1 | tee -a "$TMP_LOG"
      test -d "$HOME/.$POV_DIR" || mkdir "$HOME/.$POV_DIR" 2>&1 | tee -a "$TMP_LOG"
      test -d "$HOME/.$POV_DIR/$VERSION" || mkdir "$HOME/.$POV_DIR/$VERSION" 2>&1 | tee -a "$TMP_LOG"
      cp "$SYSCONFDIR/$POV_DIR/$VERSION/povray.conf" "$HOME/.$POV_DIR/$VERSION/povray.conf" 2>&1 | tee -a "$TMP_LOG"
      CONF_MODE=3
    else
      if [ -r "./povray.conf" ] ; then
        echo "  installing new povray.conf" 2>&1 | tee -a "$TMP_LOG"
        test -d "$HOME/.$POV_DIR" || mkdir "$HOME/.$POV_DIR" 2>&1 | tee -a "$TMP_LOG"
        test -d "$HOME/.$POV_DIR/$VERSION" || mkdir "$HOME/.$POV_DIR/$VERSION" 2>&1 | tee -a "$TMP_LOG"
        cp "./povray.conf" "$HOME/.$POV_DIR/$VERSION/povray.conf" 2>&1 | tee -a "$TMP_LOG"
        CONF_MODE=5
      else
        echo "  Warning: povray.conf template not found" 2>&1 | tee -a "$TMP_LOG"
        echo "           i/o restrictions will be disabled" 2>&1 | tee -a "$TMP_LOG"
        CONF_MODE=0
      fi
    fi
  else
		if echo "$INSTALL_DIR" | grep "$HOME"  > /dev/null ; then
			if [ -r "./povray.conf" ] ; then
				echo "  a user povray.conf file already exists." 2>&1 | tee -a "$TMP_LOG"
				echo "  copying the default version as povray.conf.new" 2>&1 | tee -a "$TMP_LOG"
				cp "./povray.conf" "$HOME/.$POV_DIR/$VERSION/povray.conf.new" 2>&1 | tee -a "$TMP_LOG"
				CONF_MODE=6
			fi
		else
			echo "  a user povray.conf file already exists." 2>&1 | tee -a "$TMP_LOG"
			add_read_conf "$INSTALL_DIR/share/$VER_DIR/scenes" 
			add_read_conf "$INSTALL_DIR/share/$VER_DIR/include"
			if [ -r "./povray.conf" ] ; then
				cp "./povray.conf" "$HOME/.$POV_DIR/$VERSION/povray.conf.new" 2>&1 | tee -a "$TMP_LOG"
			fi
			CONF_MODE=7
		fi
	fi

	echo "Finished updating configuration" 2>&1 | tee -a "$TMP_LOG"
	echo "------------------------------------------------------" 2>&1 | tee -a "$TMP_LOG"
	echo "" 2>&1 | tee -a "$TMP_LOG"

	case $INI_MODE in
		"1")
			info_message "It seems you have had $POVRAY $VERSION_FULL installed previously.
The installation has updated the existing povray.ini file.

You should check if the new ini file:

  ~/.$POV_DIR/$VERSION/povray.ini

correctly reflects your configuration."
			;;
		"2")
			info_message "An older version of $POVRAY seems to have been previously
installed on this system.  The installation has copied the
old .povrayrc file and updated it for the new installation.

You should check if the new ini file:

  ~/.$POV_DIR/$VERSION/povray.ini

correctly reflects your configuration."
			;;
		"3")
			info_message "$POVRAY $VERSION_FULL seems to be installed system-wide.  The system
povray.ini has been copied and updated.

You should check if the new ini file:

  ~/.$POV_DIR/$VERSION/povray.ini

correctly reflects your configuration."
			;;
		"4")
			info_message "A system-wide ini file from an older version of $POVRAY
has been found and was copied and updated.

You should check if the new ini file:

  ~/.$POV_DIR/$VERSION/povray.ini

correctly reflects your configuration."
			;;
		"5")
			info_message "$POVRAY does not seem to have been previously installed
on this system.  The installation created a default
povray.ini at:

  $BASEDIR/etc/$POV_DIR/$VERSION/povray.ini

which can be modified for individual requirements."
			;;
	esac

	echo "" 2>&1 | tee -a "$TMP_LOG"

	case $CONF_MODE in
		"3")
			info_message "A user i/o restrictions configuation file has been copied
from the system-wide version.

You should check if the new file:

  ~/.$POV_DIR/$VERSION/povray.conf

correctly reflects your configuration.  If you only want
to use the system file you can also delete this."
			;;
    "5")
			info_message "A new i/o restrictions configuation file has been created:

  ~/.$POV_DIR/$VERSION/povray.conf

See the documentation for how to customize the settings."
			;;
		"6")
			info_message "An existing povray.conf file has been found and was left
as it is.  The default file has been copied as:

  ~/.$POV_DIR/$VERSION/povray.conf.new

for reference."
			;;
		"7")
			info_message "An existing povray.conf file has been found and was modified
for the new configuration.  The default file has been
copied as:

  ~/.$POV_DIR/$VERSION/povray.conf.new

for reference. You should check if the modified file:

  ~/.$POV_DIR/$VERSION/povray.conf

correctly reflects your configuration."
			;;
	esac

	echo "" 2>&1 | tee -a "$TMP_LOG"
	echo "------------------------------------------------------" 2>&1 | tee -a "$TMP_LOG"
	echo "" 2>&1 | tee -a "$TMP_LOG"

	return 1
}

# ==================================================================
#    update system configuration
# ==================================================================

sys_install()
{
  # don't call without parameter for first time install
  if [ -z "$1" ] ; then
    INSTALL_DIR=`install_dir`
  else
    INSTALL_DIR="$1"
  fi

  INI_MODE=
  CONF_MODE=
  POVINI=

  if [ -z "$INSTALL_DIR" ] ; then
    error_message "System configuration update NOT successful.
The directory where $POVRAY is installed could not be
determined.  Make sure $POVRAY is correctly installed
on this computer."
    return 0
  fi

  echo "------------------------------------------------------" 2>&1 | tee -a "$TMP_LOG"
  echo "updating system level configuration..." 2>&1 | tee -a "$TMP_LOG"

  if [ ! -d "$BASEDIR/etc/$POV_DIR/$VERSION" ] ; then
    echo "  creating directory $BASEDIR/etc/$POV_DIR/$VERSION..." 2>&1 | tee -a "$TMP_LOG"
    mkdir -p "$BASEDIR/etc/$POV_DIR/$VERSION" 2>&1 | tee -a "$TMP_LOG"
  fi
  if [ ! -r "$BASEDIR/etc/$POV_DIR/$VERSION/povray.ini" ] ; then
    if [ -r "$BASEDIR/etc/povray.ini" ] ; then
      echo "  copying povray.ini file from older version of $POVRAY" 2>&1 | tee -a "$TMP_LOG"
      cp -f "$BASEDIR/etc/povray.ini" "$BASEDIR/etc/$POV_DIR/$VERSION/povray.ini" 2>&1 | tee -a "$TMP_LOG"
      INI_MODE=2
    else
      echo "  installing new main $POVRAY ini file..." 2>&1 | tee -a "$TMP_LOG"
      cp -f "./povray.ini" "$BASEDIR/etc/$POV_DIR/$VERSION/" 2>&1 | tee -a "$TMP_LOG"
      INI_MODE=5
    fi
  else
    echo "  creating backup of old povray.ini file as povray.ini.old.`date +%Y-%m-%d`" 2>&1 | tee -a "$TMP_LOG"
    cp "$BASEDIR/etc/$POV_DIR/$VERSION/povray.ini" "$BASEDIR/etc/$POV_DIR/$VERSION/povray.ini.old.`date +%Y-%m-%d`"  2>&1 | tee -a "$TMP_LOG"
    INI_MODE=1
  fi

  echo "  updating main $POVRAY ini file..." 2>&1 | tee -a "$TMP_LOG"
  add_libpath_ini "$BASEDIR" "$BASEDIR/etc/$POV_DIR/$VERSION/povray.ini"

  chmod 644 "$BASEDIR/etc/$POV_DIR/$VERSION/povray.ini" 2>&1 | tee -a "$TMP_LOG"

  if [ ! -r "$BASEDIR/etc/$POV_DIR/$VERSION/povray.conf" ] ; then
    echo "  installing $POVRAY configuration file..." 2>&1 | tee -a "$TMP_LOG"
    cp -f "./povray.conf" "$BASEDIR/etc/$POV_DIR/$VERSION/povray.conf" 2>&1 | tee -a "$TMP_LOG"
    chmod 644 "$BASEDIR/etc/$POV_DIR/$VERSION/povray.conf" 2>&1 | tee -a "$TMP_LOG"
    CONF_MODE=5
  else
    echo "  a system povray.conf file already exists." 2>&1 | tee -a "$TMP_LOG"
    echo "  copying the default version as povray.conf.new" 2>&1 | tee -a "$TMP_LOG"
    cp -f "./povray.conf" "$BASEDIR/etc/$POV_DIR/$VERSION/povray.conf.new" 2>&1 | tee -a "$TMP_LOG"
    chmod 644 "$BASEDIR/etc/$POV_DIR/$VERSION/povray.conf.new" 2>&1 | tee -a "$TMP_LOG"
    CONF_MODE=6
    #echo "  creating backup from old POV-Ray configuration file as povray.conf.old"
    #mv -f "$BASEDIR/etc/povray/$VERSION/povray.conf" "$BASEDIR/etc/povray/$VERSION/povray.conf.old"
    #echo "  creating new $BASEDIR/etc/povray/$VERSION/povray.conf"
    #cp -f ./povray.conf "$BASEDIR/etc/povray/$VERSION/povray.conf"
    #chmod 644 "$BASEDIR/etc/povray/$VERSION/povray.conf"
  fi

  echo "Finished updating configuration" 2>&1 | tee -a "$TMP_LOG"
  echo "------------------------------------------------------" 2>&1 | tee -a "$TMP_LOG"
  echo "" 2>&1 | tee -a "$TMP_LOG"

  case $INI_MODE in
    "1")
			info_message "$POVRAY $VERSION has seemingly already been installed on this
system before.  The installation has updated the existing
povray.ini file.

You should check if the new ini file:

  $BASEDIR/etc/$POV_DIR/$VERSION/povray.ini

correctly reflects your configuration."
      ;;
    "2")
			info_message "A previous installation of $POVRAY has been found on this
system.  The installation has copied the old povray.ini
file and updated it for the new installation.

You should check if the new ini file:

  $BASEDIR/etc/$POV_DIR/$VERSION/povray.ini

correctly reflects your configuration."
      ;;
    "5")
			info_message "$POVRAY does not seem to have been previously installed
on this system.  The installation created a default
povray.ini at:

  $BASEDIR/etc/$POV_DIR/$VERSION/povray.ini

which can be modified for individual requirements."
      ;;
  esac

  echo "" 2>&1 | tee -a "$TMP_LOG"

  case $CONF_MODE in
    "5")
			info_message "A new i/o restrictions configuation file has been created:

  $BASEDIR/etc/$POV_DIR/$VERSION/povray.conf

See the documentation for how to customize the settings."
      ;;
    "6")
			info_message "An existing povray.conf file has been found and was left
as it is.  The default file has been copied as:

  $BASEDIR/etc/$POV_DIR/$VERSION/povray.conf.new

for reference."
      ;;
  esac

	if [ ! -z "$KDIALOG" ] ; then
		kdialog --caption "$POVRAY $VERSION_FULL installation" --yesno "The install script can now run a short test render to check if $POVRAY is correctly configured.  This test render will be without display since this will often not work correctly in superuser mode.  Run a test render?"

		if [ $? -eq 1 ] ; then
			INPUT="S"
		else
			INPUT="R"
		fi
	else	
		echo ""
		echo "------------------------------------------------------"
		echo ""
		echo "  The install script can now run a short test render"
		echo "  to check if $POVRAY is correctly configured."
		echo "  This test render will be without display since this"
		echo "  will often not work correctly in superuser mode."
		echo ""
		echo "  Type 'R' to run the test"
		echo "  Type 'S' to skip it."
		echo ""
		read_input INPUT "Your choice ([R]/S): "

		echo ""
	fi

  case $INPUT in
    "s" | "S")
      echo ""
      echo "  skipping test render..."
    ;;
    *)
      echo ""
      echo "  running test render..."
			test_render "-d"
    ;;
  esac

  echo ""
  echo "------------------------------------------------------"
  echo ""

  return 1
}

# ==================================================================
#    Install configuration files
# ==================================================================

conf_install()
{
	if [ "$BASEDIR" = "$DEFAULT_DIR" ] ; then

		# --- system based installation ---

		sys_install "$BASEDIR"
		kde_install "$BASEDIR"

		info_message "Finished installing POV-Ray $VERSION_FULL

This install script can also add some useful entries to
the KDE panel if KDE is installed.  Running:

  install kde

as a user will add entries for this user.
"

	else

		# --- user level installation ---

		user_install "$BASEDIR"

		test -z "$KDEHOME" && KDEHOME="$HOME/.kde"
		if [ -w "$KDEHOME" ] ; then
			kde_install_user "$BASEDIR"
		fi

		info_message "Finished installing POV-Ray $VERSION_FULL
The POV-Ray files have been copied to $BASEDIR.

For completing the installation of POV-Ray you will have
to set your PATH and MANPATH environment variables to
point to your custom installation location.
"

	fi
}

# ==================================================================
#    Copy files
# ==================================================================

copy_files()
{
	log_install

	echo "------------------------------------------------------" 2>&1 | tee -a "$TMP_LOG"
	echo "Copying files..." 2>&1 | tee -a "$TMP_LOG"

	if [ ! -d "$BASEDIR" ] ; then
		echo "  creating directory $BASEDIR..." 2>&1 | tee -a "$TMP_LOG"
		mkdir "$BASEDIR" 2>&1 | tee -a "$TMP_LOG"
	fi
	if [ ! -d "$BASEDIR/share" ] ; then
		echo "  creating directory $BASEDIR/share..." 2>&1 | tee -a "$TMP_LOG"
		mkdir "$BASEDIR/share" 2>&1 | tee -a "$TMP_LOG"
	fi

	echo "  creating supplementary files directory ($BASEDIR/share/$VER_DIR)..." 2>&1 | tee -a "$TMP_LOG"

	if [ -d "$BASEDIR/share/$VER_DIR" ] ; then

		if [ ! -z "$KDIALOG" ] ; then
			kdialog --caption "$POVRAY $VERSION_FULL installation" --yesno "Directory $BASEDIR/share/$VER_DIR already exists.  Do you want to create a backup of the current content before installing?"

			if [ $? -eq 1 ] ; then
				INPUT="W"
			else
				INPUT="B"
			fi
		else	
			echo "  Directory $BASEDIR/share/$VER_DIR already exists."
			echo "  Type 'B' to make a backup"
			echo "  Type 'W' to overwrite current content"
			echo ""
			read_input INPUT "Your choice ([B]/W): "

			echo ""
		fi

		case $INPUT in
			"w" | "W")
				echo "" 2>&1 | tee -a "$TMP_LOG"
				echo "  clearing $BASEDIR/share/$VER_DIR" 2>&1 | tee -a "$TMP_LOG"
				rm -rf "$BASEDIR/share/$VER_DIR" 2>&1 | tee -a "$TMP_LOG"
				mkdir "$BASEDIR/share/$VER_DIR" 2>&1 | tee -a "$TMP_LOG"

				log_install "F" "$BASEDIR/share/$VER_DIR"
				;;
			*)
				echo "" 2>&1 | tee -a "$TMP_LOG"
				echo "  creating backup of $BASEDIR/share/$VER_DIR" 2>&1 | tee -a "$TMP_LOG"
				echo "  as $BASEDIR/share/$VER_DIR.bak" 2>&1 | tee -a "$TMP_LOG"
				rm -rf "$BASEDIR/share/$VER_DIR.bak" 2>&1 | tee -a "$TMP_LOG"
				mv -f "$BASEDIR/share/$VER_DIR" "$BASEDIR/share/$VER_DIR.bak" 2>&1 | tee -a "$TMP_LOG"
				mkdir "$BASEDIR/share/$VER_DIR" 2>&1 | tee -a "$TMP_LOG"

				log_install "B" "$BASEDIR/share/$VER_DIR.bak" "$BASEDIR/share/$VER_DIR"
			;;
		esac

	else
		mkdir "$BASEDIR/share/$VER_DIR" 2>&1 | tee -a "$TMP_LOG"

		log_install "F" "$BASEDIR/share/$VER_DIR"
	fi

	echo "  copying include files..." 2>&1 | tee -a "$TMP_LOG"
	cp -r ./include "$BASEDIR/share/$VER_DIR/" 2>&1 | tee -a "$TMP_LOG"
	echo "  copying sample scenes..." 2>&1 | tee -a "$TMP_LOG"
	cp -r ./scenes "$BASEDIR/share/$VER_DIR/" 2>&1 | tee -a "$TMP_LOG"
	echo "  copying ini files..." 2>&1 | tee -a "$TMP_LOG"
	cp -r ./ini "$BASEDIR/share/$VER_DIR/" 2>&1 | tee -a "$TMP_LOG"
	echo "  copying script files..." 2>&1 | tee -a "$TMP_LOG"
	cp -r ./scripts "$BASEDIR/share/$VER_DIR/" 2>&1 | tee -a "$TMP_LOG"
	echo "  copying icon files..." 2>&1 | tee -a "$TMP_LOG"
	cp -r ./icons "$BASEDIR/share/$VER_DIR/" 2>&1 | tee -a "$TMP_LOG"

	if [ ! -d "$BASEDIR/man" ] ; then
		echo "  creating directory $BASEDIR/man..." 2>&1 | tee -a "$TMP_LOG"
		mkdir "$BASEDIR/man" 2>&1 | tee -a "$TMP_LOG"
	fi
	if [ ! -d "$BASEDIR/man/man1" ] ; then
		echo "  creating directory $BASEDIR/man/man1..." 2>&1 | tee -a "$TMP_LOG"
		mkdir "$BASEDIR/man/man1" 2>&1 | tee -a "$TMP_LOG"
	fi

	echo "  copying POV-Ray man page..." 2>&1 | tee -a "$TMP_LOG"
	cp -f ./povray.1 "$BASEDIR/man/man1/" 2>&1 | tee -a "$TMP_LOG"
	chmod 644 "$BASEDIR/man/man1/povray.1" 2>&1 | tee -a "$TMP_LOG"

	log_install "F" "$BASEDIR/man/man1/povray.1"

	if [ ! -d "$BASEDIR/bin" ] ; then
		echo "  creating directory $BASEDIR/bin..." 2>&1 | tee -a "$TMP_LOG"
		mkdir "$BASEDIR/bin" 2>&1 | tee -a "$TMP_LOG"
	fi

	echo "  copying POV-Ray executable..." 2>&1 | tee -a "$TMP_LOG"
	if [ -r "$BASEDIR/bin/povray" ] ; then
		echo "    - creating backup from old POV-Ray executable as povray.old.`date +%Y-%m-%d`" 2>&1 | tee -a "$TMP_LOG"
		mv -f "$BASEDIR/bin/povray" "$BASEDIR/bin/povray.old.`date +%Y-%m-%d`" 2>&1 | tee -a "$TMP_LOG"
		log_install "B" "$BASEDIR/bin/povray.old.`date +%Y-%m-%d`" "$BASEDIR/bin/povray"
	else
		log_install "F" "$BASEDIR/bin/povray"
	fi
	cp -f ./povray "$BASEDIR/bin/" 2>&1 | tee -a "$TMP_LOG"
	chmod 755 "$BASEDIR/bin/povray" 2>&1 | tee -a "$TMP_LOG"

	if [ ! -d "$BASEDIR/share/doc" ] ; then
		echo "  creating directory $BASEDIR/share/doc..." 2>&1 | tee -a "$TMP_LOG"
		mkdir "$BASEDIR/share/doc" 2>&1 | tee -a "$TMP_LOG"
	fi
	if [ ! -d "$BASEDIR/share/doc/$VER_DIR" ] ; then
		echo "  creating directory $BASEDIR/share/doc/$VER_DIR..." 2>&1 | tee -a "$TMP_LOG"
		mkdir "$BASEDIR/share/doc/$VER_DIR" 2>&1 | tee -a "$TMP_LOG"
		log_install "F" "$BASEDIR/share/doc/$VER_DIR" 2>&1 | tee -a "$TMP_LOG"
	else
		echo "" 2>&1 | tee -a "$TMP_LOG"
		echo "  creating backup of $BASEDIR/share/doc/$VER_DIR" 2>&1 | tee -a "$TMP_LOG"
		echo "  as $BASEDIR/share/doc/$VER_DIR.bak" 2>&1 | tee -a "$TMP_LOG"
		rm -rf "$BASEDIR/share/doc/$VER_DIR.bak" 2>&1 | tee -a "$TMP_LOG"
		mv -f "$BASEDIR/share/doc/$VER_DIR" "$BASEDIR/share/doc/$VER_DIR.bak" 2>&1 | tee -a "$TMP_LOG"
		mkdir "$BASEDIR/share/doc/$VER_DIR" 2>&1 | tee -a "$TMP_LOG"
		log_install "B" "$BASEDIR/share/doc/$VER_DIR.bak" "$BASEDIR/share/doc/$VER_DIR"
	fi
	echo "  copying POV-Ray documentation..." 2>&1 | tee -a "$TMP_LOG"
	cp -r -f ./doc/* "$BASEDIR/share/doc/$VER_DIR/" 2>&1 | tee -a "$TMP_LOG"

	echo "Finished copying files" 2>&1 | tee -a "$TMP_LOG"
}

# ==================================================================
#    hardware architecture compatibility test
# ==================================================================

arch_check()
{
	SYSNAME=`uname -s`
	ARCHNAME=`uname -m`

	MATCH=

	case $TARGET_PLATFORM in
		x86 )
			case $ARCHNAME in
				i?86* | athlon* )
					case $SYSNAME in
						Linux | linux) MATCH=true ;;
					esac
				;;
			esac
		;;
		x86_64 )
			case $ARCHNAME in
				x86_64* )
					case $SYSNAME in
						Linux | linux) MATCH=true ;;
					esac
				;;
			esac
		;;
	esac

	if [ -z "$MATCH" ] ; then
		error_message "This machine does not seem to be a $TARGET_PLATFORM_NAME computer.
This version of POV-Ray only runs on $TARGET_PLATFORM_NAME machines.
You can obtain a version appropriate for your architecture
on http://www.povray.org/

If you want to force an installation you can use

  install -no-arch-check"
		exit
	fi
}

# ==================================================================


echo "" 2>&1 | tee -a "$TMP_LOG"
echo "$POVRAY $VERSION_FULL installation" 2>&1 | tee -a "$TMP_LOG"
echo "=============================" 2>&1 | tee -a "$TMP_LOG"
echo "" 2>&1 | tee -a "$TMP_LOG"

# ==================================================================

SKIP_ARCH=
TEXT_MODE=
QUIET=
SKIP=

case $1 in
	--h* | -h*)
		echo "Invocation syntax:"
		echo ""
		echo " install [-no-arch-check] [text] [kde|user|uninstall|test]"
		echo ""
		echo "  -no-arch-check    skip hardware compatibility test"
		echo "  text              do not use kdialog even if available"
		echo "  kde               install kde integration for current user"
		echo "  user              install configuration files for current user"
		echo "  uninstall         uninstall for current user"
		echo "  test              run test render"
		echo ""
		exit
		;;
	--n* | -n*)
		echo "skipping architecture compatibility test." 2>&1 | tee -a "$TMP_LOG"
		SKIP_ARCH=on
		PARAMETER=$2
		;;
  text | quiet)
		PARAMETER=$2
		;;
	*)
		PARAMETER=$1
		SKIP=on
		;;
esac

if [ -z "$SKIP" ] ; then

case $2 in
  text | quiet)
		PARAMETER=$3
		;;
	*)
		PARAMETER=$2
		SKIP=on
		;;
esac

fi

if [ -z "$SKIP" ] ; then

case $3 in
  text | quiet)
		PARAMETER=$4
		;;
	*)
		PARAMETER=$3
		SKIP=on
		;;
esac

fi

if [ ! -z "$SKIP_ARCH" ] ; then
	arch_check
fi

case $PARAMETER in
  kde* | KDE* | Kde* )

    kde_install
    kde_install_user

    exit
    ;;

  user* | USER* | User* )

    user_install

    exit
    ;;

  uninstall* | UNINSTALL* | Uninstall* )

    uninstall

    exit
    ;;

  test* | TEST* | Test* )

    test_render "+d"

    exit
    ;;

esac

prepare_bin_install
select_target_dir
copy_files
conf_install

# ==================================================================