Skip to content

Commit 34b7c44

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents 0532604 + 66a9605 commit 34b7c44

File tree

1 file changed

+124
-15
lines changed

1 file changed

+124
-15
lines changed

doinstall

Lines changed: 124 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,72 @@ check_gtk_bin() {
2626
fi
2727
}
2828

29+
# Find all conflicting libraries between gtk-bin and target directory
30+
# Outputs a list of conflicting library filenames
31+
find_conflicting_libs() {
32+
local target_dir=$1
33+
34+
# Check lib and lib64 directories for conflicts
35+
for gtk_lib_dir in lib lib64; do
36+
if [ -d "$gtk_bin_dir/$gtk_lib_dir" ]; then
37+
# Check all files in gtk-bin lib directory
38+
for file in "$gtk_bin_dir/$gtk_lib_dir"/*; do
39+
if [ -e "$file" ]; then
40+
filename=$(basename "$file")
41+
# Check if file exists in target lib or lib64
42+
if [ -e "$target_dir/lib/$filename" ] || [ -e "$target_dir/lib64/$filename" ]; then
43+
echo "$filename"
44+
fi
45+
fi
46+
done
47+
fi
48+
done
49+
}
50+
51+
# Ask user about conflicting libraries
52+
ask_about_conflicts() {
53+
local conflicts_list=$1
54+
55+
echo ""
56+
echo " The following libraries present in the installation package already"
57+
echo " exist in the target directory:"
58+
echo ""
59+
echo "$conflicts_list" | while read lib; do
60+
echo " - $lib"
61+
done
62+
echo ""
63+
printf " Do you want to overwrite these libraries [y/N] ? "
64+
read x
65+
if [ "$x" = "y" -o "$x" = "Y" ]; then
66+
return 0
67+
else
68+
return 1
69+
fi
70+
}
71+
2972
## Read the base directory (absolute path name)
3073
## Sets the variable $basedir
3174
ask_basedir() {
3275
clear
33-
default_dir=/opt/gtkada
34-
cat <<EOF
76+
default_dir="`type gnatmake 2>/dev/null| cut -d' ' -f3`"
77+
default_dir="`dirname \"$default_dir\" 2>/dev/null`"
78+
79+
if [ "$default_dir" != "" -a "$default_dir" != "." -a "$default_dir" != "/usr/bin" ]; then
80+
default_dir="`cd "$default_dir/.."; pwd`"
81+
cat <<EOF
82+
83+
GNAT has been found in $default_dir.
84+
Do you want to install GtkAda there too? Hit RETURN if yes or enter
85+
the name of the directory in which GtkAda should be installed:
86+
87+
EOF
88+
else
89+
default_dir=/opt/gtkada
90+
cat <<EOF
3591
Enter the name of the directory in which you would like to install GtkAda
3692
3793
EOF
94+
fi
3895

3996
while [ "$basedir" = "" ]; do
4097
printf "[$default_dir] "
@@ -88,6 +145,16 @@ EOF
88145
mkdir -p "$basedir"
89146
fi
90147

148+
# Check for conflicting libraries
149+
conflicting_libs=$(find_conflicting_libs "$basedir")
150+
if [ -n "$conflicting_libs" ]; then
151+
if ! ask_about_conflicts "$conflicting_libs"; then
152+
skip_overwriting_libs=1
153+
# Store the list of conflicting files for later use
154+
conflicting_files="$conflicting_libs"
155+
fi
156+
fi
157+
91158
echo ""
92159
printf " Are you now ready to proceed with the installation [Y/n] ? "
93160
read x
@@ -105,21 +172,35 @@ install_binaries() {
105172

106173
echo "Copying the Gtk+ binaries"
107174

108-
cp -ri "$gtk_bin_dir"/* "$basedir"
175+
# Copy binaries, excluding conflicting libs if requested
176+
if [ "$skip_overwriting_libs" = "1" ]; then
177+
# Detect conflicting files if not already detected (e.g., in non-interactive mode)
178+
if [ -z "$conflicting_files" ]; then
179+
conflicting_files=$(find_conflicting_libs "$basedir")
180+
fi
181+
182+
# Create tar with exclude patterns for each conflicting file
183+
# Build the exclude arguments dynamically from the detected conflicts
184+
( cd "$gtk_bin_dir" && \
185+
tar $(echo "$conflicting_files" | sed 's/^/--exclude=*\//' | tr '\n' ' ') -cf - . ) | \
186+
( cd "$basedir" && tar -xf - )
187+
else
188+
cp -r "$gtk_bin_dir"/* "$basedir"
189+
fi
109190

110191
echo "Setting up the environment"
111192
eval `"$basedir"/bin/gtkada-env.sh --print-only`
112193

113194
# Update gdkpixbuf loaders cache
114195

115-
LD_LIBRARY_PATH=$basedir/lib:$LD_LIBRARY_PATH \
196+
LD_LIBRARY_PATH=$basedir/lib:$basedir/lib64:$LD_LIBRARY_PATH \
116197
GDK_PIXBUF_MODULE_FILE=$basedir/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache \
117198
GDK_PIXBUF_MODULEDIR=$basedir/lib/gdk-pixbuf-2.0/2.10.0/loaders \
118199
$basedir/bin/gdk-pixbuf-query-loaders --update-cache
119200

120201
# Update immodules cache
121202

122-
LD_LIBRARY_PATH=$basedir/lib:$LD_LIBRARY_PATH \
203+
LD_LIBRARY_PATH=$basedir/lib:$basedir/lib64:$LD_LIBRARY_PATH \
123204
GTK_IM_MODULE_FILE=$basedir/lib/gtk-3.0/3.0.0/immodules.cache \
124205
GTK_PATH=$basedir/lib/gtk-3.0 \
125206
$basedir/bin/gtk-query-immodules-3.0 --update-cache
@@ -154,28 +235,56 @@ EOF
154235

155236
## Main program
156237

157-
if [ $# -eq 1 ]; then
238+
# Initialize variables
239+
skip_overwriting_libs=0
240+
interactive_mode=0
241+
242+
if [ $# -ge 1 ]; then
158243
if [ "$1" = "--help" ]; then
159244
printf "
160-
Usage: $0 [install_dir]
245+
Usage: $0 [options] [install_dir]
246+
247+
When no arguments are specified, runs the GtkAda installer
248+
interactively. Otherwise installs automatically.
161249
162-
When no argument is specified, runs the GtkAda installer
163-
interactively, otherwise installs automatically under install_dir.
250+
Options:
251+
--help Show this help message
252+
--no-overwrite Do not overwrite existing libraries in the target directory
164253
"
165254
else
166-
echo "installing GtkAda under $1"
167-
check_gtk_bin
168-
basedir="$1"
169-
mkdir -p $basedir || exit 1
170-
install_binaries
171-
end_message
255+
# Parse arguments
256+
while [ $# -gt 0 ]; do
257+
case "$1" in
258+
--no-overwrite)
259+
skip_overwriting_libs=1
260+
shift
261+
;;
262+
*)
263+
break
264+
;;
265+
esac
266+
done
267+
268+
# Remaining argument should be the install directory
269+
if [ $# -eq 1 ]; then
270+
echo "installing GtkAda under $1"
271+
check_gtk_bin
272+
basedir="$1"
273+
mkdir -p $basedir || exit 1
274+
install_binaries
275+
end_message
276+
else
277+
echo "Error: Invalid arguments"
278+
exit 1
279+
fi
172280
fi
173281
exit 0
174282
fi
175283

176284
# Perform interactive install
177285

178286
check_gtk_bin
287+
interactive_mode=1
179288
begin_message
180289
ask_basedir
181290
install_binaries

0 commit comments

Comments
 (0)