-
Notifications
You must be signed in to change notification settings - Fork 0
/
discord
executable file
·126 lines (111 loc) · 4.14 KB
/
discord
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
#!/bin/bash
## TODO
# resolving dependencies
# installing to dirs not owned by the user
(
THIS_NAME="$(basename "$0")"
opt_dir="${HOME}/.local/opt"
discord_dir="${opt_dir}/discord"
msg() { printf '\033[32m[%s]\033[0m: %s\n' "${THIS_NAME}" "${1}"; }
error() { >&2 printf '\033[31m[%s]\033[0m: %s\n' "${THIS_NAME}" "${1}"; }
error_quit() { error "${1}"; exit 1; }
question() { zenity --question --width 550 --text "${1}"; return ${?}; }
zenity_error() { zenity --error --width 550 --text "${1}"; }
zenity_msg() { zenity --info --width 550 --text "${1}"; }
launch() { ( cd "${HOME}/.local/opt/discord/" && ./Discord ); }
if [ "${1}" = "--help" ] && [ -z "${2}" ]; then
printf "%s - a launcher for Discord by unicatte. This launcher updates Discord independently from the package manager whenever there's a new version available. It's meant to be a drop-in replacement for any other method of running Discord on Linux.\n" "${THIS_NAME}"
exit 0;
fi
if ! command -v zenity >/dev/null; then
error "zenity not found."
error_quit "This script requires zenity being installed and accessible from the shell."
fi
if [ "${1}" = "uninstall" ] && [ -z "${2}" ]; then
if ! question "Do you want to uninstall Discord?"; then
exit 1
fi
rm -rvf "${HOME}/.local/opt/discord"
rm -vf "${HOME}/.local/share/applications/discord.desktop"
zenity_msg "Discord has been uninstalled successfully!"
exit 0;
elif [ -n "${1}" ]; then
error_quit "Too many arguments."
fi
for i in curl jq ; do
if ! command -v "${i}" >/dev/null; then
zenity_error "${i} - command not found.\nThis script requires $i being installed and accessible from the shell."
exit 1;
fi
done
installed=false
if [ -d "${opt_dir}" ] && [ -d "${discord_dir}" ] && [ -f "${discord_dir}/Discord" ]; then
launch &
running_pid="${!}"
installed=true
fi
URL="$(curl -LsIo /dev/null -w '%{url_effective}' 'https://discord.com/api/download?platform=linux&format=tar.gz')"
curl_error="${?}"
if [ "${curl_error}" != 0 ]; then
zenity_error "curl error ${curl_error}"
exit 1
fi
case ${URL} in
https://dl.discordapp.net/apps/linux/*.*.*/discord-*.*.*.tar.gz|https://stable.dl2.discordapp.net/apps/linux/*.*.*/discord-*.*.*.tar.gz)
# Pattern matched, do nothing
true
;;
*)
if ! question "The redirect HTTPS address doesn't match our pattern. The directory structure of downloads from Discord might have changed or the server has been compromised. Do you want to continue?"; then
wait
exit 0
fi
;;
esac
REMOTE_VER="$(echo "${URL}" | grep -Eo '[0-9]{1,}.[0-9]{1,}.[0-9]{1,}' | head -n 1)"
LOCAL_VER="n/a"
if [ -f "${HOME}/.local/opt/discord/resources/build_info.json" ]; then
LOCAL_VER="$(jq -r .version "${HOME}/.local/opt/discord/resources/build_info.json")"
if [ "${REMOTE_VER}" = "${LOCAL_VER}" ]; then
wait
exit 0
fi
fi
if "${installed}" && ! question "New Discord version is available for download!"$'\n'"New version: ${REMOTE_VER}"$'\n'"Old version: ${LOCAL_VER}"$'\n'"Would you like to install it?"; then
wait
exit 0
fi
DL_FILE="$(mktemp)"
curl -Lo "${DL_FILE}" "${URL}"
[ -d "${HOME}/.local/opt" ] || mkdir -p "${HOME}/.local/opt"
( ! [ -d "${HOME}/.local/opt/discord" ] || rm -rvf "${HOME}/.local/opt/discord" )
mkdir "${discord_dir}"
( cd "${discord_dir}" && tar --strip-components=1 -zxvf "${DL_FILE}" Discord/ )
chmod u+x "${HOME}/.local/opt/discord/Discord"
[ -d "${HOME}/.local/share/applications" ] || mkdir -p "${HOME}/.local/share/applications"
printf "[Desktop Entry]
Name=Discord
StartupWMClass=discord
Comment=All-in-one voice and text chat for gamers that's free, secure, and works on both your desktop and phone.
GenericName=Internet Messenger
Exec=%s
Icon=%s/.local/opt/discord/discord.png
Type=Application
Categories=Network;InstantMessaging;
Path=%s/.local/bin
Actions=uninstall
[Desktop Action uninstall]
Name=Uninstall Discord
Exec=%s uninstall" "$(readlink -f "${0}")" "${HOME}" "${HOME}" "$(readlink -f "${0}")"> "${HOME}/.local/share/applications/discord.desktop"
rm "${DL_FILE}"
if "${installed}"; then
if question "Installing update finished, changes will be available after next restart of Discord. Would you like to do that now?"; then
killall Discord
launch
else
wait
fi
else
launch
fi
)