File indexing completed on 2024-05-12 16:42:15

0001 #!/bin/bash
0002 # SPDX-FileCopyrightText: 2021 Dawid Wrobel <me@dawidwrobel.com>
0003 # SPDX-FileCopyrightText: 2020 Thomas Baumgart <tbaumgart@kde.org>
0004 # SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006 # Usage: ./copy_from_breeze.sh breeze-icons\
0007 # where breeze-icon\ is a path to a root folder of a cloned breeze-icon git repository
0008 # (must contain "icons" and "icons-dark" subfolders).
0009 
0010 function show_help()
0011 {
0012     echo "Syntax: $0 <breeze-icon-dir>"
0013     echo
0014     echo "  <breeze-icon-dir> must contain an icons and an icons-dark subdirectory"
0015 }
0016 
0017 # the following function implementation was taken from a post on
0018 # https://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
0019 function readlinkf()
0020 {
0021     perl -MCwd -e 'print Cwd::abs_path shift' "$1";
0022 }
0023 
0024 # make sure, src_dir does not end in '/' and is present
0025 src_dir=${1%/}
0026 if [ -z "$src_dir" ]; then
0027     echo "Missing breeze-icon-dir argument"
0028     show_help
0029     exit 1
0030 fi
0031 
0032 # check for src_dir being a directory
0033 if [ ! -d $src_dir ]; then
0034     echo "$src_dir is not a directory"
0035     show_help
0036     exit 1
0037 fi
0038 
0039 # check for src_dir/icons being a directory
0040 if [ ! -d $src_dir/icons ]; then
0041     echo "$src_dir does not have an 'icons' subdirectory"
0042     show_help
0043     exit 1
0044 fi
0045 
0046 # check for src_dir/icons-dark being a directory
0047 if [ ! -d $src_dir/icons-dark ]; then
0048     echo "$src_dir does not have an 'icons-dark' subdirectory"
0049     show_help
0050     exit 1
0051 fi
0052 
0053 scriptdir=$(dirname $(readlinkf $0))
0054 [ -n "$scriptdir" ] || exit 1
0055 cd $scriptdir
0056 
0057 if [ ! -r icons.cpp ]; then
0058     echo "icons.cpp source file not found in $scriptdir"
0059     exit 1
0060 fi
0061 
0062 used_in_code=$(perl -nle "print for /\{IconSet\:\:(?>Breeze|Common), QStringLiteral\(\"(.*?)\"\)\}/gm" icons.cpp | sort -u)
0063 additional=" index application-x-kmymoney edit-undo edit-redo document-print"
0064 all_icons=$used_in_code$additional
0065 
0066 # check if we have the dos2unix tool available
0067 DOS2UNIX=$(which dos2unix 2>/dev/null)
0068 
0069 rm -rf breeze breeze-dark
0070 
0071 for i in $all_icons; do
0072     for src in $(find $src_dir -name "$i.*"); do
0073         dest=${src/#$src_dir\/icons/breeze}
0074         # breeze < 5.81 doesn't have actions/48 sections defined in its index.theme, so 48px icons wouldn't load
0075         dest=${dest/actions\/48/actions\/32}
0076         dest_dir=${dest%/*}
0077         [ -d "$dest_dir" ] || mkdir -p "$dest_dir"
0078         echo "copying $src to $dest"
0079         cp "$src" "$dest"
0080         chmod oga-x "$dest"
0081         [ -z "$DOS2UNIX" ] || $DOS2UNIX $dest
0082     done
0083 done