Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·88 lines (74 loc) · 2.36 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·88 lines (74 loc) · 2.36 KB
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
#!/usr/bin/env bash
set -euo pipefail
script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
theme_dir="${HOME}/.themes/flake-material-gtk"
config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/gtk-4.0"
force=0
flatpak_support=0
usage() {
cat <<'EOF'
Usage: ./install.sh [--force] [--flatpak]
Install flake-material-gtk for the current user.
--force Back up regular GTK4 config files before replacing them.
--flatpak Grant Flatpak apps read-only access to theme/config files.
-h, --help Show this help.
EOF
}
while (($#)); do
case "$1" in
--force) force=1 ;;
--flatpak) flatpak_support=1 ;;
-h|--help) usage; exit 0 ;;
*) printf 'Unknown option: %s\n' "$1" >&2; usage >&2; exit 2 ;;
esac
shift
done
if ((flatpak_support)) && ! command -v flatpak >/dev/null 2>&1; then
printf 'The --flatpak option requires the flatpak command.\n' >&2
exit 1
fi
for path in gtk-3.0 gtk-4.0 themes index.theme; do
if [[ ! -e "$script_dir/$path" ]]; then
printf 'Required theme path is missing: %s\n' "$script_dir/$path" >&2
exit 1
fi
done
mkdir -p "$HOME/.themes" "$theme_dir" "$config_dir"
cp -a "$script_dir/gtk-3.0" "$script_dir/gtk-4.0" \
"$script_dir/themes" "$script_dir/index.theme" \
"$theme_dir/"
link_config_file() {
local name="$1"
local source="$theme_dir/gtk-4.0/$name"
local target="$config_dir/$name"
if [[ ! -e "$source" ]]; then
printf 'Cannot link missing source file: %s\n' "$source" >&2
return 1
fi
if [[ -e "$target" && ! -L "$target" ]]; then
if ((force == 0)); then
printf 'Refusing to replace existing file: %s (use --force to back it up)\n' "$target" >&2
return 1
fi
backup="$(mktemp "${target}.bak.XXXXXX")"
cp -a -- "$target" "$backup"
printf 'Backed up %s to %s\n' "$target" "$backup"
fi
ln -sfn -- "$source" "$target"
}
link_config_file gtk.css
link_config_file gtk-dark.css
link_config_file colors.css
if ((flatpak_support)); then
flatpak override --user --unset-env=GTK_THEME
flatpak override --user \
--filesystem=xdg-config/gtk-4.0:ro \
--filesystem=xdg-config/gtk-3.0:ro \
--filesystem=xdg-data/themes:ro \
--filesystem="$HOME/.themes:ro"
fi
printf 'flake-material-gtk installed to %s\n' "$theme_dir"
printf 'GTK4 stylesheets linked in %s\n' "$config_dir"
if ((flatpak_support)); then
printf 'Flatpak theme access enabled for the current user.\n'
fi