Skip to content

Instantly share code, notes, and snippets.

@RobChiocchio
Last active February 9, 2026 05:23
Show Gist options
  • Select an option

  • Save RobChiocchio/3e4a9eac1d4f8c472b999554ffa1c42e to your computer and use it in GitHub Desktop.

Select an option

Save RobChiocchio/3e4a9eac1d4f8c472b999554ffa1c42e to your computer and use it in GitHub Desktop.

Revisions

  1. RobChiocchio revised this gist Apr 30, 2024. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions install-flatpak-betterdiscord.sh
    Original file line number Diff line number Diff line change
    @@ -2,12 +2,14 @@
    # This script installs BetterDiscord for the Flatpak version of Discord on Linux.
    # Written by Rob Chiocchio on 04/30/2024

    ### Variables ###
    # Color variables
    NO_COLOR="\033[0m"
    COLOR="\033[0;36m" # Cyan

    DOWNLOAD_URL=https://github.com/BetterDiscord/Installer/releases/latest/download/BetterDiscord-Linux.AppImage
    # Flatpak Discord AppID and download URL for latest BetterDiscord Linux AppImage release
    APPID=com.discordapp.Discord
    DOWNLOAD_URL=https://github.com/BetterDiscord/Installer/releases/latest/download/BetterDiscord-Linux.AppImage

    # Set temporary directory
    DISCORD_TMPDIR="$XDG_RUNTIME_DIR/app/$APPID/"
    @@ -17,24 +19,28 @@ cd $TEMP
    # Cleanup temp directory on exit
    trap "rm -rf $TEMP" EXIT

    # Functions
    ### Functions ###
    # Log a message with colors and a timestamp
    log () {
    echo -e "${COLOR}[$(date +'%Y-%m-%d %H:%M:%S')]${NO_COLOR} $1"
    }

    # Return true (0) if Discord is running, false (1) otherwise. Sets PIDS variable to the list of PIDs.
    is_running () {
    PIDS=$(flatpak ps | grep $APPID | grep -oP "(^\\S+)")
    return $(test -n "$PIDS")
    }

    # Main script
    ### Main Script ###
    log "BetterDiscord installer script for Flatpak Discord by Rob Chiocchio"

    # Check if Discord is running
    if is_running; then
    log "Discord is currently running. Please close Discord before installing BetterDiscord. Press any key to continue..."
    read -n 1 -r -s -p ""
    fi

    # If Discord is still running, kill processes
    if is_running; then
    echo "$PIDS" | while read -r pid; do
    log "Killing Discord process $pid..."
  2. RobChiocchio created this gist Apr 30, 2024.
    58 changes: 58 additions & 0 deletions install-flatpak-betterdiscord.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    #!/bin/bash
    # This script installs BetterDiscord for the Flatpak version of Discord on Linux.
    # Written by Rob Chiocchio on 04/30/2024

    # Color variables
    NO_COLOR="\033[0m"
    COLOR="\033[0;36m" # Cyan

    DOWNLOAD_URL=https://github.com/BetterDiscord/Installer/releases/latest/download/BetterDiscord-Linux.AppImage
    APPID=com.discordapp.Discord

    # Set temporary directory
    DISCORD_TMPDIR="$XDG_RUNTIME_DIR/app/$APPID/"
    TEMP=$(TMPDIR=$DISCORD_TMPDIR mktemp -d)
    cd $TEMP

    # Cleanup temp directory on exit
    trap "rm -rf $TEMP" EXIT

    # Functions
    log () {
    echo -e "${COLOR}[$(date +'%Y-%m-%d %H:%M:%S')]${NO_COLOR} $1"
    }

    is_running () {
    PIDS=$(flatpak ps | grep $APPID | grep -oP "(^\\S+)")
    return $(test -n "$PIDS")
    }

    # Main script
    log "BetterDiscord installer script for Flatpak Discord by Rob Chiocchio"

    if is_running; then
    log "Discord is currently running. Please close Discord before installing BetterDiscord. Press any key to continue..."
    read -n 1 -r -s -p ""
    fi

    if is_running; then
    echo "$PIDS" | while read -r pid; do
    log "Killing Discord process $pid..."
    flatpak kill $pid
    done
    fi

    log "Downloading BetterDiscord..."
    wget --quiet --show-progress --progress=bar:force:noscroll -O BetterDiscord.AppImage $DOWNLOAD_URL
    chmod +x $TEMP/BetterDiscord.AppImage

    log "Extracting BetterDiscord installer files..."
    $TEMP/BetterDiscord.AppImage --appimage-extract 2>&1 > /dev/null

    log "Running BetterDiscord installer..."
    flatpak run --command=$TEMP/squashfs-root/betterdiscord-installer $APPID --no-sandbox

    log "Cleaning up temporary files..."
    rm -rf $TEMP

    log "BetterDiscord installation complete!"