Skip to content

Commit

Permalink
feat(tools): added new function to download the discord file
Browse files Browse the repository at this point in the history
Now the script can download the Discord file. The script will ask you to choose if you want to download or provide the path to the file. I also included a small fix to delete the temporary folder if an error occurs while moving the files.
  • Loading branch information
walthersmith committed Jul 9, 2024
1 parent 7522432 commit 885291f
Showing 1 changed file with 52 additions and 15 deletions.
67 changes: 52 additions & 15 deletions dis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,61 @@ check_root() {
fi
}

download_discord_file() {
local url="https://discord.com/api/download?platform=linux&format=tar.gz"
local output_file="discord.tar.gz"

if command -v curl > /dev/null; then
print_color "RED" "Using curl to download the file from https://discord.com..."
curl -L -o "$output_file" "$url"
elif command -v wget > /dev/null; then
print_color "RED" "Using wget to download the file from https://discord.com..."
wget -O "$output_file" "$url"
else
print_color "RED" "Error: Neither curl nor wget is installed."
return 1
fi

print_color "GREEN" "Download completed: $output_file"
DISCORD_ARCHIVE="$output_file"
}

get_discord_archive() {
while true; do
if [ -n "$1" ] && [ -f "$1" ]; then
DISCORD_ARCHIVE="$1"
break
else
read -p "Enter the path to the Discord archive (e.g., /path/to/discord.tar.gz): " DISCORD_ARCHIVE
if [ -f "$DISCORD_ARCHIVE" ]; then
break
else
print_color "YELLOW" "File not found. Please try again."
fi
fi
print_color "YELLOW" "Would you like to provide a path to the Discord archive or download it?"
PS3="Please select an option (1-2): "
options=("Provide a file path" "Download Discord.tar.gz")
select opt in "${options[@]}"
do
case "$opt" in
"Provide a file path")
while true; do
if [ -n "$1" ] && [ -f "$1" ]; then
DISCORD_ARCHIVE="$1"
break
else
read -p "Enter the path to the Discord archive (e.g., /path/to/discord.tar.gz): " DISCORD_ARCHIVE
if [ -f "$DISCORD_ARCHIVE" ]; then
break 2
else
print_color "YELLOW" "File not found. Please try again."
fi
fi
done
;;
"Download Discord.tar.gz")
download_discord_file
break 2
;;

*)
print_color "RED" "Invalid option $REPLY"
;;
esac
done
}

install_discord() {
print_color "GREEN" "Starting Discord installation..."
print_color "GREEN" "Starting Discord installation..."
# Create temporary and installation directories
print_color "YELLOW" "Creating directories..."
mkdir -p /opt/discord
Expand All @@ -46,7 +83,7 @@ install_discord() {
tar -xzvf "$DISCORD_ARCHIVE" -C temp_discord || { print_color "RED" "Failed to extract Discord archive."; exit 1; }
# Move contents to installation directory
print_color "YELLOW" "Moving files to installation directory..."
mv temp_discord/Discord/* /opt/discord/ || { print_color "RED" "Failed to move Discord files."; exit 1; }
mv temp_discord/Discord/* /opt/discord/ || { print_color "RED" "Failed to move Discord files."; rm -rf temp_discord && exit 1; }
# Clean up temporary directory
rm -rf temp_discord
# Create symlink
Expand Down Expand Up @@ -116,7 +153,7 @@ main() {
break
;;
"Exit")
print_color "GREEN" "Thank you for using Discord Manager. Goodbye!"
print_color "GREEN" "Thank you for using Discord installer Script. Goodbye!"
exit 0
;;
*)
Expand Down

0 comments on commit 885291f

Please sign in to comment.