"Fossies" - the Fresh Open Source Software Archive

Member "xterm-379/df-install.in" (18 Aug 2020, 4211 Bytes) of package /linux/misc/xterm-379.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh
    2 # $XTermId: df-install.in,v 1.17 2020/08/18 20:44:00 tom Exp $
    3 # -----------------------------------------------------------------------------
    4 # this file is part of xterm
    5 #
    6 # Copyright 2011-2018,2020 by Thomas E. Dickey
    7 #
    8 #                         All Rights Reserved
    9 #
   10 # Permission is hereby granted, free of charge, to any person obtaining a
   11 # copy of this software and associated documentation files (the
   12 # "Software"), to deal in the Software without restriction, including
   13 # without limitation the rights to use, copy, modify, merge, publish,
   14 # distribute, sublicense, and/or sell copies of the Software, and to
   15 # permit persons to whom the Software is furnished to do so, subject to
   16 # the following conditions:
   17 #
   18 # The above copyright notice and this permission notice shall be included
   19 # in all copies or substantial portions of the Software.
   20 #
   21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   22 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   23 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   24 # IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
   25 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   26 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   27 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   28 #
   29 # Except as contained in this notice, the name(s) of the above copyright
   30 # holders shall not be used in advertising or otherwise to promote the
   31 # sale, use or other dealings in this Software without prior written
   32 # authorization.
   33 # -----------------------------------------------------------------------------
   34 #
   35 # Install desktop-files, substituting the category to customize the file
   36 # to the current system's conventions.
   37 #
   38 # Parameters are passed to the desktop-file-install program.  The last
   39 # parameter is the name of the ".desktop" file to install.
   40 
   41 failed() {
   42     echo "? $*" >&2
   43     exit 1
   44 }
   45 
   46 OPTS=
   47 
   48 if test $# != 0
   49 then
   50     APP_NAME=$1
   51     shift 1
   52 fi
   53 
   54 if test $# != 0
   55 then
   56     ICON_NAME=$1
   57     shift 1
   58 fi
   59 
   60 TOOL=desktop-file-install
   61 
   62 CDPATH=:
   63 export CDPATH
   64 
   65 while test $# != 0
   66 do
   67     case .$1 in #(vi
   68     .DESTDIR=*) #(vi
   69         if test "$1" != "DESTDIR="
   70         then
   71             DESTDIR=`echo "$1" | sed -e 's,^DESTDIR=,,'`
   72         fi
   73         ;;
   74     *.desktop) #(vi
   75         if test $# = 1
   76         then
   77             OLD_FILE=$1
   78         else
   79             OPTS="$OPTS $1"
   80         fi
   81         ;;
   82     .--dir=*) #(vi
   83         OPTS="$OPTS $1"
   84         DESTDIR=
   85         ;;
   86     *)
   87         OPTS="$OPTS $1"
   88         ;;
   89     esac
   90     shift 1
   91 done
   92 
   93 # If DESTDIR is set (either as an environment variable, or command-line
   94 # parameter), attempt to determine the full pathname (needed by the installer)
   95 # to tell it to use the alternate location.  Because the installer has no
   96 # useful options for this purpose, we search along the path to find the tool,
   97 # and from that get the prefix, and assume that was the extent of customization
   98 # when the tool was configured/installed.
   99 if test -n "$DESTDIR"
  100 then
  101     if test -d "$DESTDIR"
  102     then
  103         prefix=
  104 
  105         save_IFS="$IFS"
  106         IFS=':'
  107         for P in $PATH
  108         do
  109             test -z "$P" && P=.
  110             if test -f "$P/$TOOL"
  111             then
  112                 prefix=`echo "$P" | sed -e 's,/[^/]*$,,'`
  113                 break
  114             fi
  115         done
  116         IFS="$save_IFS"
  117 
  118         test -z "$prefix" && failed "could not find $TOOL in PATH"
  119 
  120         TARGET="${DESTDIR}${prefix}/share/applications"
  121         mkdir -p "$TARGET"
  122 
  123         OPTS="$OPTS --dir=${TARGET}"
  124     else
  125         failed "DESTDIR is not a directory: $DESTDIR"
  126     fi
  127 fi
  128 
  129 MY_TEMP=tempdir$$
  130 rm -rf $MY_TEMP
  131 
  132 if test -z "$OLD_FILE"
  133 then
  134     failed "not found: $OLD_FILE"
  135 elif ! mkdir $MY_TEMP
  136 then
  137     failed "cannot mkdir: $MY_TEMP"
  138 fi
  139 
  140 # The newer dfi whines about deprecation of encoding, but no release provides
  141 # --version or equivalent.  really.
  142 if desktop-file-install --help-all >/dev/null 2>&1
  143 then
  144     NO_ENCODING="#Encoding"
  145 else
  146     NO_ENCODING="Encoding"
  147 fi
  148 
  149 NEW_FILE=`basename "$OLD_FILE"`
  150 sed \
  151     -e '/^Encoding=/s%Encoding%'"$NO_ENCODING"'%' \
  152     -e '/^[^#]*Icon=/s%=.*%='"$ICON_NAME"'%' \
  153     -e '/^[^#]*Category=/s%=.*%=@DESKTOP_CATEGORY@%' \
  154     -e '/^[^#]*Categories=/s%=.*%=@DESKTOP_CATEGORY@%' \
  155     -e '/^[^#]/s%xterm%'"$APP_NAME"'%g' \
  156     -e '/^[^#]/s%XTerm%@APP_CLASS@%g' \
  157     "$OLD_FILE" >"$MY_TEMP/$NEW_FILE"
  158 diff -u "$OLD_FILE" "$MY_TEMP/$NEW_FILE"
  159 cd $MY_TEMP || exit 1
  160 
  161 "$TOOL" $OPTS "$NEW_FILE"
  162 
  163 cd ..
  164 rm -rf $MY_TEMP
  165 
  166 # vi:ts=4 sw=4