Pre change
This commit is contained in:
parent
89cbb8a4d4
commit
01a838c7f2
@ -3,12 +3,14 @@
|
||||
# BEGIN: Includes & Requires
|
||||
|
||||
require 'erb'
|
||||
require 'time'
|
||||
require 'json'
|
||||
require 'net/http'
|
||||
require 'English'
|
||||
require 'rubygems/package'
|
||||
require 'fileutils'
|
||||
require 'optparse'
|
||||
require 'zlib'
|
||||
|
||||
# END: Includes & Requires
|
||||
|
||||
@ -46,6 +48,7 @@ DOWNLOAD_URL='https://discord.com/api/download/stable?platform=linux&format=tar.
|
||||
$CONFIG = Hash.new
|
||||
$CONFIG[:icon_dir] = Dir.new(Dir.home) / '.local' / 'share' / 'icons'
|
||||
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'
|
||||
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'
|
||||
@ -88,6 +91,15 @@ OptionParser.new do |parser|
|
||||
$CONFIG[:action] = 'install'
|
||||
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 " General Flags"
|
||||
parser.separator "------------------------------------------------------------------------"
|
||||
@ -127,6 +139,7 @@ def get_local_version
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def download_installer(version)
|
||||
uri = URI(URL_DOWNLOAD_BASE.gsub('{VERSION}', version.to_s))
|
||||
puts "download_installer: Downloading The discord #{version.to_s} tar.gz"
|
||||
@ -180,6 +193,40 @@ def update_desktop_file
|
||||
end
|
||||
end
|
||||
|
||||
def make_backup
|
||||
files = Array.new
|
||||
Dir.glob("#{$CONFIG[:discord_config_path]}/**").each{|item|
|
||||
if File.file?(item) or File.directory?(item)
|
||||
files << File.new(item)
|
||||
end
|
||||
}
|
||||
Dir.glob("#{$CONFIG[:discord_path]}/**").each {|item|
|
||||
if File.file?(item) or File.directory?(item)
|
||||
files << File.new(item)
|
||||
end
|
||||
}
|
||||
|
||||
Dir.chdir(Dir.home) do
|
||||
File.open($CONFIG[:backup_filename], "wb") do |file|
|
||||
Zlib::GzipWriter.wrap(file) do |gzip|
|
||||
Gem::Package::TarWriter.new(gzip) do |tar|
|
||||
files.each do |file|
|
||||
if File.file?(file)
|
||||
content = file.read()
|
||||
tar.add_file_simple(file.path.sub("#{Dir.home}/",''), file.stat.mode, content.length) do |io|
|
||||
io.write(content)
|
||||
end
|
||||
elsif File.directory?(file)
|
||||
tar.mkdir(file.path.sub("#{Dir.home}/",""), file.stat.mode)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# END: Helper Functions
|
||||
|
||||
|
||||
@ -207,6 +254,8 @@ case $CONFIG[:action]
|
||||
puts " Remote Version: #{remote_version.to_s}"
|
||||
puts " Local Version: #{local_version.to_s}"
|
||||
puts " Needs Updating: #{(remote_version > local_version) ? "Yes" : "No"}"
|
||||
when 'backup'
|
||||
make_backup
|
||||
end
|
||||
|
||||
# END: Work
|
||||
|
Loading…
Reference in New Issue
Block a user