-
Notifications
You must be signed in to change notification settings - Fork 1
/
rocketship.sh
executable file
·167 lines (142 loc) · 4.82 KB
/
rocketship.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
#!/usr/bin/env bash
# rocketship.sh v1.0.0 https://github.com/moonlight-mod/rocketship
set -eu
discord_branch="stable"
discord_exe="Discord"
discord_exe_kebab="discord"
force_yes=false
print_usage() {
set +x
echo "rocketship.sh v1.0.0 https://github.com/moonlight-mod/rocketship"
echo "Usage: $0 [options]"
echo "Options:"
echo " -b, --branch <branch> The branch of Discord to install (stable, ptb, canary)"
echo " -y, --yes Automatically answer yes to all prompts"
echo " -h, --help Display this help message"
set -x
}
set_branch() {
case $discord_branch in
"stable" | "Discord" | "discord")
discord_branch="stable"
discord_exe="Discord"
discord_exe_kebab="discord"
;;
"ptb" | "DiscordPTB" | "discord-ptb")
discord_branch="ptb"
discord_exe="DiscordPTB"
discord_exe_kebab="discord-ptb"
;;
"canary" | "DiscordCanary" | "discord-canary")
discord_branch="canary"
discord_exe="DiscordCanary"
discord_exe_kebab="discord-canary"
;;
*)
echo "Invalid branch: $input_branch"
print_usage
exit 1
;;
esac
}
# https://stackoverflow.com/a/9271406
while [ "${1:-}" != "" ]; do
case $1 in
"-b" | "--branch")
shift
discord_branch=$1
set_branch
;;
"-y" | "--yes")
force_yes=true
;;
"-h" | "--help")
print_usage
exit 0
;;
esac
shift
done
download_url="https://discordapp.com/api/download/$discord_branch?platform=linux&format=tar.gz"
electron_url="https://github.com/moonlight-mod/discord-electron/releases/latest/download/electron.tar.gz"
venmic_url="https://registry.npmjs.org/@vencord/venmic/-/venmic-6.1.0.tgz"
venmic_sum="7d8694997ff2eeffe1dea6205df1af56df8f2d2656d9ba966bc884b23cb08c1f"
work_dir="/tmp/moonlight-rocketship"
# TODO we should use XDG environment variables
discord_dir="$HOME/.local/share/$discord_exe"
applications_dir="$HOME/.local/share/applications"
icons_dir="$HOME/.local/share/icons/hicolor/256x256"
set +x
echo "rocketship will do the following:"
echo "- Download Discord from $download_url"
echo "- Download modified Electron from $electron_url"
echo "- Download venmic from $venmic_url"
echo "- Install Discord to $discord_dir"
echo "- Add a desktop entry and icon"
set -x
if [ $force_yes = false ]; then
read -p "Do you want to continue? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Exiting."
exit 0
fi
fi
if [ -d $work_dir ]; then
echo "Cleaning up previous run of rocketship in $work_dir..."
rm -rf $work_dir
fi
mkdir -p $work_dir
if [ -d $discord_dir ]; then
if [ $force_yes = false ]; then
read -p "Discord is already installed at $discord_dir. Do you want to delete it? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Exiting."
exit 0
fi
fi
echo "Deleting existing Discord installation in $discord_dir..."
rm -rf $discord_dir
fi
echo "Downloading Discord..."
wget -O "$work_dir/discord.tar.gz" "$download_url"
tar -xf "$work_dir/discord.tar.gz" -C "$work_dir"
discord_extracted_dir="$work_dir/$discord_exe"
echo "Downloading modified Electron..."
wget -O "$work_dir/electron.tar.gz" "$electron_url"
mkdir -p "$work_dir/electron"
tar -xf "$work_dir/electron.tar.gz" -C "$work_dir/electron"
echo "Installing modified Electron..."
mv "$work_dir/electron" "$discord_dir"
echo "Downloading venmic..."
venmic_tar_path="$work_dir/venmic.tar.gz"
venmic_target_path="$discord_dir/venmic.node"
wget -O "$venmic_tar_path" "$venmic_url"
venmic_upstream_sum=$(sha256sum "$venmic_tar_path" | awk '{ print $1; }')
if [ "$venmic_upstream_sum" != "$venmic_sum" ]; then
echo "venmic node sum does not match upstream sum. Exiting."
echo "upstream: $venmic_upstream_sum"
echo "wanted: $venmic_sum"
exit 1
fi
mkdir "$work_dir/venmic"
tar xf "$venmic_tar_path" -C "$work_dir/venmic"
mv "$work_dir/venmic/package/prebuilds/venmic-addon-linux-x64/node-napi-v7.node" "$venmic_target_path"
echo "Installing Discord..."
cp "$discord_extracted_dir/$discord_exe_kebab.desktop" "$discord_dir"
cp "$discord_extracted_dir/discord.png" "$discord_dir"
cp "$discord_extracted_dir/postinst.sh" "$discord_dir"
cp -r "$discord_extracted_dir/resources" "$discord_dir"
echo "Renaming executable..."
mv $discord_dir/electron $discord_dir/$discord_exe
echo "Installing desktop entry..."
mkdir -p "$applications_dir"
cp "$discord_dir/$discord_exe_kebab.desktop" "$applications_dir"
sed -i "s|/usr/share/$discord_exe_kebab|$discord_dir|" "$applications_dir/$discord_exe_kebab.desktop"
mkdir -p $icons_dir
cp "$discord_dir/discord.png" "$icons_dir/$discord_exe_kebab.png"
sed -i "s|Icon=$discord_exe_kebab|Icon=$icons_dir/$discord_exe_kebab.png|" "$applications_dir/$discord_exe_kebab.desktop"
echo "Cleaning up $work_dir..."
rm -rf $work_dir
echo "Done! Run $discord_exe in $discord_dir to start Discord directly."