Add PTB support and fallback for missing wget
* Add support for Discord PTB and update the documentation accordingly * Add curl as a fallback when wget is not installed * Fix installation directory being /opt/discord-stable regardless of version * Remove suffix from the Stable version (now simply discord/Discord) * Exit with exit code 1 on error * Miscellaneous minor edits and fixes
This commit is contained in:
		
							parent
							
								
									295f383a75
								
							
						
					
					
						commit
						3f417e97a2
					
				
					 4 changed files with 47 additions and 23 deletions
				
			
		
							
								
								
									
										15
									
								
								README.md
									
										
									
									
									
								
							
							
						
						
									
										15
									
								
								README.md
									
										
									
									
									
								
							|  | @ -6,16 +6,19 @@ Unofficial RPM package for Discord. | |||
| ## How to use | ||||
| 1. [Download](https://github.com/RPM-Outpost/discord/archive/master.zip) and extract the zip. | ||||
| 2. Open a terminal and `cd` to the `discord-master` directory. | ||||
| 3. Run `./create-package.sh stable` to get the stable version of Discord, or `./create-package.sh canary` to get the unstable beta version. | ||||
| 3. Run one of the following depending on the version you want to create a package for: | ||||
|     - Discord Stable: `./create-package.sh stable` | ||||
|     - Discord PTB:     `./create-package.sh ptb` | ||||
|     - Discord Canary: `./create-package.sh canary` | ||||
| 
 | ||||
| ## Features | ||||
| - Downloads the latest version of Discord from the official website | ||||
| - Creates a ready-to-use RPM package | ||||
| - Discord stable and canary can be installed at the same time | ||||
| - Adds Discord to the applications' list with a nice HD icon | ||||
| - Discord Stable, PTB, and Canary can be installed at the same time | ||||
| - Adds Discord to the applications list with a nice HD icon | ||||
| - Supports Fedora (26, 27), OpenSUSE (Leap) and CentOS (7.x) | ||||
| 
 | ||||
| ## More informations | ||||
| ## More information | ||||
| 
 | ||||
| ### Warning - no accents | ||||
| 
 | ||||
|  | @ -23,9 +26,9 @@ The path where you run the script must **not** contain any special character lik | |||
| 
 | ||||
| ### How to update | ||||
| 
 | ||||
| When a new version of discord is released, simply run the script again to get the updated version. | ||||
| When a new version of Discord is released, simply run the script again to get the updated version. | ||||
| 
 | ||||
| ### Requirements | ||||
| ### Dependencies | ||||
| The `rpmdevtools` package is required to build RPM packages. The script detects if it isn't installed and offers to install it. | ||||
| 
 | ||||
| ### About root privileges | ||||
|  |  | |||
|  | @ -26,8 +26,17 @@ else | |||
| 	distrib="unknown" | ||||
| fi | ||||
| 
 | ||||
| # Initializes $wget_progress: detects if the option --show-progress is available | ||||
| wget --help | grep -q '\--show-progress' && wget_progress="-q --show-progress" || wget_progress="" | ||||
| # Initializes $downloader: checks if wget is installed and fallbacks to curl if it isn't | ||||
| hash wget 2>/dev/null && downloader='wget' || downloader='curl' | ||||
| 
 | ||||
| # Initializes $progress: detects if the downloader has a progress option | ||||
| if [[ "$downloader" == 'wget' ]]; then | ||||
|     wget --help | grep -q '\--show-progress' && \ | ||||
| 	  progress='-q --show-progress' || progress='' | ||||
| else | ||||
|     curl --help | grep -q '\--progress-bar' && \ | ||||
|       progress='--progress-bar' || progress='' | ||||
| fi | ||||
| 
 | ||||
| # ask_yesno question | ||||
| ## Asks a yes/no question and stores the result in the 'answer' variable | ||||
|  | @ -58,7 +67,7 @@ ask_remove_dir() { | |||
| ## If it doesn't exist, creates it. | ||||
| manage_dir() { | ||||
| 	if [ -d "$1" ]; then | ||||
| 		echo "The $2 directory already exist and may contain outdated data." | ||||
| 		echo "The $2 directory already exists and may contain outdated data." | ||||
| 		ask_remove_dir "$1" | ||||
| 	fi | ||||
| 	mkdir -p "$1" | ||||
|  |  | |||
|  | @ -20,14 +20,14 @@ elif [[ $distrib == "suse" ]]; then | |||
| 	pkg_req='libatomic1, glibc, alsa, gconf2, libnotify, mozilla-nspr >= 4.13, mozilla-nss >= 3.27, libstdc++6, libX11 >= 1.6, libXtst >= 1.2, libappindicator, libc++1, libXScrnSaver' | ||||
| else | ||||
| 	disp "${red}Sorry, your distribution isn't supported (yet).$reset" | ||||
| 	exit | ||||
| 	exit 1 | ||||
| fi	 | ||||
| 
 | ||||
| # Checks that the version (stable/canary) is given as a parameter. | ||||
| if [[ $# -ne 1 || $1 != "stable" && $1 != "canary" ]]; then | ||||
| # Checks that the version (stable/ptb/canary) is given as a parameter. | ||||
| if [[ $# -ne 1 || $1 != "stable" && $1 != "ptb" && $1 != "canary" ]]; then | ||||
| 	disp "${red}Wrong or missing parameters!$reset" | ||||
| 	echo 'Usage: create-package.sh stable/canary' | ||||
| 	exit | ||||
| 	echo 'Usage: create-package.sh [ stable | ptb | canary ]' | ||||
| 	exit 1 | ||||
| fi | ||||
| 
 | ||||
| # Settings according to the discord type (canary or stable) | ||||
|  | @ -38,19 +38,33 @@ if [[ $1 == "canary" ]]; then | |||
| 	download_url='https://discordapp.com/api/download/canary' | ||||
| 	cut_part=3 | ||||
| 	desktop_file="$work_dir/discord-canary.desktop" | ||||
| elif [[ $1 == "ptb" ]]; then | ||||
| 	app_name='Discord PTB' | ||||
| 	exe_name='DiscordPTB' | ||||
| 	pkg_name='discord-ptb' | ||||
| 	download_url='https://discordapp.com/api/download/ptb' | ||||
| 	cut_part=3 | ||||
| 	desktop_file="$work_dir/discord-ptb.desktop" | ||||
| else | ||||
| 	app_name='Discord' | ||||
| 	exe_name='Discord' | ||||
| 	pkg_name='discord-stable' | ||||
| 	pkg_name='discord' | ||||
| 	download_url='https://discordapp.com/api/download' | ||||
| 	cut_part=2 | ||||
| 	desktop_file="$work_dir/discord-stable.desktop" | ||||
| 	desktop_file="$work_dir/discord.desktop" | ||||
| fi | ||||
| 
 | ||||
| # Downloads the discord tar.gz archive and puts its name in the global variable archive_name. | ||||
| download_discord() { | ||||
| 	echo "Downloading $app_name for linux..." | ||||
| 	wget $wget_progress --content-disposition "${download_url}?platform=linux&format=tar.gz" | ||||
|     if [[ "$downloader" == 'wget' ]]; then | ||||
|       wget --content-disposition $progress "${download_url}?platform=linux&format=tar.gz" | ||||
|     else | ||||
|       # curl's content disposition tends to fail, get the direct URL manually instead and remove the carriage return | ||||
|       direct_url=$(curl -sSI "${download_url}?platform=linux&format=tar.gz" | grep location | awk '{print $2}') | ||||
|       direct_url=${direct_url%$'\r'} | ||||
|       curl -SO $progress $direct_url | ||||
|     fi | ||||
| 	archive_name="$(ls *.tar.gz)" | ||||
| } | ||||
| 
 | ||||
|  | @ -77,13 +91,11 @@ fi | |||
| 
 | ||||
| # Extracts the archive: | ||||
| echo | ||||
| if [ ! -d "$downloaded_dir" ]; then | ||||
| 	mkdir "$downloaded_dir" | ||||
| fi | ||||
| mkdir -p "$downloaded_dir" | ||||
| extract "$archive_name" "$downloaded_dir" "--strip 1" # --strip 1 gets rid of the top archive's directory | ||||
| 
 | ||||
| 
 | ||||
| # Gets the discord's version number + icon file name | ||||
| # Gets Discord's version number + icon file name | ||||
| echo 'Analysing the files...' | ||||
| pkg_version="$(echo "$archive_name" | cut -d'-' -f$cut_part | rev | cut -c 8- | rev)" | ||||
| # cut -d'-' -fn  splits the archive's name around the '-' character, and takes the n-th part | ||||
|  | @ -108,7 +120,7 @@ rpmbuild --quiet -bb "$spec_file" --define "_topdir $work_dir" --define "_rpmdir | |||
| 	--define "desktop_file $desktop_file" --define "pkg_name $pkg_name" --define "pkg_req $pkg_req" | ||||
| 
 | ||||
| disp "${bgreen}Done!${reset_font}" | ||||
| disp "The RPM package is located in the \"RPMs/$arch\" folder." | ||||
| disp "The RPM package is located in the \"RPMs/$arch\" directory." | ||||
| disp '----------------' | ||||
| 
 | ||||
| ask_remove_dir "$work_dir" | ||||
|  |  | |||
|  | @ -5,7 +5,7 @@ | |||
| # downloaded_dir | ||||
| # desktop_file | ||||
| 
 | ||||
| %define install_dir /opt/discord-stable | ||||
| %define install_dir /opt/%{pkg_name} | ||||
| %define apps_dir /usr/share/applications | ||||
| %define _build_id_links none | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 ObserverOfTime
						ObserverOfTime