Created
May 8, 2014 13:53
-
-
Save salekseev/9d904e72bcb3b9440128 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
Script_Info = { | |
'base repo location' => 'cobbler/ks_mirror/OL6.5-x86_64', | |
'base repo title' => 'OL6.5', | |
'updates repo location' => 'LocalRepo/ol-6.5-updates', | |
'updates repo title' => 'OL6.5-updates', | |
'repo file dir' => '/etc/yum.repos.d', | |
'new version string' => 'Oracle Linux Server release 6.4', | |
'old repo files' => ['OEL6.4.repo','OEL6.4-lb.repo'], | |
} | |
def delete_old_repos | |
Script_Info['old repo files'].each do |repo_file| | |
next unless File.exist?("/etc/yum.repos.d/#{repo_file}") | |
File.delete("/etc/yum.repos.d/#{repo_file}") | |
end | |
end #delete_old_repos | |
def get_cobbler_host | |
return File.open("/etc/yum.repos.d/#{Script_Info['old repo files'][0]}", "rb").read.match(/^baseurl\=http:\/\/(.*).athenahealth.com/)[1].to_s | |
end #get_cobbler_host | |
def write_base_repo_file | |
repo_file = File.open("#{Script_Info['repo file dir']}/#{Script_Info['base repo title']}.repo", 'w+') | |
repo_file.chmod(0644) | |
repo_file.write( "[#{Script_Info['base repo title']}] | |
name=Local #{Script_Info['base repo title']} | |
baseurl=http://#{get_cobbler_host}.athenahealth.com/#{Script_Info['base repo location']}/Server | |
enabled=1 | |
gpgcheck=1 | |
metadata_expire=1m | |
priority=1 | |
[#{Script_Info['base repo title']}-UEK3] | |
name=Local #{Script_Info['base repo title']} UEK3 | |
baseurl=http://#{get_cobbler_host}.athenahealth.com/LocalRepo/UEK/UEK3 | |
enabled=1 | |
gpgcheck=1 | |
metadata_expire=1m | |
priority=1 | |
") | |
repo_file.close | |
end #write_net_repo_file | |
def write_updates_repo_file | |
repo_file = File.open("#{Script_Info['repo file dir']}/#{Script_Info['updates repo title']}.repo", 'w+') | |
repo_file.chmod(0644) | |
repo_file.write( "[#{Script_Info['updates repo title']}] | |
name=Local #{Script_Info['updates repo title']} | |
baseurl=http://#{get_cobbler_host}.athenahealth.com/#{Script_Info['updates repo location']} | |
enabled=1 | |
gpgcheck=1 | |
metadata_expire=1m | |
priority=1 | |
") | |
repo_file.close | |
end #write_net_repo_file | |
############## Main ################### | |
raise "You must be root to run me!" unless Process.uid == 0 | |
raise "This script is only meant for upgrading from #{Script_Info['new version string']}" unless open('/etc/oracle-release') { |file| file.gets.match(/^#{Script_Info['new version string']}$/) } | |
write_base_repo_file | |
write_updates_repo_file | |
system('yum upgrade -y') | |
delete_old_repos |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment