Repository navigation
Expand file tree
/
Copy pathdist.sh
More file actions
executable file
·142 lines (119 loc) · 3.83 KB
/
Copy pathdist.sh
File metadata and controls
executable file
·142 lines (119 loc) · 3.83 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
set -e
# This script is intended to help with correct packaging of Trayscale.
# It is not intended for general usage. If you'd like to install
# Trayscale manually, you can read through the installation section of
# this script to see where various files are put.
_usage() {
echo "Usage: $0 <build | install | install-data | install-macos | uninstall-macos> [options]"
echo
echo "Modes:"
echo " build: build the binary with embedded version information"
echo " Usage: build [version]"
echo " install: install the binary and other files into a directory tree"
echo " Usage: install <destination directory>"
echo " install-data: install everything except the binary into a directory tree"
echo " Usage: install-data <destination directory>"
echo " install-macos: install Trayscale for macOS (Apple Silicon)"
echo " Usage: install-macos"
echo " uninstall-macos: uninstall Trayscale from macOS"
echo " Usage: uninstall-macos"
exit 2
}
_build() {
version="$1"
if [ -z "$version" ]; then
version="$(git describe --tags --always)"
fi
echo "Building $version"
go build -v -trimpath -ldflags="-w -s -X 'deedles.dev/trayscale/internal/metadata.version=$version'" -o trayscale ./cmd/trayscale
}
_install() {
dstdir="$1"
if [ -z "$dstdir" ]; then
_usage
fi
install -D -t "$dstdir/bin" trayscale
_install_data "$dstdir"
}
_install_data() {
dstdir="$1"
if [ -z "$dstdir" ]; then
_usage
fi
echo "Installing to $dstdir"
install -Dm644 -t "$dstdir/share/icons/hicolor/256x256/apps" dev.deedles.Trayscale.png
install -Dm644 -t "$dstdir/share/applications" dev.deedles.Trayscale.desktop
install -Dm644 -t "$dstdir/share/metainfo" dev.deedles.Trayscale.metainfo.xml
install -Dm644 -t "$dstdir/share/glib-2.0/schemas" dev.deedles.Trayscale.gschema.xml
}
_install_macos() {
if [ -z "$HOMEBREW_PREFIX" ]; then
echo "Error: HOMEBREW_PREFIX not set. Is Homebrew installed?"
exit 1
fi
echo "Installing for macOS"
# Create wrapper script to set up environment
cat > trayscale.wrapper << EOF
#!/bin/bash
export XDG_DATA_DIRS="$HOMEBREW_PREFIX/share:\${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
exec "$HOMEBREW_PREFIX/libexec/trayscale"
EOF
chmod +x trayscale.wrapper
# Install binary to libexec (actual executable)
install -d "$HOMEBREW_PREFIX/libexec"
install trayscale "$HOMEBREW_PREFIX/libexec/"
# Install wrapper to bin (what users will run)
install trayscale.wrapper "$HOMEBREW_PREFIX/bin/trayscale"
rm trayscale.wrapper
schema_dir="$HOMEBREW_PREFIX/share/glib-2.0/schemas"
install -d "$schema_dir"
install -m644 dev.deedles.Trayscale.gschema.xml "$schema_dir/"
glib-compile-schemas "$schema_dir"
share_dir="$HOMEBREW_PREFIX/share"
install -d "$share_dir/applications"
install -m644 dev.deedles.Trayscale.desktop "$share_dir/applications/"
install -d "$share_dir/icons/hicolor/256x256/apps"
install -m644 dev.deedles.Trayscale.png "$share_dir/icons/hicolor/256x256/apps/"
echo "Installation complete. You can now run 'trayscale' from anywhere"
}
_uninstall_macos() {
if [ -z "$HOMEBREW_PREFIX" ]; then
echo "Error: HOMEBREW_PREFIX not set. Is Homebrew installed?"
exit 1
fi
echo "Uninstalling from macOS"
rm -f "$HOMEBREW_PREFIX/bin/trayscale"
rm -f "$HOMEBREW_PREFIX/libexec/trayscale"
schema_dir="$HOMEBREW_PREFIX/share/glib-2.0/schemas"
rm -f "$schema_dir/dev.deedles.Trayscale.gschema.xml"
glib-compile-schemas "$schema_dir"
share_dir="$HOMEBREW_PREFIX/share"
rm -f "$share_dir/applications/dev.deedles.Trayscale.desktop"
rm -f "$share_dir/icons/hicolor/256x256/apps/dev.deedles.Trayscale.png"
echo "Uninstallation complete"
}
case "$1" in
build)
_build "$2"
;;
install)
_install "$2"
;;
install-data)
_install_data "$2"
;;
install-macos)
_install_macos
;;
uninstall-macos)
_uninstall_macos
;;
--help)
_usage
;;
*)
echo "Error: Unknown mode $1"
_usage
;;
esac