Changeset 3346

Show
Ignore:
Timestamp:
01/11/10 10:39:11 (10 years ago)
Author:
imcheng
Message:

Removed the shell scripts for the installer for Nokia. Integrated the Nokia installer into seattle[un]installer.py

Location:
seattle/trunk/dist
Files:
2 removed
2 modified

Legend:

Unmodified
Added
Removed
  • seattle/trunk/dist/seattleinstaller.py

    r3327 r3346  
    3232import time 
    3333import getpass 
     34 
     35# Derek Cheng: This is for detecting if the user is root on the Nokia N800/900 
     36# tablet. 
     37import pwd 
     38# Derek Cheng: This is for changing the permission bits on the startup scripts 
     39# on the Nokia tablet. (i.e., stat.S_IXUSR gives owner permission to execute) 
     40import stat 
    3441 
    3542# Python should do this by default, but doesn't on Windows CE. 
     
    11841191 
    11851192 
     1193# Derek Cheng: added function for setting up the startup of Seattle on the  
     1194# Nokia tablet. This is to be called from setup_linux_or_mac() since the Nokia 
     1195# runs on a Linux-based OS. 
     1196def setup_nokia_startup(): 
     1197  """ 
     1198  <Purpose> 
     1199    Sets up seattle to run at startup on a Nokia tablet. It requires the user 
     1200    to be currently on root access (checked in main()). It creates a short 
     1201    shell script in /etc/init.d that will in turn run start_seattle.sh, and a 
     1202    symlink in /etc/rc2.d that will link to the short script in /etc/init.d. 
     1203    These two files will cause Seattle to run on startup. 
     1204 
     1205  <Arguments> 
     1206    None. 
     1207     
     1208  <Exceptions> 
     1209    AlreadyInstalledError if seattle has already been installed on the system. 
     1210 
     1211  <Side Effects> 
     1212    None. 
     1213 
     1214  <Returns> 
     1215    True if the files are created successfully, 
     1216    False otherwise. 
     1217  """ 
     1218   
     1219  # The name of the startup script. 
     1220  startup_script_name = "nokia_seattle_startup.sh" 
     1221  # The directory where the startup script will reside. 
     1222  startup_script_dir = "/etc/init.d/" 
     1223  # The full path to the startup script. 
     1224  startup_script_path = startup_script_dir + startup_script_name 
     1225 
     1226  # The name of the symlink that links to the startup script. 
     1227  symlink_name = "S99startseattle" 
     1228  # The directory where the symlink to the startup script will reside. 
     1229  symlink_dir = "/etc/rc2.d/" 
     1230  # The full path to the symlink. 
     1231  symlink_path = symlink_dir + symlink_name 
     1232 
     1233  # The username of the user. This is assumed to be 'user', since this is the 
     1234  # default name and it is highly unlikely that the name can be changed.  
     1235  username = "user" 
     1236   
     1237  # If the startup script or the symlink already exists prior to this  
     1238  # installation, an AlreadyInstalledError is raised. 
     1239  if os.path.exists(startup_script_path) or \ 
     1240        os.path.lexists(symlink_dir + symlink_name): 
     1241    _output("The files that are required for running Seattle on startup " \ 
     1242              + "already exists. If you would like a clean installation, " \ 
     1243              + "please run the uninstaller first to remove those files.") 
     1244    servicelogger.log("The startup files were not added to the /etc/ " \ 
     1245                        + "directories because they already existed prior to " \ 
     1246                        + "the installation.") 
     1247    raise AlreadyInstalledError()   
     1248   
     1249  # The contents of the startup script in its entirety. 
     1250  # This line indicates that it is a shell script. 
     1251  startup_script_content = "#! /bin/sh" + "\n" 
     1252  # This line runs start_seattle.sh as "user". 
     1253  startup_script_content += "su - " + username + " -c " \ 
     1254      + os.path.realpath(get_starter_file_name()) + "\n"  
     1255   
     1256  # Creates the startup script file. 
     1257  try: 
     1258    startup_script_handle = file(startup_script_path, 'w') 
     1259  except: 
     1260    _output("Cannot create startup script file. Make sure you have the " \ 
     1261              + "permission to do so.") 
     1262    servicelogger.log("Seattle was not configured to run on startup because " \ 
     1263                        + startup_script_path + " cannot be created.") 
     1264    return False 
     1265 
     1266  # Writes the startup script content to the startup script file. 
     1267  try: 
     1268    startup_script_handle.write(startup_script_content) 
     1269  except: 
     1270    _output("Cannot write to the startup script file. Make sure you have the " \ 
     1271              + "permission to do so.") 
     1272    servicelogger.log("Seattle was not configured to run on startup because " \ 
     1273                        + startup_script_path + " cannot be written to.") 
     1274    return False 
     1275  finally: 
     1276    startup_script_handle.close() 
     1277 
     1278  # Changes the permission bits of the startup script to executable by owner. 
     1279  try: 
     1280    os.chmod(startup_script_path, stat.S_IXUSR) 
     1281  except: 
     1282    _output("Cannot change the startup script permission to executable. Make " \ 
     1283              + "sure you have the permission to do so.") 
     1284    servicelogger.log("Seattle was not configured to run on startup because " \ 
     1285                        + "permissions of " +  startup_script_path + \ 
     1286                        " cannot be changed.") 
     1287    # This is an attempt to clean up by removing the script file if chmod fails. 
     1288    try: 
     1289      os.remove(startup_script_path) 
     1290    except: 
     1291      pass 
     1292    return False 
     1293 
     1294  # Creates the symlink to the startup script at symlink_dir. 
     1295  try: 
     1296    os.symlink(startup_script_path, symlink_path) 
     1297  except: 
     1298    _output("Cannot create symlink to the startup script. Make sure you have " \ 
     1299              + "the permission to do so.") 
     1300    servicelogger.log("Seattle was not configured to run on startup because " \ 
     1301                        + " the symlink " + symlink_path + " cannot be " \ 
     1302                        + "created.") 
     1303    # Attempt to clean up by removing the startup script. 
     1304    try: 
     1305      os.remove(startup_script_path) 
     1306    except: 
     1307      pass 
     1308    return False 
     1309 
     1310  _output("Seattle has been configured to run on startup.") 
     1311  servicelogger.log("Seattle has been configured to run on startup. Two " \ 
     1312                      + "files were created: " + startup_script_path + " and " \ 
     1313                      + symlink_path +".") 
     1314  return True 
     1315 
     1316 
     1317 
     1318 
    11861319def setup_linux_or_mac_startup(): 
    11871320  """ 
     
    12131346    raise UnsupportedOSError 
    12141347 
     1348  # Derek Cheng: check to see if Seattle is being installed on a Nokia tablet. 
     1349  if platform.node().startswith('Nokia-N'): 
     1350    return setup_nokia_startup() 
    12151351 
    12161352  _output("Attempting to add an entry to the crontab...") 
     
    18772013 
    18782014 
     2015  # Derek Cheng: if the user is running a Nokia N800 tablet, we require them 
     2016  # to be on root first in order to have files created in the /etc/init.d and 
     2017  # /etc/rc2.d directories.  
     2018  if platform.node().startswith('Nokia-N'): 
     2019    _output('Seattle is being installed on a Nokia N800/900 Internet Tablet.') 
     2020    # if the current user name is not 'root' 
     2021    if pwd.getpwuid(os.getuid())[0] != 'root': 
     2022      _output('Please run the installer as root. This can be done in by ' \ 
     2023                + 'installing/using the rootsh or openssh package.') 
     2024      return 
    18792025 
    18802026 
     
    19292075          # reasons why configuration to run at startup failed will have already 
    19302076          # be given to the user from the setup_linux_or_mac_startup() function. 
    1931           if platform.node().startswith('Nokia-N'): 
    1932             # if this is a Nokia, we will have a separate script that will  
    1933             # setup the startup. 
    1934             _output("It appears you're using a Nokia internet tablet. To " \ 
    1935                       + "make Seattle run on startup, please run " \ 
    1936                       + "nokia_seattle_startup.sh as root.") 
    1937           else: 
    1938             _output("Seattle failed to be configured to run automatically at " \ 
     2077          _output("Seattle failed to be configured to run automatically at " \ 
    19392078                    + "startup.") 
    19402079      else: 
  • seattle/trunk/dist/seattleuninstaller.py

    r3327 r3346  
    3030import getopt 
    3131import time 
    32 import platform # for detecting Nokia tablets 
     32# Derek Cheng: This is for detecting Nokia N800/900 tablets. 
     33import platform 
     34# Derek Cheng: This is for detecting if the user is root (for Nokia tablets) 
     35import pwd 
    3336 
    3437# Import seattle modules 
     
    332335 
    333336 
     337# Derek Cheng: Added a separate uninstaller for Nokia N800/900 Tablets. This  
     338# function is to be called from uninstall_Linux_or_Mac(). 
     339def uninstall_nokia(): 
     340  """ 
     341    <Purpose> 
     342    Remove the startup script and symlink to it in the /etc/init.d and  
     343    /etc/rc2.d directories, and kill all seattle processes by using  
     344    impose_seattlestopper_lock. This requires the user to be currently on root 
     345    access. 
     346 
     347  <Arguments> 
     348    None. 
     349 
     350  <Exceptions> 
     351    None. 
     352 
     353  <Side Effects> 
     354    Removes the startup script and the symlink to it, and stops seattle from  
     355    running. 
     356 
     357  <Returns> 
     358    True if succeeded in uninstalling, 
     359    False otherwise. 
     360  """ 
     361   
     362  # Check to see if the current user is root. 
     363  if pwd.getpwuid(os.getuid())[0] != 'root': 
     364    _output('Please run the uninstaller as root. This can be done by ' \ 
     365              + 'installing/using the rootsh or openssh package.') 
     366    return False 
     367   
     368  # Stop all instances of seattle from running. 
     369  impose_seattlestopper_lock.killall() 
     370 
     371  # The name of the startup script. 
     372  startup_script_name = "nokia_seattle_startup.sh" 
     373  # The directory where the startup script resides. 
     374  startup_script_dir = "/etc/init.d/" 
     375  # The full path to the startup script. 
     376  startup_script_path = startup_script_dir + startup_script_name 
     377 
     378  # The name of the symlink that links to the startup script. 
     379  symlink_name = "S99startseattle" 
     380  # The directory where the symlink to the startup script resides. 
     381  symlink_dir = "/etc/rc2.d/" 
     382  # The full path to the symlink. 
     383  symlink_path = symlink_dir + symlink_name 
     384 
     385  # Check if the startup script and the symlink exists. 
     386  if not os.path.exists(startup_script_path) and \ 
     387        not os.path.lexists(symlink_path): 
     388    _output("Neither the startup script nor the symlink exists.") 
     389    return True 
     390 
     391  # Remove the startup script. 
     392  try: 
     393    os.remove(startup_script_path) 
     394  except: 
     395    # The script does not exist for some reason (but the symlink exists) 
     396    pass 
     397   
     398  # Remove the symlink. 
     399  try: 
     400    os.remove(symlink_path) 
     401  except: 
     402    # The symlink does not exist for some reason (but the script existed) 
     403    pass 
     404 
     405  return True 
     406 
     407 
     408 
     409 
    334410def uninstall_Linux_and_Mac(): 
    335411  """ 
     
    355431  """ 
    356432 
    357   # Find out if it is running on a Nokia tablet, which does not have crontab 
    358   # installed. 
     433 
     434  # Derek Cheng: Find out if this is a Nokia N800/900 Tablet, and if so runs a  
     435  # separate uninstaller because there is no crontab on the tablets. 
    359436  if platform.node().startswith('Nokia-N'): 
    360       _output("It appears you're using a Nokia tablet. To completely " \ 
    361             + "uninstall Seattle, please run nokia_seattle_startup.sh " \ 
    362             + "with the -r flag as root.") 
    363       # Stop all instances of seattle from running before returning. 
    364       stop_all_seattle_processes.main() 
    365       return True 
     437    return uninstall_nokia() 
     438 
    366439 
    367440  # Find out if Seattle is installed (currently in the crontab), and remove if