2021-08-21 16:39:24 +02:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
die() {
|
|
|
|
echo "$@" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2021-08-28 16:04:02 +02:00
|
|
|
pakitheme_gtk3() {
|
2021-08-21 16:39:24 +02:00
|
|
|
local color="$(destify ${1})"
|
|
|
|
local opacity="$(destify ${2})"
|
|
|
|
local alt="$(destify ${3})"
|
|
|
|
local theme="$(destify ${4})"
|
|
|
|
|
|
|
|
local FLATPAK_THEME="${name}${color}${opacity}${alt}${theme}"
|
|
|
|
|
2021-08-28 16:04:02 +02:00
|
|
|
local GTK_3_THEME_VER=3.22
|
2021-08-21 16:39:24 +02:00
|
|
|
local cache_home="${XDG_CACHE_HOME:-$HOME/.cache}"
|
|
|
|
local data_home="${XDG_DATA_HOME:-$HOME/.local/share}"
|
|
|
|
local pakitheme_cache="$cache_home/pakitheme"
|
|
|
|
local repo_dir="$pakitheme_cache/repo"
|
2021-08-28 16:04:02 +02:00
|
|
|
local gtk3_app_id="org.gtk.Gtk3theme.$FLATPAK_THEME"
|
2021-08-21 16:39:24 +02:00
|
|
|
local root_dir="$pakitheme_cache/$FLATPAK_THEME"
|
|
|
|
local repo_dir="$root_dir/repo"
|
|
|
|
local build_dir="$root_dir/build"
|
|
|
|
|
|
|
|
for location in "$data_home/themes" "$HOME/.themes" /usr/share/themes; do
|
|
|
|
if [[ -d "$location/$FLATPAK_THEME" ]]; then
|
2021-08-27 07:24:32 +02:00
|
|
|
prompt -s "Found theme located at: $location/$FLATPAK_THEME \n"
|
2021-08-21 16:39:24 +02:00
|
|
|
theme_path="$location/$FLATPAK_THEME"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2021-08-27 07:24:32 +02:00
|
|
|
if [[ -n "$theme_path" ]]; then
|
|
|
|
prompt -i "Converting theme: $FLATPAK_THEME... \n"
|
|
|
|
else
|
|
|
|
prompt -e "Could not locate theme... install theme first! \n"
|
|
|
|
exit 0
|
|
|
|
fi
|
2021-08-21 16:39:24 +02:00
|
|
|
|
|
|
|
rm -rf "$root_dir" "$repo_dir"
|
|
|
|
mkdir -p "$repo_dir"
|
|
|
|
ostree --repo="$repo_dir" init --mode=archive
|
|
|
|
ostree --repo="$repo_dir" config set core.min-free-space-percent 0
|
|
|
|
|
|
|
|
rm -rf "$build_dir"
|
|
|
|
mkdir -p "$build_dir/files"
|
|
|
|
|
|
|
|
theme_gtk_version=$(ls -1d "$theme_path"/* 2>/dev/null | grep -Po 'gtk-3\.\K\d+$' | sort -nr | head -1)
|
|
|
|
[[ -n "$theme_gtk_version" ]] || \
|
|
|
|
die "Theme directory did not contain any recognized GTK themes."
|
|
|
|
|
|
|
|
cp -a "$theme_path/gtk-3.$theme_gtk_version/"* "$build_dir/files"
|
|
|
|
|
|
|
|
mkdir -p "$build_dir/files/share/appdata"
|
2021-08-28 16:04:02 +02:00
|
|
|
cat >"$build_dir/files/share/appdata/$gtk3_app_id.appdata.xml" <<EOF
|
2021-08-21 16:39:24 +02:00
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<component type="runtime">
|
2021-08-28 16:04:02 +02:00
|
|
|
<id>$gtk3_app_id</id>
|
2021-08-21 16:39:24 +02:00
|
|
|
<metadata_license>CC0-1.0</metadata_license>
|
2021-08-28 16:04:02 +02:00
|
|
|
<name>$FLATPAK_THEME Gtk theme</name>
|
|
|
|
<summary>$FLATPAK_THEME Gtk theme (generated via pakitheme)</summary>
|
2021-08-21 16:39:24 +02:00
|
|
|
</component>
|
|
|
|
EOF
|
|
|
|
|
2021-08-28 16:04:02 +02:00
|
|
|
appstream-compose --prefix="$build_dir/files" --basename="$gtk3_app_id" --origin=flatpak "$gtk3_app_id"
|
2021-08-21 16:39:24 +02:00
|
|
|
|
|
|
|
ostree --repo="$repo_dir" commit -b base --tree=dir="$build_dir"
|
|
|
|
|
|
|
|
bundles=()
|
|
|
|
|
|
|
|
while read -r arch; do
|
2021-08-28 16:04:02 +02:00
|
|
|
bundle="$root_dir/$gtk3_app_id-$arch.flatpak"
|
2021-08-21 16:39:24 +02:00
|
|
|
|
|
|
|
rm -rf "$build_dir"
|
|
|
|
ostree --repo="$repo_dir" checkout -U base "$build_dir"
|
|
|
|
|
|
|
|
read -rd '' metadata <<EOF ||:
|
|
|
|
[Runtime]
|
2021-08-28 16:04:02 +02:00
|
|
|
name=$gtk3_app_id
|
|
|
|
runtime=$gtk3_app_id/$arch/$GTK_3_THEME_VER
|
|
|
|
sdk=$gtk3_app_id/$arch/$GTK_3_THEME_VER
|
2021-08-21 16:39:24 +02:00
|
|
|
EOF
|
|
|
|
# Make sure there is no trailing newline, so xa.metadata doesn't get confused later
|
|
|
|
echo -n "$metadata" > "$build_dir/metadata"
|
|
|
|
|
2021-08-28 16:04:02 +02:00
|
|
|
ostree --repo="$repo_dir" commit -b "runtime/$gtk3_app_id/$arch/$GTK_3_THEME_VER" \
|
2021-08-21 16:39:24 +02:00
|
|
|
--add-metadata-string "xa.metadata=$(cat $build_dir/metadata)" --link-checkout-speedup "$build_dir"
|
2021-08-28 16:04:02 +02:00
|
|
|
flatpak build-bundle --runtime "$repo_dir" "$bundle" "$gtk3_app_id" "$GTK_3_THEME_VER"
|
2021-08-21 16:39:24 +02:00
|
|
|
|
|
|
|
trap 'rm "$bundle"' EXIT
|
|
|
|
|
|
|
|
bundles+=("$bundle")
|
|
|
|
# Note: a pipe can't be used because it will mess with subshells and cause the append
|
|
|
|
# to bundles to fail.
|
|
|
|
done < <(flatpak list --runtime --columns=arch:f | sort -u)
|
|
|
|
|
|
|
|
for bundle in "${bundles[@]}"; do
|
2021-08-23 10:00:41 +02:00
|
|
|
if [[ -w "/root" ]]; then
|
|
|
|
sudo flatpak install -y --system "${bundle}"
|
|
|
|
else
|
|
|
|
udo flatpak install -y --user "${bundle}"
|
|
|
|
fi
|
2021-08-21 16:39:24 +02:00
|
|
|
done
|
|
|
|
}
|
2021-08-27 16:02:58 +02:00
|
|
|
|
|
|
|
flatpak_remove() {
|
|
|
|
local color="$(destify ${1})"
|
|
|
|
local opacity="$(destify ${2})"
|
|
|
|
local alt="$(destify ${3})"
|
|
|
|
local theme="$(destify ${4})"
|
|
|
|
|
|
|
|
if [[ -w "/root" ]]; then
|
|
|
|
sudo flatpak remove -y --system org.gtk.Gtk3theme.${name}${color}${opacity}${alt}${theme}
|
|
|
|
else
|
|
|
|
udo flatpak remove -y --user org.gtk.Gtk3theme.${name}${color}${opacity}${alt}${theme}
|
|
|
|
fi
|
|
|
|
}
|