From c18680c478dc04e53f402fe075b32aecb5ea9490 Mon Sep 17 00:00:00 2001 From: TheElectronWill Date: Sat, 5 Nov 2016 15:32:51 +0100 Subject: [PATCH] Commit work --- create-package.sh | 104 ++++++++++++++++++++++++++++++++++++++++++++++ discord.desktop | 10 +++++ discord.spec | 38 +++++++++++++++++ 3 files changed, 152 insertions(+) create mode 100755 create-package.sh create mode 100644 discord.desktop create mode 100644 discord.spec diff --git a/create-package.sh b/create-package.sh new file mode 100755 index 0000000..6d2c1ca --- /dev/null +++ b/create-package.sh @@ -0,0 +1,104 @@ +#!/bin/sh +# Author: TheElectronWill +# This script downloads the latest version of Discord for linux, and creates a package with rpmbuild. + +rpm_dir=$PWD/RPMs + +desktop_model=$PWD/discord.desktop +spec_file=$PWD/discord.spec + +work_dir=$PWD/work +downloaded_dir=$work_dir/discord +desktop_file=$work_dir/discord.desktop + + +# Download the discord tar.gz archive and puts its name in the global variable archive_name. +function download_discord { + echo 'Downloading discord canary for linux...' + wget -q --show-progress --content-disposition "https://discordapp.com/api/download/canary?platform=linux&format=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. +function ask_remove_dir { + read -p "Do you want to remove the \"$1\" directory? [y/N]" answer + case $answer in + [Yy]* ) + rm -r "$1" + echo "\"$1\" directory removed." + ;; + * ) echo "Ok, I won't remove it." ;; + esac +} + +# If the specified directory exists, asks the user if he/she wants to remove it. +# If it doesn't exist, creates it. +function manage_dir { + if [ -d "$1" ]; then + echo "The $2 directory already exist. It may contain outdated things." + ask_remove_dir "$1" + else + mkdir "$work_dir" + fi +} + +manage_dir "$work_dir" 'work' +manage_dir "$rpm_dir" 'RPMs' +cd "$work_dir" + +# Download discord if needed +archive_name=$(ls *.tar.gz) +if [ $? -eq 0 ]; then + echo "Found $archive_name" + read -p 'Do you want to use this archive instead of downloading a new one? [y/N]' answer + case $answer in + [Yy]* ) + echo 'Ok, I will use this this archive.' + ;; + * ) + download_discord + ;; + esac +else + download_discord +fi + +# Extracts the archive +echo 'Extracting the files...' +archive_name=$(ls *.tar.gz) +if [ ! -d "$downloaded_dir" ]; then + mkdir "$downloaded_dir" +fi +tar -xzf "$archive_name" -C "$downloaded_dir" --strip 1 +# --strip 1 gets rid of the top archive's directory + + +# Gets the discord's version number + icon file name +echo 'Analysing the files...' +version_number=$(echo "$archive_name" | cut -d'-' -f3 | rev | cut -c 8- | rev) +# Explaination on how it works: +# cut -d'-' -f3 splits the archive's name around the '-' character, and takes the 3rd part +# For example if archive_name is "discord-canary-0.0.10.tar.gz" we get "0.0.10.tar.gz" +# Then, rev | cut -c 8- | rev reverse the string, removes the first 7 characters, and re-reverse it. +# This actually removes the last 8 characters, ie the ".tar.gz" part. +# So in our example we'll get version_number=0.0.10 +cd "$downloaded_dir" +icon_name=$(ls *.png) +echo "Archive: $archive_name" +echo "Version: $version_number" +echo "Icon: $icon_name" + +# Creates a .desktop file: +echo 'Creating .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 +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" + +echo '-----------' +echo 'Done!' +echo "The RPM package is located in the \"RPMs/x86_64\" folder." + +# Removes the work directory if the user wants to +ask_remove_dir "$work_dir" diff --git a/discord.desktop b/discord.desktop new file mode 100644 index 0000000..0dcb514 --- /dev/null +++ b/discord.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Version=_version +Type=Application +Name=Discord +Icon=/opt/discord/_icon +Exec=/opt/discord/DiscordCanary +Comment=Free voice and text chat for gamers +Categories=Communication;Internet; +Terminal=false + diff --git a/discord.spec b/discord.spec new file mode 100644 index 0000000..a32f92d --- /dev/null +++ b/discord.spec @@ -0,0 +1,38 @@ +# Defined by the caller (ie the script): +# version_number +# downloaded_dir +# desktop_file + +%define install_dir /opt/discord +%define apps_dir /usr/local/share/applications + +Name: discord +Version: %{version_number} +Release: canary%{?dist} +Summary: Free Voice and Text Chat for Gamers. + +Group: Applications/Internet +License: Proprietary +URL: https://discordapp.com/ +BuildArch: x86_64 +Requires: glibc, alsa-lib, GConf2, libnotify, nspr >= 4.13, nss >= 3.27, libstdc++ >= 6, libX11 >= 1.6, libXtst >= 1.2, libappindicator + +%description +All-in-one voice and text chat for gamers that’s free, secure, and works on both your desktop and phone. +It’s time to ditch Skype and TeamSpeak. + +%prep + +%build + +%install +mkdir -p "%{buildroot}%{install_dir}" +mkdir -p "%{buildroot}%{apps_dir}" +mv "%{downloaded_dir}"/* "%{buildroot}%{install_dir}" +cp "%{desktop_file}" "%{buildroot}%{apps_dir}" +chmod +x "%{buildroot}%{install_dir}"/*.so + +%files +/* + +