cc-4227: updated install scripts for upgrade
This commit is contained in:
parent
abeef43a5b
commit
6c1e822b6a
|
@ -2,6 +2,7 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
from configobj import ConfigObj
|
from configobj import ConfigObj
|
||||||
|
import upgrade2dot2
|
||||||
|
|
||||||
def get_current_script_dir():
|
def get_current_script_dir():
|
||||||
return os.path.dirname(os.path.realpath(__file__))
|
return os.path.dirname(os.path.realpath(__file__))
|
||||||
|
@ -14,12 +15,14 @@ def copy_dir(src_dir, dest_dir):
|
||||||
shutil.copytree(src_dir, dest_dir)
|
shutil.copytree(src_dir, dest_dir)
|
||||||
|
|
||||||
PATH_INI_FILE = '/etc/airtime/api_client.cfg'
|
PATH_INI_FILE = '/etc/airtime/api_client.cfg'
|
||||||
|
|
||||||
current_script_dir = get_current_script_dir()
|
current_script_dir = get_current_script_dir()
|
||||||
|
|
||||||
if not os.path.exists(PATH_INI_FILE):
|
if not os.path.exists(PATH_INI_FILE):
|
||||||
shutil.copy('%s/../api_client.cfg'%current_script_dir, PATH_INI_FILE)
|
shutil.copy('%s/../api_client.cfg'%current_script_dir, PATH_INI_FILE)
|
||||||
|
|
||||||
|
upgrade2dot2.upgrade('%s/../api_client.cfg'% current_script_dir, PATH_INI_FILE)
|
||||||
|
|
||||||
"""load config file"""
|
"""load config file"""
|
||||||
try:
|
try:
|
||||||
config = ConfigObj("%s/../api_client.cfg" % current_script_dir)
|
config = ConfigObj("%s/../api_client.cfg" % current_script_dir)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
import upgrade2dot2
|
||||||
from configobj import ConfigObj
|
from configobj import ConfigObj
|
||||||
|
|
||||||
if os.geteuid() != 0:
|
if os.geteuid() != 0:
|
||||||
|
@ -62,6 +63,9 @@ try:
|
||||||
mm2_source = os.path.realpath(os.path.join(current_script_dir,
|
mm2_source = os.path.realpath(os.path.join(current_script_dir,
|
||||||
"../../media-monitor2"))
|
"../../media-monitor2"))
|
||||||
copy_dir(mm2_source, os.path.join( config["bin_dir"], "mm2" ))
|
copy_dir(mm2_source, os.path.join( config["bin_dir"], "mm2" ))
|
||||||
|
# upgrade mm2 config
|
||||||
|
upgrade2dot2.upgrade(('%s/../media-monitor.cfg'%current_script_dir),
|
||||||
|
PATH_INI_FILE)
|
||||||
|
|
||||||
#copy init.d script
|
#copy init.d script
|
||||||
shutil.copy(config["bin_dir"]+"/airtime-media-monitor-init-d", "/etc/init.d/airtime-media-monitor")
|
shutil.copy(config["bin_dir"]+"/airtime-media-monitor-init-d", "/etc/init.d/airtime-media-monitor")
|
||||||
|
|
|
@ -38,7 +38,7 @@ class TestUpgrade(unittest.TestCase):
|
||||||
self.assertTrue( os.path.exists(cf['source']['path']) )
|
self.assertTrue( os.path.exists(cf['source']['path']) )
|
||||||
self.assertTrue( os.path.exists(cf['dest']['path']) )
|
self.assertTrue( os.path.exists(cf['dest']['path']) )
|
||||||
# Finished preparing
|
# Finished preparing
|
||||||
upgrade2dot2.upgrade({ cf['source']['path'] : cf['dest']['path'] })
|
upgrade2dot2.upgrade(cf['source']['path'], cf['dest']['path'] )
|
||||||
c1, c2 = ConfigObj(cf['source']['path']), ConfigObj(cf['dest']['path'])
|
c1, c2 = ConfigObj(cf['source']['path']), ConfigObj(cf['dest']['path'])
|
||||||
self.assertEqual( c2['key2'], 'val2')
|
self.assertEqual( c2['key2'], 'val2')
|
||||||
self.assertEqual( c2['key4'], '10')
|
self.assertEqual( c2['key4'], '10')
|
||||||
|
|
|
@ -7,22 +7,21 @@ upgrades_config = {
|
||||||
'/etc/airtime/api_client.cfg' : '../api_clients/api_client.cfg',
|
'/etc/airtime/api_client.cfg' : '../api_clients/api_client.cfg',
|
||||||
}
|
}
|
||||||
|
|
||||||
def upgrade(upgrade_data):
|
def upgrade(source, destination):
|
||||||
"""
|
"""
|
||||||
Must be ran as sudo. will do upgrade of configuration files by filling in
|
Must be ran as sudo. will do upgrade of configuration files by filling in
|
||||||
missing values according to upgrade_data
|
missing values according to upgrade_data
|
||||||
"""
|
"""
|
||||||
for source, destination in upgrade_data.iteritems():
|
if not os.path.exists(source):
|
||||||
if not os.path.exists(source):
|
print("Cannot upgrade '%s'. Skipping this file" % source)
|
||||||
print("Cannot upgrade '%s'. Skipping this file" % source)
|
return
|
||||||
continue
|
try:
|
||||||
try:
|
cfg_source, cfg_dest = ConfigObj(source), ConfigObj(destination)
|
||||||
cfg_source, cfg_dest = ConfigObj(source), ConfigObj(destination)
|
for key, val in cfg_source.iteritems():
|
||||||
for key, val in cfg_source.iteritems():
|
if key not in cfg_dest: cfg_dest[key] = val
|
||||||
if key not in cfg_dest: cfg_dest[key] = val
|
cfg_dest.write()
|
||||||
cfg_dest.write()
|
except Exception:
|
||||||
except Exception:
|
print("Error upgrading")
|
||||||
print("Error upgrading")
|
print( traceback.format_exc() )
|
||||||
print( traceback.format_exc() )
|
|
||||||
|
|
||||||
if __name__ == "__main__": upgrade(upgrades_config)
|
if __name__ == "__main__": upgrade(upgrades_config)
|
||||||
|
|
Loading…
Reference in New Issue