3 # Fetch and extract Geany dependencies for Windows/MSYS2
4 # This script will download (or use Pacman's cache) to extract
5 # dependencies as defined below needed to run Geany.
6 # To be run within a MSYS2 shell. The extracted files will be
7 # placed into the current directory.
9 ABI
=x86_64
# do not change, i686 is not supported any longer
16 UNX_UTILS_URL
="https://download.geany.org/contrib/UnxUpdates.zip"
17 # we use the Prof-Gnome GTK theme from the Geany macOS repository
18 GTK_THEME_URL
="https://github.com/geany/geany-osx/archive/refs/heads/master.zip"
20 # Wine commands for 32bit and 64bit binaries (we still need 32bit for UnxUtils sort.exe)
21 # Used only when "-x" is set
22 EXE_WRAPPER_32
="mingw-w64-i686-wine"
23 EXE_WRAPPER_64
="mingw-w64-x86_64-wine"
26 gtk3_dependency_pkgs
=""
27 gtk4_dependency_pkgs
=""
64 handle_command_line_options
() {
86 echo "gtk-bundle-from-msys2.sh [-c] [-h] [-n] [-z] [-3 | -4] [CACHEDIR]"
87 echo " -c Use pacman cache. Otherwise pacman will download"
89 echo " -h Show this help screen"
90 echo " -n Do not run post install scripts of the packages"
91 echo " -z Create a zip afterwards"
92 echo " -3 Prefer gtk3"
93 echo " -4 Prefer gtk4"
94 echo " -x Set when the script is executed in a cross-compilation context (e.g. to use wine)"
95 echo "CACHEDIR Directory where to look for cached packages (default: /var/cache/pacman/pkg)"
105 set -e # stop on errors
106 # enable extended globbing as we need it in _getpkg
110 if [ -z "$cachedir" ]; then
111 cachedir
="/var/cache/pacman/pkg"
114 if [ "$use_cache" = "yes" ] && ! [ -d "$cachedir" ]; then
115 echo "Cache dir \"$cachedir\" not a directory"
119 if [ "$cross" != "yes" ]; then
120 # if running natively, we do not need wine or any other wrappers
126 eval "gtk_dependency_pkgs=\${${gtk}_dependency_pkgs}"
130 ${gtk_dependency_pkgs}
136 if [ "$use_cache" = "yes" ]; then
137 package_info
=$
(pacman
-Qi mingw-w64-
$ABI-$1)
138 package_version
=$
(echo "$package_info" |
grep "^Version " | cut
-d':' -f 2 |
tr -d '[[:space:]]')
139 # use @(gz|xz|zst) to filter out signature files (e.g. mingw-w64-x86_64-...-any.pkg.tar.zst.sig)
140 ls $cachedir/mingw-w64-
${ABI}-${1}-${package_version}-*.
tar.@
(gz|xz|zst
) |
sort -V |
tail -n 1
142 # -dd to ignore dependencies as we listed them already above in $packages and
143 # make pacman ignore its possibly existing cache (otherwise we would get an URL to the cache)
144 pacman
-Sddp --cachedir /nonexistent mingw-w64-
${ABI}-${1}
148 _remember_package_source
() {
149 if [ "$use_cache" = "yes" ]; then
150 package_url
=$
(pacman
-Sddp mingw-w64-
${ABI}-${2})
154 package_urls
="${package_urls}\n${package_url}"
160 _remember_package_source
$pkg $i
161 if [ "$use_cache" = "yes" ]; then
162 if [ -e "$pkg" ]; then
163 echo "Extracting $pkg from cache"
166 echo "ERROR: File $pkg not found"
170 echo "Download $pkg using curl"
171 filename
=$
(basename "$pkg")
172 curl
--silent --location --output "$filename" "$pkg"
176 if [ "$make_zip" = "yes" -a "$i" = "$gtk" ]; then
177 VERSION
=$
(grep ^pkgver .PKGINFO |
sed -e 's,^pkgver = ,,' -e 's,-.*$,,')
179 rm -f .INSTALL .MTREE .PKGINFO .BUILDINFO
183 move_extracted_files
() {
184 echo "Move extracted data to destination directory"
185 if [ -d mingw64
]; then
186 for d
in bin etc home include lib locale share var
; do
187 if [ -d "mingw64/$d" ]; then
189 # prevent sporadic 'permission denied' errors on my system, not sure why they happen
198 delayed_post_install
() {
199 if [ "$run_pi" ]; then
200 echo "Execute delayed post install tasks"
201 # Commands have been collected manually from the various .INSTALL scripts
202 ${EXE_WRAPPER_64} bin
/fc-cache.exe
-f
203 ${EXE_WRAPPER_64} bin
/gdk-pixbuf-query-loaders.exe
--update-cache
204 ${EXE_WRAPPER_64} bin
/gtk-update-icon-cache-3.0.exe
-q -t -f share
/icons
/hicolor
205 ${EXE_WRAPPER_64} bin
/gtk-update-icon-cache-3.0.exe
-q -t -f share
/icons
/Adwaita
206 ${EXE_WRAPPER_64} bin
/glib-compile-schemas
share
/glib-2.0
/schemas
/
210 cleanup_unnecessary_files
() {
211 echo "Cleanup unnecessary files"
212 # cleanup temporary files
213 rm -rf var
/cache
/fontconfig
214 test -d var
/cache
&& rmdir var
/cache
215 test -d var
&& rmdir var
216 # cleanup development and other unnecessary files
223 find lib
-name '*.a' -delete
224 find lib
-name '*.typelib' -delete
225 find lib
-name '*.def' -delete
226 find lib
-name '*.h' -delete
227 find lib
-name '*.sh' -delete
228 # cleanup other unnecessary files
230 rm -rf share
/applications
231 rm -rf share
/bash-completion
235 rm -rf share
/gettext-
*
237 rm -rf share
/glib-2.0
/codegen
238 rm -rf share
/glib-2.0
/gdb
239 rm -rf share
/glib-2.0
/gettext
240 rm -rf share
/graphite2
243 rm -rf share
/icons
/Adwaita
/cursors
246 rm -rf share
/thumbnailers
249 rm -rf usr
/share
/libalpm
250 # cleanup binaries and libs (delete anything except *.dll and GSpawn helper binaries)
251 find bin
! -name '*.dll' ! -name 'grep.exe' ! -name 'gspawn-win32-helper*.exe' -type f
-delete
252 # cleanup empty directories
253 find .
-type d
-empty -delete
256 download_and_extract_sort
() {
257 echo "Download and unpack 'sort'"
258 # add sort to the bin directory
259 unxutils_archive
="unxutilsupdates.zip"
260 wget
--no-verbose -O ${unxutils_archive} ${UNX_UTILS_URL}
261 unzip ${unxutils_archive} sort.exe
-d bin
/
262 rm ${unxutils_archive}
265 download_and_extract_gtk_theme
() {
266 echo "Download and unpack GTK theme 'Prof-Gnome'"
267 geany_osx_archive
="geany_osx.zip"
268 wget
--no-verbose -O ${geany_osx_archive} ${GTK_THEME_URL}
269 unzip ${geany_osx_archive} "geany-osx-master/Prof-Gnome/**" "geany-osx-master/prof_gnome_windows_changes.patch"
270 mkdir
-p share
/themes
/
271 mv geany-osx-master
/Prof-Gnome
share
/themes
/
272 patch --dir share
/themes
/Prof-Gnome
-p2 < geany-osx-master
/prof_gnome_windows_changes.
patch
273 rm ${geany_osx_archive}
274 rm geany-osx-master
/prof_gnome_windows_changes.
patch
275 rmdir geany-osx-master
276 # create GTK settings to enable the theme
277 if [ -f "etc/gtk-3.0/settings.ini" ]; then
278 echo "etc/gtk-3.0/settings.ini already exists. Aborting."
281 echo -e "[Settings]\r\ngtk-theme-name=Prof-Gnome" > etc
/gtk-3.0
/settings.ini
284 create_bundle_dependency_info_file
() {
285 # sort.exe from UnxUtils is a 32bit binary, so use $EXE_WRAPPER_32
286 sort_version
="$(${EXE_WRAPPER_32} bin/sort.exe --version | sed -n 1p)"
287 # use "sed -n 1p" instead of "head -n1" as grep will otherwise prints a weird error,
288 # probably because the output pipe is closed prematurely
289 grep_version
="$(${EXE_WRAPPER_64} bin/grep.exe --version | sed -n 1p)"
290 filename
="ReadMe.Dependencies.Geany.txt"
291 cat << EOF > "${filename}"
292 This installation contains dependencies for Geany which are distributed
293 as binaries (usually .dll files) as well as additional files
294 necessary for these dependencies.
295 Following is a list of all included binary packages with their
296 full download URL as used to create this installation.
298 sort.exe is extracted from the ZIP archive at
300 Sort version: ${sort_version}
302 grep.exe is taken from a 64bit MSYS2 installation and
303 is bundled together with its dependencies.
304 Grep version: ${grep_version}
306 GTK theme "Prof-Gnome" was downloaded from:
309 Other dependencies are provided by the MSYS2 project
310 (https://msys2.github.io) and were downloaded from:
312 echo -e "${package_urls}" >> "${filename}"
315 create_zip_archive
() {
316 if [ "$make_zip" = "yes" ]; then
317 if [ -z "$VERSION" ]; then
318 VERSION
="unknown-version"
320 echo "Packing the bundle"
321 zip -r gtk-
$VERSION.
zip bin etc include lib locale share var
327 handle_command_line_options $@
332 cleanup_unnecessary_files
333 download_and_extract_sort
334 download_and_extract_gtk_theme
335 create_bundle_dependency_info_file