# frozen_string_literal: true

# uninstall
package_names = %w[Hardening PGP Leafcutter Metamigo]

package_names.each do |name|
  puts "Attempting to uninstall #{name} package..."
  package = Package.find_by(name: name)
  if package.blank?
    puts "Package #{name} is not installed."
  else
    puts "Uninstalling #{package.name} #{package.version}..."
    Package.uninstall(name: package.name, version: package.version)
    puts 'Uninstalled'
  end
rescue StandardError => e
  puts e.message
end

# install
packages = Dir.glob('/opt/zammad/contrib/link/addons/*')

packages.each do |package|
  puts "Installing #{package} package..."
  Package.install(file: package)
  puts 'Installed'
rescue StandardError => e
  puts e.message
end
