-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·162 lines (133 loc) · 4.17 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·162 lines (133 loc) · 4.17 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/sh
set -eu
REPO_URL="${AMDECRYPT_GUI_REPO:-https://github.com/gabors0/AMDecrypt-gui.git}"
REPO_REF="${AMDECRYPT_GUI_REF:-}"
WAILS_BUILD_TAGS="${WAILS_BUILD_TAGS:-webkit2_41}"
TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/amdecrypt-gui-install.XXXXXX")"
APP_NAME="amdecrypt-gui"
SOURCE_DIR=""
if [ -n "${SUDO_USER:-}" ] && [ "$SUDO_USER" != "root" ]; then
INVOKING_USER="$SUDO_USER"
else
INVOKING_USER="$(id -un)"
fi
INVOKING_HOME="$(getent passwd "$INVOKING_USER" | cut -d: -f6)"
cleanup() {
if [ -n "$TMP_DIR" ] && [ -d "$TMP_DIR" ]; then
rm -rf "$TMP_DIR"
fi
}
trap cleanup EXIT
require_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "Missing required command: $1" >&2
exit 1
fi
}
resolve_wails() {
if command -v wails >/dev/null 2>&1; then
command -v wails
return 0
fi
if [ -n "${GOBIN:-}" ] && [ -x "${GOBIN}/wails" ]; then
printf '%s\n' "${GOBIN}/wails"
return 0
fi
if [ -n "${INVOKING_HOME:-}" ] && [ -x "${INVOKING_HOME}/go/bin/wails" ]; then
printf '%s\n' "${INVOKING_HOME}/go/bin/wails"
return 0
fi
return 1
}
run_as_root() {
if [ "$(id -u)" -eq 0 ]; then
"$@"
else
sudo "$@"
fi
}
install_for_user() {
mode="$1"
source_path="$2"
target_path="$3"
target_dir="$(dirname "$target_path")"
if [ "$(id -u)" -eq 0 ]; then
run_as_root install -d -o "$INVOKING_USER" -g "$INVOKING_USER" "$target_dir"
run_as_root install -m "$mode" -o "$INVOKING_USER" -g "$INVOKING_USER" "$source_path" "$target_path"
else
mkdir -p "$target_dir"
install -m "$mode" "$source_path" "$target_path"
fi
}
install_built_app() {
repo_dir="$1"
binary="$repo_dir/build/bin/$APP_NAME"
icon="$repo_dir/build/appicon.png"
install_bin="/usr/local/bin/$APP_NAME"
if [ -z "$INVOKING_HOME" ]; then
echo "Failed to resolve home directory for user: $INVOKING_USER" >&2
exit 1
fi
install_icon="$INVOKING_HOME/.local/share/icons/hicolor/256x256/apps/$APP_NAME.png"
install_desktop="$INVOKING_HOME/.local/share/applications/$APP_NAME.desktop"
desktop_tmp="$TMP_DIR/$APP_NAME.desktop"
if [ ! -f "$binary" ]; then
echo "Binary not found: $binary" >&2
echo "Build failed or did not produce the expected output." >&2
exit 1
fi
echo "Installing $APP_NAME..."
echo "Target user: $INVOKING_USER"
echo "Binary path: $install_bin"
echo "Desktop file: $install_desktop"
run_as_root install -Dm755 "$binary" "$install_bin"
install_for_user 644 "$icon" "$install_icon"
cat > "$desktop_tmp" <<EOF
[Desktop Entry]
Name=AMDecrypt-GUI
Comment=GUI for AppleMusicDecrypt
Exec=$install_bin
Icon=$install_icon
Type=Application
Terminal=false
Categories=Utility;AudioVideo;
StartupWMClass=amdecrypt-gui
StartupNotify=true
EOF
install_for_user 644 "$desktop_tmp" "$install_desktop"
gtk-update-icon-cache "$INVOKING_HOME/.local/share/icons/hicolor/" 2>/dev/null || true
update-desktop-database "$INVOKING_HOME/.local/share/applications/" 2>/dev/null || true
xdg-desktop-menu forceupdate 2>/dev/null || true
}
require_cmd git
require_cmd go
require_cmd npm
if ! WAILS_BIN="$(resolve_wails)"; then
echo "Missing required command: wails" >&2
echo "Install it with: go install github.com/wailsapp/wails/v2/cmd/wails@latest" >&2
echo "If you run this script with sudo, make sure wails is installed for $INVOKING_USER." >&2
exit 1
fi
if [ -f "./wails.json" ]; then
SOURCE_DIR="$(pwd)"
echo "Using local checkout at $SOURCE_DIR..."
else
echo "Cloning $REPO_URL..."
git clone --depth 1 "$REPO_URL" "$TMP_DIR/repo"
SOURCE_DIR="$TMP_DIR/repo"
fi
cd "$SOURCE_DIR"
if [ -n "$REPO_REF" ] && [ "$SOURCE_DIR" = "$TMP_DIR/repo" ]; then
echo "Checking out $REPO_REF..."
git fetch --depth 1 origin "$REPO_REF"
git checkout --detach FETCH_HEAD
fi
echo "Building AMDecrypt-gui..."
if [ -n "$WAILS_BUILD_TAGS" ]; then
"$WAILS_BIN" build -tags "$WAILS_BUILD_TAGS"
else
"$WAILS_BIN" build
fi
echo "Installing built application..."
install_built_app "$SOURCE_DIR"
echo "AMDecrypt-gui is now installed (or updated)."