Project

General

Profile

Download (4.58 KB) Statistics
| Branch: | Tag: | Revision:
#!/usr/bin/env ruby

require 'optparse'
require 'fileutils'

options = {}
optparse = OptionParser.new do |opts|
opts.banner = """
This script is used to remove all Katello related packages and services.
This should only be used if you are sure you are wanting to completly remove Katello from this machine and lose all of your settings and synced content.\n
"""

opts.on('-y', '--assume-yes', 'Remove without confirmation') do
options[:unattended] = true
end
opts.parse!
end

CONFIG_FILES = [
'/etc/pulp',
'/etc/opt/rh/rh-mongodb34/mongod.conf',
'/etc/candlepin',
'/etc/katello',
'/etc/httpd',
'/etc/foreman',
'/etc/tomcat',
'/etc/foreman-installer',
'/etc/foreman-proxy',
'/etc/pki/katello-certs-tools',
'/etc/sudoers.d/foreman-proxy',
'/etc/hammer',
'/etc/tomcat',
'/etc/squid',
'/etc/puppetlabs',
'/etc/qpid',
'/etc/qpid-dispatch',
'/etc/sysconfig/foreman.rpmsave'
]

LOG_FILES = [
'/var/log/katello',
'/var/log/pulp',
'/var/log/candlepin',
'/var/log/httpd',
'/var/log/mongodb',
'/var/log/foreman',
'/var/log/foreman-proxy',
'/var/log/foreman-installer',
'/var/log/tomcat',
'/var/log/squid',
'/var/log/capsule-certs-generate*'
]

RPMS = [
'puppetlabs-release',
'foreman-release',
'foreman-client',
'foreman-proxy',
'candlepin',
'katello',
'^pulp',
'^python-pulp',
'^pulp-',
'mongo',
'postgre',
'^mod_',
'^rubygem',
'^tfm',
'^foreman',
'^qpid',
'^python-crane',
'^python-celery',
'^python-gofer',
'^python-qpid',
'^python-kombu',
'^python-webpy',
'^python-nectar',
'^python-saslwrapper',
'^python-amqp',
'^python-billiard',
'^python-semantic_version',
'^python-requests',
'^python-isodate',
'$HOSTNAME',
'saslwrapper',
'ruby',
'rubygems',
'httpd',
'puppet',
'tomcat',
'squid'
]

CERT_FILES = [
'/etc/pki/pulp',
'/etc/pki/content/*',
'/etc/pki/katello',
'/root/ssl-build',
'/etc/pki/tls/certs/katello-node.crt',
'/etc/pki/tls/private/katello-node.key',
'/etc/pki/tls/certs/pulp_consumers_ca.crt',
'/etc/pki/tls/certs/pulp_ssl_cert.crt',
'/var/www/html/pub/katello-ca*.rpm',
'/etc/pki/ca-trust/source/anchors/katello_server-host-cert.crt'
]

CONTENT = [
'/usr/share/foreman-proxy',
'/usr/share/foreman-installer-katello',
'/var/www/html/pub/katello-server-ca.crt',
'/usr/share/foreman',
'/var/lib/candlepin',
'/usr/share/katello',
'/var/lib/puppet',
'/opt/puppetlabs/puppet',
'/var/lib/pgsql',
'/var/lib/mongodb',
'/var/lib/katello',
'/var/lib/pulp',
'/var/lib/foreman',
'/usr/share/pulp',
'/var/lib/tomcat',
'/var/lib/qpidd',
'/usr/share/candlepin',
'/usr/share/tomcat',
'/usr/share/katello-installer-base',
'/usr/share/qpid',
'/usr/share/qpid-tools',
'/var/cache/',
'/opt/theforeman',
'/var/www/html/pub/katello-rhsm-consumer',
'/var/tmp/foreman-proxy'
]

CONTENT.map! do |dir|
if File.readlines('/proc/mounts').any? { |line| line.split(' ')[1] =~ /#{dir}$/ }
dir + '/*'
else
dir
end
end

def remove
puts 'Stopping services'
`katello-service stop`

puts 'Removing RPMs'
packages = []
RPMS.each do |rpm|
rpmpackages = `rpm -qa | grep "#{rpm}"`
packages += rpmpackages.lines.map(&:chomp)
end
`yum erase -y #{packages.join(' ')} > /dev/null 2>&1`

puts 'Cleaning up configuration files'
FileUtils.rm_rf CONFIG_FILES

puts 'Cleaning up log files'
# logs
FileUtils.rm_rf LOG_FILES

puts 'Cleaning up certs'
# pulp cert stuff
FileUtils.rm_rf CERT_FILES

puts 'Cleaning up content'
# content
FileUtils.rm_rf CONTENT

puts 'Finished'
end

def confirmed?
puts "\nARE YOU SURE?: This script permanently deletes data and configurations."
puts "\nRead the source at /usr/sbin/katello-remove for a list of what is removed. Type [remove] to continue "
gets.chomp == 'remove'
end

def check?
puts "\nWARNING: This script will erase many packages and config files."
puts "Important packages such as the following will be removed:\n"
puts ' * httpd (apache)'
puts ' * mongodb'
puts ' * tomcat'
puts ' * puppet'
puts ' * ruby'
puts ' * rubygems'
puts " * All Katello and Foreman Packages\n"
puts 'Once these packages and configuration files are removed there is no going back.'
puts 'If you use this system for anything other than Katello and Foreman you probably'
puts "do not want to execute this script.\n"
puts "\nRead the source at /usr/sbin/katello-remove for a list of what is removed. Are you sure(Y/N) "

response = gets.chomp
/[Y]/i.match(response)
end

if options[:unattended] || (check? && confirmed?)
puts "\nStarting removal"
remove
else
puts "**cancelled**"
end
(8-8/15)