forked from ThomasDickey/xterm-snapshots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdf-install.in
166 lines (147 loc) · 4.11 KB
/
df-install.in
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
#!/bin/sh
# $XTermId: df-install.in,v 1.17 2020/08/18 20:44:00 tom Exp $
# -----------------------------------------------------------------------------
# this file is part of xterm
#
# Copyright 2011-2018,2020 by Thomas E. Dickey
#
# All Rights Reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Except as contained in this notice, the name(s) of the above copyright
# holders shall not be used in advertising or otherwise to promote the
# sale, use or other dealings in this Software without prior written
# authorization.
# -----------------------------------------------------------------------------
#
# Install desktop-files, substituting the category to customize the file
# to the current system's conventions.
#
# Parameters are passed to the desktop-file-install program. The last
# parameter is the name of the ".desktop" file to install.
failed() {
echo "? $*" >&2
exit 1
}
OPTS=
if test $# != 0
then
APP_NAME=$1
shift 1
fi
if test $# != 0
then
ICON_NAME=$1
shift 1
fi
TOOL=desktop-file-install
CDPATH=:
export CDPATH
while test $# != 0
do
case .$1 in #(vi
.DESTDIR=*) #(vi
if test "$1" != "DESTDIR="
then
DESTDIR=`echo "$1" | sed -e 's,^DESTDIR=,,'`
fi
;;
*.desktop) #(vi
if test $# = 1
then
OLD_FILE=$1
else
OPTS="$OPTS $1"
fi
;;
.--dir=*) #(vi
OPTS="$OPTS $1"
DESTDIR=
;;
*)
OPTS="$OPTS $1"
;;
esac
shift 1
done
# If DESTDIR is set (either as an environment variable, or command-line
# parameter), attempt to determine the full pathname (needed by the installer)
# to tell it to use the alternate location. Because the installer has no
# useful options for this purpose, we search along the path to find the tool,
# and from that get the prefix, and assume that was the extent of customization
# when the tool was configured/installed.
if test -n "$DESTDIR"
then
if test -d "$DESTDIR"
then
prefix=
save_IFS="$IFS"
IFS=':'
for P in $PATH
do
test -z "$P" && P=.
if test -f "$P/$TOOL"
then
prefix=`echo "$P" | sed -e 's,/[^/]*$,,'`
break
fi
done
IFS="$save_IFS"
test -z "$prefix" && failed "could not find $TOOL in PATH"
TARGET="${DESTDIR}${prefix}/share/applications"
mkdir -p "$TARGET"
OPTS="$OPTS --dir=${TARGET}"
else
failed "DESTDIR is not a directory: $DESTDIR"
fi
fi
MY_TEMP=tempdir$$
rm -rf $MY_TEMP
if test -z "$OLD_FILE"
then
failed "not found: $OLD_FILE"
elif ! mkdir $MY_TEMP
then
failed "cannot mkdir: $MY_TEMP"
fi
# The newer dfi whines about deprecation of encoding, but no release provides
# --version or equivalent. really.
if desktop-file-install --help-all >/dev/null 2>&1
then
NO_ENCODING="#Encoding"
else
NO_ENCODING="Encoding"
fi
NEW_FILE=`basename "$OLD_FILE"`
sed \
-e '/^Encoding=/s%Encoding%'"$NO_ENCODING"'%' \
-e '/^[^#]*Icon=/s%=.*%='"$ICON_NAME"'%' \
-e '/^[^#]*Category=/s%=.*%=@DESKTOP_CATEGORY@%' \
-e '/^[^#]*Categories=/s%=.*%=@DESKTOP_CATEGORY@%' \
-e '/^[^#]/s%xterm%'"$APP_NAME"'%g' \
-e '/^[^#]/s%XTerm%@APP_CLASS@%g' \
"$OLD_FILE" >"$MY_TEMP/$NEW_FILE"
diff -u "$OLD_FILE" "$MY_TEMP/$NEW_FILE"
cd $MY_TEMP || exit 1
"$TOOL" $OPTS "$NEW_FILE"
cd ..
rm -rf $MY_TEMP
# vi:ts=4 sw=4