Compare commits

..

No commits in common. "7b61dd700a1efc1452d3a5daeebf490ee70fc63b" and "89cbb8a4d471a96eea7c4e521ec7daea22787db7" have entirely different histories.

View File

@ -3,14 +3,12 @@
# BEGIN: Includes & Requires # BEGIN: Includes & Requires
require 'erb' require 'erb'
require 'time'
require 'json' require 'json'
require 'net/http' require 'net/http'
require 'English' require 'English'
require 'rubygems/package' require 'rubygems/package'
require 'fileutils' require 'fileutils'
require 'optparse' require 'optparse'
require 'zlib'
# END: Includes & Requires # END: Includes & Requires
@ -48,7 +46,6 @@ DOWNLOAD_URL='https://discord.com/api/download/stable?platform=linux&format=tar.
$CONFIG = Hash.new $CONFIG = Hash.new
$CONFIG[:icon_dir] = Dir.new(Dir.home) / '.local' / 'share' / 'icons' $CONFIG[:icon_dir] = Dir.new(Dir.home) / '.local' / 'share' / 'icons'
File.mkdir($CONFIG[:icon_dir]) if not File.exist?($CONFIG[:icon_dir]) File.mkdir($CONFIG[:icon_dir]) if not File.exist?($CONFIG[:icon_dir])
$CONFIG[:discord_config_path] = Dir.new(Dir.home) / '.config' / 'discord'
$CONFIG[:local_application_install_dir] = Dir.new(Dir.home) / '.local' / 'share' / 'applications' $CONFIG[:local_application_install_dir] = Dir.new(Dir.home) / '.local' / 'share' / 'applications'
File.mkdir($CONFIG[:local_application_install_dir]) if not File.exist?($CONFIG[:local_application_install_dir]) File.mkdir($CONFIG[:local_application_install_dir]) if not File.exist?($CONFIG[:local_application_install_dir])
$CONFIG[:desktop_path] = Dir.new(Dir.home) / '.local' / 'share' / 'applications' / 'discord.desktop' $CONFIG[:desktop_path] = Dir.new(Dir.home) / '.local' / 'share' / 'applications' / 'discord.desktop'
@ -91,15 +88,6 @@ OptionParser.new do |parser|
$CONFIG[:action] = 'install' $CONFIG[:action] = 'install'
end end
parser.on('-u', '--uninstall', "Uninstall Discord (not-implemented)") do
$CONFIG[:action] = 'uninstall'
end
parser.on('-b', '--backup', "Backup Discord Installation (not-implemented)") do
$CONFIG[:action] = 'backup'
$CONFIG[:backup_filename] = 'discord-backup-' + Time.now.strftime('%Y-%m-%d') + '.tar.gz'
end
parser.separator "" parser.separator ""
parser.separator " General Flags" parser.separator " General Flags"
parser.separator "------------------------------------------------------------------------" parser.separator "------------------------------------------------------------------------"
@ -139,7 +127,6 @@ def get_local_version
end end
end end
def download_installer(version) def download_installer(version)
uri = URI(URL_DOWNLOAD_BASE.gsub('{VERSION}', version.to_s)) uri = URI(URL_DOWNLOAD_BASE.gsub('{VERSION}', version.to_s))
puts "download_installer: Downloading The discord #{version.to_s} tar.gz" puts "download_installer: Downloading The discord #{version.to_s} tar.gz"
@ -161,13 +148,12 @@ def do_install(version)
File.open(installer_file, 'rb') do |file| File.open(installer_file, 'rb') do |file|
Gem::Package.new("").extract_tar_gz(file, $CONFIG[:install_dir]) Gem::Package.new("").extract_tar_gz(file, $CONFIG[:install_dir])
end end
if not $CONFIG[:keep_installer]
puts "do_install: Removing new installer (#{installer_file})"
File.unlink(installer_file)
end
end end
if not $CONFIG[:keep_installer]
puts "do_install: Removing new installer (#{installer_file})"
File.unlink(installer_file)
end
end end
def update_desktop_file def update_desktop_file
@ -194,60 +180,6 @@ def update_desktop_file
end end
end end
def make_backup
files = {
files: Array.new,
dirs: Array.new,
symlinks: Array.new
}
Dir.glob("#{$CONFIG[:discord_config_path].path}/**/**/**/**").each{ |item|
if File.file?(item)
files[:files] << item
elsif File.symlink?(item)
files[:symlinks] << item
elsif File.directory?(item)
files[:dirs] << item
end
}
Dir.glob("#{$CONFIG[:discord_path].path}/**/**/**/**").each {|item|
if File.file?(item)
files[:files] << item
elsif File.symlink?(item)
files[:symlinks] << item
elsif File.directory?(item)
files[:dirs] << item
end
}
Dir.chdir(Dir.home) do
File.open($CONFIG[:backup_filename], "wb") do |backup_file|
Zlib::GzipWriter.wrap(backup_file) do |gzip|
Gem::Package::TarWriter.new(gzip) do |tar|
files[:files].each do |file|
File.open(file, 'rb') { |file_to_archive|
contents = file_to_archive.read()
tar.add_file_simple(file_to_archive.path.sub("#{Dir.home}/",''), file_to_archive.stat.mode, contents.length) do |io|
io.write(contents)
end
}
end
files[:dirs].each do |dir|
tar.mkdir(dir.sub("#{Dir.home}/",""), File.stat(dir).mode)
end
files[:symlinks].each {|symlink|
tar.add_symlink(symlink.sub("#{Dir.home}/",""), File.readlink(symlink), File.lstat(symlink).mode)
}
end
end
end
end
end
# END: Helper Functions # END: Helper Functions
@ -275,8 +207,6 @@ case $CONFIG[:action]
puts " Remote Version: #{remote_version.to_s}" puts " Remote Version: #{remote_version.to_s}"
puts " Local Version: #{local_version.to_s}" puts " Local Version: #{local_version.to_s}"
puts " Needs Updating: #{(remote_version > local_version) ? "Yes" : "No"}" puts " Needs Updating: #{(remote_version > local_version) ? "Yes" : "No"}"
when 'backup'
make_backup
end end
# END: Work # END: Work