From 3be7c31aa549ec55feb977ac213862d5bea4229b Mon Sep 17 00:00:00 2001 From: Tristan Ancelet Date: Tue, 5 Nov 2024 09:21:10 -0600 Subject: [PATCH] Fixed a few issues and added --update-desktop flag --- install-discord-linux.rb | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/install-discord-linux.rb b/install-discord-linux.rb index af68349..68ef8dc 100755 --- a/install-discord-linux.rb +++ b/install-discord-linux.rb @@ -31,6 +31,8 @@ class Dir end end + alias to_s path + ## For backwards compat def chdir(dir = nil, &block) if dir.nil? @@ -70,18 +72,18 @@ $CONFIG[:discord_version_file] = $CONFIG[:discord_path] / 'resources' / 'build_i $CONFIG[:action] = 'install' $CONFIG[:keep_installer] = false $CONFIG[:debug] = false -DISCORD_DESKTOP_CONTENTS=</Discord Icon=discord Type=Application Categories=Network;InstantMessaging; -Path=#{$CONFIG[:discord_path]} -EOF +Path=<%= $CONFIG[:discord_path] %> +ERB # END: Variables @@ -116,6 +118,10 @@ OptionParser.new do |parser| end end + parser.on('--update-desktop', "Update desktop file"){ + $CONFIG[:action] = 'update-desktop' + } + parser.separator "" parser.separator " General Flags" parser.separator "------------------------------------------------------------------------" @@ -219,7 +225,7 @@ def update_desktop_file if File.exist?($CONFIG[:desktop_path]) puts "update_desktop_file: Desktop file exists, checking if it matches template" File.open($CONFIG[:desktop_path], 'r') do |file| - if file.read() == DISCORD_DESKTOP_CONTENTS + if file.read() == DISCORD_DESKTOP_TEMPLATE.result(binding) puts "update_desktop_file: Desktop file matches template. Not updating" file_needs_updating = false end @@ -229,7 +235,7 @@ def update_desktop_file if file_needs_updating File.open($CONFIG[:desktop_path], 'w') do |file| puts "update_desktop_file: Desktop File was written" - file.write(DISCORD_DESKTOP_CONTENTS) + file.write(DISCORD_DESKTOP_TEMPLATE.result(binding)) end puts "update_desktop_file: Triggering desktop to install new desktop entry and refresh entries" @@ -271,6 +277,7 @@ def make_backup file_count = files[:files].count files[:files].each_with_index { |file, i| puts "make_backup : files : Backing up #{file} (#{i+1}/#{file_count})" if $CONFIG[:debug] +EOF 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) { |io| @@ -331,6 +338,9 @@ case $CONFIG[:action] when 'backup' make_backup + when 'update-desktop' + update_desktop_file + end # END: Work