More strictly sh (posix) compatible + fix things
This commit is contained in:
		
							parent
							
								
									8e5f317176
								
							
						
					
					
						commit
						182d1ce9ee
					
				
					 2 changed files with 51 additions and 36 deletions
				
			
		
							
								
								
									
										17
									
								
								README.md
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								README.md
									
										
									
									
									
								
							|  | @ -1,21 +1,20 @@ | ||||||
| # RPM Package for Discord | # RPM Package for Discord | ||||||
| I love Discord. But sadly, the devs don't provide any RPM package... Therefore I've made one!   | I love Discord. But sadly, the devs don't provide any RPM package... Therefore I've made one!   | ||||||
| It is based on the [discord's canary linux build](https://github.com/crmarsh/discord-linux-bugs).   | To be precise, I've made a script that downloads the latest [discord's canary linux build](https://github.com/crmarsh/discord-linux-bugs) and creates a RPM package with it. | ||||||
| 
 | 
 | ||||||
| ## How to use | ## How to use | ||||||
| ### Build the rpm package yourself | Run the [create-package.sh](https://github.com/RPM-Outpost/discord/blob/master/create-package.sh) script from the command line. | ||||||
| Run the [create-package.sh](https://github.com/RPM-Outpost/discord/blob/master/create-package.sh) script (from the command line). |  | ||||||
| It will download the latest version of discord and build an RPM package. | It will download the latest version of discord and build an RPM package. | ||||||
| Then, install the package with `sudo dnf install <rpm file>`. | Then, install the package with `sudo dnf install <rpm file>`. | ||||||
| 
 | 
 | ||||||
| **Note:** You need to install the `rpmdevtools` package to use the script. | ### Requirements | ||||||
|  | You need to install the `rpmdevtools` package to build RPM packages and use the script. | ||||||
| Don't worry: the script detects if it isn't installed, and can install it for you. | Don't worry: the script detects if it isn't installed, and can install it for you. | ||||||
| 
 | 
 | ||||||
| ### Use the rpm package I've already built | ### About root privileges | ||||||
| I've already built a package with my script. | Building an RPM package with root privileges is dangerous, because a mistake in SPEC file could result in running nasty commands. | ||||||
| You can download this package [here](https://github.com/RPM-Outpost/discord/blob/master/RPMs/x86_64/discord-0.0.10-canary.fc24.x86_64.rpm). | See [](http://serverfault.com/questions/10027/why-is-it-bad-to-build-rpms-as-root). | ||||||
| 
 | 
 | ||||||
| ### How to update | ## Update discord | ||||||
| When a new version of discord is released, you can run the `create-package.sh` script again to create an updated package. | When a new version of discord is released, you can run the `create-package.sh` script again to create an updated package. | ||||||
| Or you can download an updated package from my github repository. |  | ||||||
| Then, simply install the updated package with `sudo dnf install <rpm file>`. | Then, simply install the updated package with `sudo dnf install <rpm file>`. | ||||||
|  |  | ||||||
|  | @ -2,77 +2,92 @@ | ||||||
| # Author: TheElectronWill | # Author: TheElectronWill | ||||||
| # This script downloads the latest version of Discord for linux, and creates a package with rpmbuild. | # This script downloads the latest version of Discord for linux, and creates a package with rpmbuild. | ||||||
| 
 | 
 | ||||||
| rpm_dir=$PWD/RPMs | # Define the needed paths | ||||||
| 
 |  | ||||||
| desktop_model=$PWD/discord.desktop | desktop_model=$PWD/discord.desktop | ||||||
| spec_file=$PWD/discord.spec | spec_file=$PWD/discord.spec | ||||||
| 
 | 
 | ||||||
|  | rpm_dir=$PWD/RPMs | ||||||
| work_dir=$PWD/work | work_dir=$PWD/work | ||||||
| downloaded_dir=$work_dir/discord | downloaded_dir=$work_dir/discord | ||||||
| desktop_file=$work_dir/discord.desktop | desktop_file=$work_dir/discord.desktop | ||||||
| 
 | 
 | ||||||
|  | # It's a bad idea to run rpmbuild as root! | ||||||
|  | if [ "$(id -u)" = "0" ]; then | ||||||
|  | 	echo '----- WARNING -----' | ||||||
|  | 	echo 'This script should NOT be executed with root privileges!' | ||||||
|  | 	echo 'Building rpm packages as root is dangerous and may harm the system!' | ||||||
|  | 	echo 'Actually, badly written RPM spec files may execute dangerous command in the system directories.' | ||||||
|  | 	echo 'So it is REALLY safer not to run this script as root.' | ||||||
|  | 	echo 'If you still want to run this script as root, type "do it!" within 5 seconds (type anything else to exit):' | ||||||
|  | 	read -t 5 -n 6 -p 'Do you really want to do it (not recommended)? ' answer | ||||||
|  | 	if [ "$answer" != "do it!" ]; then | ||||||
|  | 		exit | ||||||
|  | 	fi | ||||||
|  | fi | ||||||
|  | 
 | ||||||
| # Checks that rpmbuild is installed | # Checks that rpmbuild is installed | ||||||
| if ! type 'rpmbuild' > /dev/null | if ! type 'rpmbuild' > /dev/null; then | ||||||
| then | 	echo 'You need the rpm development tools to create rpm packages.' | ||||||
| 	echo "You need the rpm development tools to create rpm packages" | 	read -n 1 -p 'Do you want to install the rpmdevtools package now? [y/N]' answer | ||||||
| 	read -p "Do you want to install rpmdevtools now? This will run sudo dnf install rpmdevtools. [y/N]" answer |  | ||||||
| 	case $answer in | 	case $answer in | ||||||
| 		[Yy]* ) sudo dnf install rpmdevtools;; | 		y|Y) | ||||||
|  | 			sudo -p 'Enter your password to install rpmdevtools: ' dnf install rpmdevtools | ||||||
|  | 			;; | ||||||
| 		*)  | 		*)  | ||||||
| 			echo "Ok, I won't install rpmdevtools." | 			echo "Ok, I won't install rpmdevtools." | ||||||
| 			exit | 			exit | ||||||
| 		;; |  | ||||||
| 	esac | 	esac | ||||||
| else | else | ||||||
| 	echo "rpmbuild detected!" | 	echo "rpmbuild detected!" | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| # Download the discord tar.gz archive and puts its name in the global variable archive_name. | # Downloads the discord tar.gz archive and puts its name in the global variable archive_name. | ||||||
| function download_discord { | download_discord() { | ||||||
| 	echo 'Downloading discord canary for linux...' | 	echo 'Downloading discord canary for linux...' | ||||||
| 	wget -q --show-progress --content-disposition "https://discordapp.com/api/download/canary?platform=linux&format=tar.gz" | 	wget -q --show-progress --content-disposition "https://discordapp.com/api/download/canary?platform=linux&format=tar.gz" | ||||||
| 	archive_name=$(ls *.tar.gz) | 	archive_name=$(ls *.tar.gz) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| # Asks the user if he/she wants to remove the specified directory, and removes it if he wants to. | # Asks the user if they want to remove the specified directory, and removes it if they want to. | ||||||
| function ask_remove_dir { | ask_remove_dir() { | ||||||
| 	read -p "Do you want to remove the \"$1\" directory? [y/N]" answer | 	read -p "Do you want to remove the \"$1\" directory? [y/N]" answer | ||||||
| 	case $answer in | 	case $answer in | ||||||
| 		[Yy]* ) | 		y|Y) | ||||||
| 			rm -r "$1" | 			rm -r "$1" | ||||||
| 			echo "\"$1\" directory removed."		 | 			echo "\"$1\" directory removed."		 | ||||||
| 			;; | 			;; | ||||||
| 		* ) echo "Ok, I won't remove it." ;; | 		*) | ||||||
|  | 			echo "Ok, I won't remove it." | ||||||
|  | 			;; | ||||||
| 	esac | 	esac | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| # If the specified directory exists, asks the user if he/she wants to remove it. | # If the specified directory exists, asks the user if they want to remove it. | ||||||
| # If it doesn't exist, creates it. | # If it doesn't exist, creates it. | ||||||
| function manage_dir { | manage_dir() { | ||||||
| 	if [ -d "$1" ]; then | 	if [ -d "$1" ]; then | ||||||
| 		echo "The $2 directory already exist. It may contain outdated things." | 		echo "The $2 directory already exist. It may contain outdated things." | ||||||
| 		ask_remove_dir "$1" | 		ask_remove_dir "$1" | ||||||
| 	else |  | ||||||
| 		mkdir "$work_dir" |  | ||||||
| 	fi | 	fi | ||||||
|  | 	mkdir -p "$work_dir" | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| manage_dir "$work_dir" 'work' | manage_dir "$work_dir" 'work' | ||||||
| manage_dir "$rpm_dir" 'RPMs' | manage_dir "$rpm_dir" 'RPMs' | ||||||
| cd "$work_dir" | cd "$work_dir" | ||||||
| 
 | 
 | ||||||
| # Download discord if needed | # Downloads discord if needed | ||||||
| archive_name=$(ls *.tar.gz) | archive_name=$(ls *.tar.gz 2>/dev/null) | ||||||
| if [ $? -eq 0 ]; then | if [ $? -eq 0 ]; then | ||||||
| 	echo "Found $archive_name" | 	echo "Found $archive_name" | ||||||
| 	read -p 'Do you want to use this archive instead of downloading a new one? [y/N]' answer | 	read -p 'Do you want to use this archive instead of downloading a new one? [y/N]' answer | ||||||
| 	case $answer in | 	case $answer in | ||||||
| 		[Yy]* ) | 		y|Y) | ||||||
| 			echo 'Ok, I will use this this archive.' | 			echo 'Ok, I will use this archive.' | ||||||
| 			;; | 			;; | ||||||
| 		*) | 		*) | ||||||
|  | 			rm "$archive_name" | ||||||
| 			download_discord | 			download_discord | ||||||
| 			;; |  | ||||||
| 	esac | 	esac | ||||||
| else | else | ||||||
| 	download_discord | 	download_discord | ||||||
|  | @ -103,14 +118,15 @@ echo "Archive: $archive_name" | ||||||
| echo "Version: $version_number" | echo "Version: $version_number" | ||||||
| echo "Icon: $icon_name" | echo "Icon: $icon_name" | ||||||
| 
 | 
 | ||||||
| # Creates a .desktop file: | # Creates a .desktop file | ||||||
| echo 'Creating .desktop file...' | echo 'Creating .desktop file...' | ||||||
| sed "s/_version/$version_number/; s/_icon/$icon_name/" "$desktop_model" > "$desktop_file" | sed "s/_version/$version_number/; s/_icon/$icon_name/" "$desktop_model" > "$desktop_file" | ||||||
| 
 | 
 | ||||||
| # Chooses the spec file based on the system's architecture and build the packages | # Builds the packages | ||||||
| echo 'Creating the RPM package...' | echo 'Creating the RPM package...' | ||||||
| rpmbuild -bb $spec_file --define "_topdir $work_dir" --define "_rpmdir $rpm_dir" --define "version_number $version_number" --define "downloaded_dir $downloaded_dir" --define "desktop_file $desktop_file" | rpmbuild -bb $spec_file --define "_topdir $work_dir" --define "_rpmdir $rpm_dir" --define "version_number $version_number" --define "downloaded_dir $downloaded_dir" --define "desktop_file $desktop_file" | ||||||
| 
 | 
 | ||||||
|  | # Done | ||||||
| echo '-----------' | echo '-----------' | ||||||
| echo 'Done!' | echo 'Done!' | ||||||
| echo "The RPM package is located in the \"RPMs/x86_64\" folder." | echo "The RPM package is located in the \"RPMs/x86_64\" folder." | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 TheElectronWill
						TheElectronWill