-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall-deb.sh
executable file
·228 lines (200 loc) · 7.35 KB
/
install-deb.sh
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash
# Check if script is run as root
if [ "$EUID" -ne 0 ]; then
echo "ERROR: Please run as root"
exit 1
fi
# Check requirements
for cmd in dpkg; do
if ! command -v $cmd &>/dev/null; then
echo "ERROR: $cmd is not present, please install it first"
exit 1
fi
done
APT_GET_INSTALLED=true
if ! command -v apt-get &>/dev/null; then
echo "ERROR: apt-get is not present"
exit 1
else
echo "INFO: apt-get is present"
apt-get update
fi
# check other dependencies: curl, jq
for cmd in curl jq; do
if ! command -v $cmd &>/dev/null; then
if [ "$APT_GET_INSTALLED" = "true" ]; then
echo "INFO: $cmd is not present, attempting to install it using apt-get"
apt-get install -y $cmd
if [ $? -ne 0 ]; then
echo "ERROR: failed to install $cmd using apt-get"
exit 1
else
echo "INFO: $cmd installed successfully using apt-get"
fi
else
echo "ERROR: $cmd is not present, please install it first"
exit 1
fi
fi
done
# check optional dependencies
ARIA2C_INSTALLED=true
if ! command -v aria2c &>/dev/null; then
if [ "$APT_GET_INSTALLED" = "true" ]; then
echo "INFO: aria2c is not present, attempting to install it using apt-get"
apt-get install -y aria2
if [ $? -ne 0 ]; then
echo "WARN: aria2c is not present, falling back to curl"
ARIA2C_INSTALLED=false
else
echo "INFO: aria2c installed successfully using apt-get"
fi
else
echo "WARN: aria2c is not present, falling back to curl"
ARIA2C_INSTALLED=false
fi
else
echo "INFO: aria2c installed"
fi
function parse_json() {
local json_content=$1
local key=$2
echo $(echo $json_content | jq -r ".$key")
}
function download_file_from_url() {
local url=$1
local target_path=$2
if [ -f $target_path ]; then
echo "INFO: $target_path already exists, removing it"
rm $target_path
fi
echo "INFO: downloading $url to $target_path"
if [ "$ARIA2C_INSTALLED" = "true" ]; then
echo "INFO: aria2c is installed, allowing parallel downloads"
# aria2c -o $target_path $url
aria2c -d $(dirname $target_path) -o $(basename $target_path) $url
else
echo "INFO: aria2c is not installed, falling back to curl"
curl -L -o $target_path $url
fi
if [ $? -ne 0 ]; then
echo "ERROR: Failed to download $url"
exit 1
fi
}
# check if raw.githubusercontent.com is accessible
RAW_GITHUB_AVAILABLE=true
if ! curl -s https://raw.githubusercontent.com/Lyricify/Lyricify-on-Wine/master/install-deb.sh | grep -q "raw.githubusercontent.com"; then
echo "WARN: raw.githubusercontent.com is not accessible. Using JSDelivr instead"
RAW_GITHUB_AVAILABLE=false
fi
function download_file_from_repo() {
local path_in_repo=$1
local target_path=$2
if [ -f $target_path ]; then
echo "INFO: $target_path already exists, removing it"
rm $target_path
fi
echo "INFO: downloading $path_in_repo to $target_path"
if [ "$RAW_GITHUB_AVAILABLE" = "true" ]; then
url=https://raw.githubusercontent.com/Lyricify/Lyricify-on-Wine/master/$path_in_repo
else
url=https://cdn.jsdelivr.net/gh/Lyricify/Lyricify-on-Wine@master/$path_in_repo
fi
download_file_from_url $url $target_path
if [ $? -ne 0 ]; then
echo "ERROR: Failed to download $path_in_repo"
exit 1
fi
}
function safe_dpkg_install() {
local package_filepath=$1
echo "INFO: installing $package_filepath using dpkg"
dpkg -i $package_filepath
if [ $? -ne 0 ]; then
echo "ERROR: failed to install $package_filepath using dpkg"
exit 1
else
echo "INFO: $package_filepath installed successfully using dpkg"
fi
}
function check_and_install_package() {
local package_name=$1
local package_name_in_repo=$2
if dpkg-query -W -f='${Status}' $package_name 2>/dev/null | grep -q "install ok installed"; then
echo "INFO: $package_name is already installed"
else
echo "INFO: attempting to install $package_name"
apt-get install -y $package_name
if [ $? -ne 0 ]; then
echo "ERROR: failed to install $package_name using apt-get. Falling back to dpkg"
download_file_from_repo "apt-missing-dependencies/${package_name_in_repo}" "/tmp/${package_name_in_repo}"
apt-get install -y /tmp/${package_name_in_repo}
if [ $? -ne 0 ]; then
echo "ERROR: failed to install $package_name using apt-get(local)"
exit 1
else
echo "INFO: $package_name installed successfully using apt-get(local)"
fi
else
echo "INFO: $package_name installed successfully, using apt-get"
fi
fi
}
check_and_install_package "deepin-app-store-runtime" "deepin-app-store-runtime_1.0.2+community_amd64.deb"
check_and_install_package "deepin-wine-helper" "deepin-wine-helper_5.3.14-1_amd64.deb"
echo "INFO: All dependencies installed successfully"
# fetch the latest version from Github Releases
latest_release=$(curl -H "Accept: application/vnd.github+json" -s "https://api.github.com/repos/Lyricify/Lyricify-on-Wine/releases/latest")
# extract the download URL from the latest release
release_id=$(parse_json "$latest_release" "id")
version_name=$(parse_json "$latest_release" "name")
upload_datetime=$(parse_json "$latest_release" "published_at")
download_url=$(parse_json "$latest_release" "assets[0].browser_download_url")
if [ "$release_id" = "null" ]; then
echo "ERROR: Failed to fetch latest release information from Github: probably rate-limited"
echo "INFO: Please try again later (maybe 20-40 seconds)"
exit 1
fi
# echo "INFO: Extracted download URL: $download_url"
echo "INFO: Version information (latest):"
echo " Release ID: $release_id"
echo " Version Name: $version_name"
echo " Upload Date: $upload_datetime"
echo " Download URL: $download_url"
echo ""
# prompt the user to confirm the download
read -p "Install $version_name? [Y/n] " answer
if [[ "$answer" =~ ^[Nn]$ ]]; then
echo "INFO: abandoning installation of $version_name"
else
# download the package
echo "INFO: Downloading $version_name from $download_url"
# if ! curl -L -o /tmp/lyricify.deb $download_url; then
# echo "ERROR: Failed to download $version_name"
# exit 1
# fi
download_file_from_url $download_url /tmp/lyricify.deb
# install the package
echo "INFO: Installing $version_name"
safe_dpkg_install /tmp/lyricify.deb
# clean up
rm /tmp/lyricify.deb
echo "INFO: $version_name installed successfully"
read -p "Install shortcut for Lyricify on Wine in /usr/bin? [Y/n] " answer
if [[ "$answer" =~ ^[Nn]$ ]]; then
echo "INFO: Skipping shortcut installation"
echo "INFO: To launch Lyricify, run /opt/apps/com.wxriw.lyricify4/files/run.sh or start from applications menu"
else
# create the shortcut
# target: /opt/apps/com.wxriw.lyricify4/files/run.sh
cat >/usr/bin/lyricify-launcher <<EOF
#!/bin/bash
/opt/apps/com.wxriw.lyricify4/files/run.sh
EOF
chmod +x /usr/bin/lyricify-launcher
echo "INFO: Shortcut installed successfully"
echo "INFO: To launch Lyricify, run lyricify-launcher"
fi
fi
echo "INFO: Done"