Created
May 3, 2024 23:19
-
-
Save Pinjontall94/a3bead497e6021ad57072afa29cfd0e5 to your computer and use it in GitHub Desktop.
update generic linux discord tarball in /opt/Discord
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| #NOTE: all that really has to happen is the following: | |
| # $ sudo rm -rf /opt/Discord && sudo tar -xf ~/Downloads/discord-*.tar.gz -C /opt/ | |
| # Globals | |
| old_cwd="$(pwd)" | |
| downloads_dir="$HOME/Downloads" | |
| opt_discord_dir="/opt/Discord" | |
| tarball_pattern=".*discord.*\.tar\.gz" | |
| discord_tarball= | |
| STATUS= | |
| check_folders() { | |
| if [ -d "$opt_discord_dir" ]; then | |
| return 0 | |
| else | |
| return 1 | |
| fi | |
| } | |
| rm_old_discord() { | |
| # This will fail and need sudo, but check the errtrace to make sure paths are correct! | |
| echo "Removing $opt_discord_dir [requires sudo]..." | |
| sudo rm -rv $opt_discord_dir | |
| if [ ! -d "$opt_discord_dir" ]; then | |
| echo "$opt_discord_dir removed" | |
| return 0 | |
| else | |
| return 1 | |
| fi | |
| } | |
| find_tarball() { | |
| discord_tarball=$(find "$downloads_dir" \ | |
| -maxdepth 1 \ | |
| -type f \ | |
| -iregex "$tarball_pattern" \ | |
| 2>/dev/null) | |
| if [ -f "$discord_tarball" ]; then | |
| return 0 | |
| else | |
| return 1 | |
| fi | |
| } | |
| extract_tarball() { | |
| echo "Extracting $discord_tarball to /opt/" | |
| sudo tar -xvf "$discord_tarball" -C /opt/ | |
| if [ -d "$opt_discord_dir" ]; then | |
| echo "Discord updated successfully :)" | |
| return 0 | |
| else | |
| return 1 | |
| fi | |
| } | |
| main() { | |
| if check_folders && find_tarball; then | |
| echo "/opt/Discord found" | |
| echo "Discord tarball found:" | |
| echo -e "\t$discord_tarball" | |
| rm_old_discord && extract_tarball | |
| return 0 | |
| elif check_folders; then | |
| echo "Discord tarball not found in $downloads_dir" | |
| return 1 | |
| elif find_tarball; then | |
| echo "$opt_discord_dir not found" | |
| return 1 | |
| fi | |
| } | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment