summaryrefslogtreecommitdiffstats
path: root/redhat/tdebase/kdebase-3.5.13.1-fix_startkde_path.patch
blob: 971daf16f2a3689d4afc43b700594a87c1246af3 (plain)
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
--- bin/startkde.ORI	2012-11-16 20:44:01.763131101 +0100
+++ bin/startkde	2012-11-16 21:24:12.865147976 +0100
@@ -15,6 +15,26 @@
   source $HOME/.xprofile
 fi
 
+# Some functions to parse and check path correctly ...
+is_in_path() {
+  search="$1"; ifs="$IFS"; IFS=":"; set $PATH; IFS="$ifs"
+  for i in $*; do
+    [ "${i}" = "${search}" ] && return 0
+  done
+  return 1
+}
+
+# Usage: place_before_in_path /opt/trinity/games /usr/games
+place_before_in_path() {
+  insert="$1"; before="$2"; ifs="$IFS"; IFS=":"; set $PATH; IFS="$ifs"
+  NPATH=""
+  for i in $*; do
+    [ "${i}" = "${before}" ] && NPATH="${NPATH}:${insert}"
+    NPATH="${NPATH}:${i}"
+  done
+  export PATH=${NPATH}
+}
+
 echo "[startkde] Starting startkde." 1>&2
 echo "[startkde] This script is $0" 1>&2
 
@@ -29,7 +49,7 @@
 # Do not use kde-config to determine the version. That command creates a
 # profile directory in the root of the file system. Refer to Bug Report 293.
 if [ -x $BIN_DIR/konqueror ]; then
-  KDE_VERSION="`$BIN_DIR/konqueror --version | grep KDE | awk '{print $2}'`"
+  KDE_VERSION=$($BIN_DIR/konqueror --version | while IFS=: read a b; do [[ "$a" =~ "KDE" ]] && echo $b; done)
   echo "[startkde] TDE version is $KDE_VERSION" 1>&2
   export KDEDIR=${BIN_DIR%/bin}
   echo "[startkde] TDE base directory is $KDEDIR" 1>&2
@@ -105,27 +125,12 @@
   # This script and kstandardirs.h and kstandardirs.cpp must match.
   # The latter two must be edited/patched before compiling.
   echo "[startkde] KDEHOME is not set." 1>&2
-  if [ -d $HOME/.trinity ]; then
-    # OK, this one is obvious.
-    export KDEHOME=$HOME/.trinity
-  elif [ -f /usr/bin/kde4-config ]; then
-    # Looks like KDE4 is installed.
-    if [ -d $HOME/.kde ] && [ ! -d $HOME/.trinity ]; then
-      # Presume $HOME/.kde is being used for KDE4 as it already exists.
-      export KDEHOME=$HOME/.trinity
-    else
-      # Presume $HOME/.kde is being used for KDE4 to be on the safe side.
-      export KDEHOME=$HOME/.trinity
-    fi
-  elif [ -f /opt/trinity/bin/kde-config ]; then
-    # Looks like Trinity is installed.
-    export KDEHOME=$HOME/.trinity
-  elif [ -f /usr/bin/kde-config ] && [ -d $HOME/.kde ]; then
+  # Default value: $HOME/.trinity. Most users will use this.
+  export KDEHOME=$HOME/.trinity
+
+  if [ ! -d $HOME/.trinity ] && [ ! -f /usr/bin/kde4-config ] && [ -f /usr/bin/kde-config ] && [ -d $HOME/.kde ]; then
     # Looks like Trinity is installed and not playing second fiddle to KDE4.
     export KDEHOME=$HOME/.kde
-  else
-    # Resort to this and hope for the best!
-    export KDEHOME=$HOME/.trinity
   fi
   echo "[startkde] Set KDEHOME to $KDEHOME." 1>&2
 fi
@@ -149,30 +154,30 @@
 
 # Modify the following environment variables only as necessary.
 if [ -d $KDEDIR/games ]; then
-  if [ "`echo $PATH | grep \"$KDEDIR/games\"`" = "" ]; then
+  if ! is_in_path "$KDEDIR/games" ; then
     # Respect the traditional path order. Don't blindly place $KDEDIR/games
     # first in the path. Only place $KDEDIR/games before /usr/games. If packagers
     # are adding $KDEDIR/games elsewhere, then they need to ensure the traditional
     # search patch is respected.
     # Is there a way we can check that $KDEDIR/games is always placed only just before
     # /usr/games in the search path?
-    if [ "`echo $PATH | grep \"^\\(.*:\\)\\?/usr/games\\(:.*\\)\\?$\"`" != "" ]; then
-      export PATH="`echo $PATH | sed \"s|^\\(.*:\\)\\?/usr/games\\(:.*\\)\\?$|\\1$KDEDIR/games:/usr/games\\2|\"`"
+    if is_in_path "/usr/games"; then
+      place_before_in_path "$KDEDIR/games" "/usr/games"
     else
       export PATH=$KDEDIR/games:$PATH
     fi
   fi
 fi
 if [ -d $KDEDIR/bin ]; then
-  if [ "`echo $PATH | grep \"$KDEDIR/bin\"`" = "" ]; then
+  if ! is_in_path "$KDEDIR/bin" ]; then
     # Respect the traditional path order. Don't blindly place $KDEDIR/bin
     # first in the path. Only place $KDEDIR/bin before /usr/bin. This order is
     # consistent with kdelibs/kdesu/stub.cpp. If packagers are adding $KDEDIR/bin
     # elsewhere, then they need to ensure the traditional search patch is respected.
     # Is there a way we can check that $KDEDIR/bin is always placed only just before
     # /usr/bin in the search path?
-    if [ "`echo $PATH | grep \"^\\(.*:\\)\\?/usr/bin\\(:.*\\)\\?$\"`" != "" ]; then
-      export PATH="`echo $PATH | sed \"s|^\\(.*:\\)\\?/usr/bin\\(:.*\\)\\?$|\\1$KDEDIR/bin:/usr/bin\\2|\"`"
+    if is_in_path "/usr/bin"; then
+      place_before_in_path "$KDEDIR/bin" "/usr/bin"
     else
       export PATH=$KDEDIR/bin:$PATH
     fi