Skip to content

Commit

Permalink
Add --upgrade-url option (#56)
Browse files Browse the repository at this point in the history
* Add --upgrade-url option
* Update the location of the flatpak installation
* Scan /usr/lib64 (Fedora package)
  • Loading branch information
ObserverOfTime authored May 6, 2020
1 parent 5f13ec2 commit cc0d6da
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ You can then keep `betterdiscordctl` up to date with one command:

Increases the verbosity level, for progressively more debugging information.

* `-s` / `--scan` (default `/opt:/usr/share`)
* `-s` / `--scan` (default `/opt:/usr/share:/usr/lib64`)

Changes the directories scanned for Discord installations. These are scanned
in the order provided. Note that these do **not** end in `/discord`—if your
Expand Down Expand Up @@ -91,13 +91,17 @@ You can then keep `betterdiscordctl` up to date with one command:

Automatically detect the default Snap directories for Discord. The `-c` flag
is set due to Snaps apps being [confined][snapcraft-docs]. A given option
argument will be used as the snap(1) command to call.
argument will be used as the snap command to call.

* `--flatpak`

Automatically detect the default Flatpak directories for Discord. The `-c`
flag is set due to Flatpak apps being [sandboxed][flatpak-docs]. A given
option argument will be used as the flatpak(1) command to call.
option argument will be used as the flatpak command to call.

* `--upgrade-url` (default `https://git.io/bdctl`)

Use the specified URL for upgrading betterdiscordctl.

[snapcraft-docs]: https://docs.snapcraft.io/reference/confinement
[flatpak-docs]: http://docs.flatpak.org/en/latest/working-with-the-sandbox.html
Expand Down Expand Up @@ -140,8 +144,8 @@ Updates `betterdiscordctl` to the latest version available on GitHub.

* `betterdiscordctl status -s /usr/share`

Shows the status of the default Discord install in `/usr/share`, instead
of `/opt`.
Shows the status of the default Discord installation in `/usr/share`,
instead of `/opt`.

* `betterdiscordctl install -f ptb`

Expand Down
54 changes: 35 additions & 19 deletions betterdiscordctl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ set -ueo pipefail
shopt -s dotglob extglob nullglob

# Constants
VERSION=1.6.1
VERSION=1.7.0
SOURCE=$(readlink -f "${BASH_SOURCE[0]}")
GITHUB_URL='https://raw.githubusercontent.com/bb010g/betterdiscordctl/master/betterdiscordctl'
DISABLE_UPGRADE=

# Options
cmd=status
verbosity=0
scan=(/opt /usr/share)
scan=(/opt /usr/share /usr/lib64)
flavors=('' canary ptb)
discord=
modules=
Expand All @@ -22,6 +21,7 @@ bd=
copy_bd=
snap=
flatpak=
upgrade_url='https://git.io/bdctl'

# Variables
flavor=
Expand All @@ -40,22 +40,24 @@ Options:
-h, --help Display this help message and exit
-v, --verbose Increase verbosity
-s, --scan=DIRECTORIES Colon-separated list of directories to scan for
a Discord installation.
a Discord installation
(default '/opt:/usr/share')
-f, --flavors=FLAVORS Colon-separated list of Discord flavors
(default ':canary:ptb')
-d, --discord=DIRECTORY Use specified Discord directory
-d, --discord=DIRECTORY Use the specified Discord directory
(requires --modules)
-m, --modules=DIRECTORY Use specified Discord modules directory
-r, --bd-repo=REPOSITORY Use specified Git repo for BetterDiscord
--bd-repo-branch=BRANCH Use specified Git branch for BetterDiscord
-m, --modules=DIRECTORY Use the specified Discord modules directory
-r, --bd-repo=REPOSITORY Use the specified Git repo for BetterDiscord
--bd-repo-branch=BRANCH Use the specified Git branch for BetterDiscord
(default 'stable16')
-b, --betterdiscord=DIRECTORY Use specified BetterDiscord directory
-b, --betterdiscord=DIRECTORY Use the specified BetterDiscord directory
-c, --copy-bd Copy BD directory instead of symlinking
--snap[=COMMAND] Use the Snap version of Discord (optionally
using the specified snap(1) command)
using the specified snap command)
--flatpak[=COMMAND] Use the Flatpak version of Discord (optionally
using the specified flatpak(1) command)
using the specified flatpak command)
--upgrade-url=URL URL to upgrade betterdiscordctl with
(default 'https://git.io/bdctl')
Commands:
status (default) Show the current Discord patch state.
Expand Down Expand Up @@ -203,6 +205,16 @@ while :; do
--flatpak=)
die_non_empty '--flatpak'
;;
--upgrade-url)
if [[ ${2+x} ]]; then upgrade_url=$2; shift
else die_non_empty '--upgrade-url'; fi
;;
--upgrade-url=?*)
upgrade_url=${1#*=}
;;
--upgrade-url=)
die_non_empty '--upgrade-url'
;;
--)
shift
break
Expand Down Expand Up @@ -322,17 +334,18 @@ bdc_upgrade() {
'If you installed this from a package, its maintainer should keep it up to date.'
fi

github_version=$(curl -sN "$GITHUB_URL" | sed -n 's/^VERSION=//p')
github_version=$(curl -NLSs "$upgrade_url" | sed -n 's/^VERSION=//p')
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
die "ERROR: GitHub couldn't be reached to check the version."
fi
verbose 2 "VV: Script location: $SOURCE"
verbose 2 "VV: Upgrade URL: $upgrade_url"
verbose 1 "V: Local version: $VERSION"
verbose 1 "V: GitHub version: $github_version"
semver_diff=$(Semver::compare "$github_version" "$VERSION")
if [[ $semver_diff -eq 1 ]]; then
printf 'Downloading betterdiscordctl...\n' >&2
if curl -Sso "$SOURCE" "$GITHUB_URL"; then
if curl -LSso "$SOURCE" "$upgrade_url"; then
printf 'Successfully updated betterdiscordctl.\n' >&2
else
die 'ERROR: Failed to update betterdiscordctl.' \
Expand Down Expand Up @@ -397,7 +410,7 @@ bdc_scan() {

bdc_find_modules() {
declare -a all_modules
all_modules=("$discord_config/"+([0-9]).+([0-9]).+([0-9])'/modules')
all_modules=("$discord_config/"+([0-9]).+([0-9]).+([0-9])/modules)
((${#all_modules[@]})) || die 'ERROR: Discord modules directory not found.'
modules=${all_modules[-1]}
verbose 1 "V: Found modules in $modules"
Expand All @@ -406,14 +419,14 @@ bdc_find_modules() {
bdc_snap() {
# shellcheck disable=SC2016
# Expansion should happen inside snap's shell.
snap_location=$("$snap_bin" run --shell discord <<< 'echo "$SNAP" 1>&3' 3>&1)
snap_location=$("$snap_bin" run --shell discord <<< $'printf -- \'%s\n\' "$SNAP" 1>&3' 3>&1)
discord=${snap_location:?}/usr/share/discord
verbose 2 "VV: Checking $discord"
if [[ -d $discord ]]; then
verbose 1 "V: Using Discord at $discord"
# shellcheck disable=SC2016
# Expansion should happen inside snap's shell.
xdg_config=$("$snap_bin" run --shell discord <<< 'echo "${XDG_CONFIG_HOME:-$SNAP_USER_DATA/.config}" 1>&3' 3>&1)
xdg_config=$("$snap_bin" run --shell discord <<< $'printf -- \'%s/.config\n\' "$SNAP_USER_DATA" 1>&3' 3>&1)
discord_config=$xdg_config/discord
bdc_find_modules
else
Expand All @@ -433,14 +446,17 @@ bdc_flatpak() {
# We're just going to grab the last line and hope for the best.
flatpak_location=$("$flatpak_bin" info --show-location com.discordapp.Discord)
flatpak_location=${flatpak_location##*$'\n'}
discord=${flatpak_location:?}/files/extra
if [[ -d ${flatpak_location:?}/files/discord ]]; then
discord=$flatpak_location/files/discord
else
discord=$flatpak_location/files/extra
fi
verbose 2 "VV: Checking $discord"
if [[ -d $discord ]]; then
verbose 1 "V: Using Discord at $discord"
# We can avoid the earlier warning problem by using FD 3. yay.
# shellcheck disable=SC2016
# Expansion should happen inside flatpak's shell.
flatpak_config=$("$flatpak_bin" run --command=sh com.discordapp.Discord -c 'echo $XDG_CONFIG_HOME 1>&3' 3>&1)
flatpak_config=$("$flatpak_bin" run --command=sh com.discordapp.Discord -c $'printf -- \'%s\n\' "$XDG_CONFIG_HOME"')
discord_config=${flatpak_config:-$HOME/.var/app/com.discordapp.Discord/config}/discord
if [[ ! -d $discord_config ]]; then
printf 'WARN: Config directory not found for Discord (%s, %s).\n' "$discord" "$discord_config" >&2
Expand Down

0 comments on commit cc0d6da

Please sign in to comment.