Author: ks156
Date: 2009-03-18 15:42:17 +0100 (Wed, 18 Mar 2009)
New Revision: 4136

Modified:
   
software_suite_v2/tuxware/installers/unix/branches/refactoring/software_updater/misc/installedFileDB.py
   
software_suite_v2/tuxware/installers/unix/branches/refactoring/software_updater/tux_software_updater.py
Log:
* Grant the privilege before updating.
  This will works only with sudo. For su users, they have to run manually the
  updater from a terminal


Modified: 
software_suite_v2/tuxware/installers/unix/branches/refactoring/software_updater/misc/installedFileDB.py
===================================================================
--- 
software_suite_v2/tuxware/installers/unix/branches/refactoring/software_updater/misc/installedFileDB.py
     2009-03-18 13:46:22 UTC (rev 4135)
+++ 
software_suite_v2/tuxware/installers/unix/branches/refactoring/software_updater/misc/installedFileDB.py
     2009-03-18 14:42:17 UTC (rev 4136)
@@ -79,17 +79,17 @@
     
     return toInstall, toRemove                       
 
-def writeDb(data, path):
+def writeDb(data, path, GRANT):
     if not os.path.isdir(path):
-        os.system("mkdir -p %s"%path)
-    f = open("%s/software.db1"%path, "w")
+        os.system("%s mkdir -p %s"%(GRANT, path))
+    f = open("/tmp/software.db1", "w")
     for entry in data:
         s="%s|%s|%s|%s|%s|%s\n"%(entry['md5Tag'], entry['name'],\
                 entry['destination'], entry['source'], \
                 entry['command'], entry['fileSize'])
         f.write(s)
     f.close()
-    os.system("mv %s/software.db1 %s/software.db"%(path, path))
+    os.system("%s mv /tmp/software.db1 %s/software.db"%(GRANT, path))
 
 
 def __isRightArchitecture(item, ARCH):

Modified: 
software_suite_v2/tuxware/installers/unix/branches/refactoring/software_updater/tux_software_updater.py
===================================================================
--- 
software_suite_v2/tuxware/installers/unix/branches/refactoring/software_updater/tux_software_updater.py
     2009-03-18 13:46:22 UTC (rev 4135)
+++ 
software_suite_v2/tuxware/installers/unix/branches/refactoring/software_updater/tux_software_updater.py
     2009-03-18 14:42:17 UTC (rev 4136)
@@ -10,6 +10,7 @@
 import sys
 import os
 
+GRANT = ""
 ARCH = None
 PREFIX = None
 MIRROR = ""
@@ -61,6 +62,18 @@
         toRemove = []
     return toInstall, toRemove
 
+def __grantPrivilege():
+    global GRANT
+    if os.geteuid() != 0:
+        if os.path.isfile("/usr/bin/sudo") and os.system("sudo -v") == 0:
+            GRANT = "sudo "
+        else:
+            print ""
+            print "Privileges cannot be granted"
+            print "Please run this script as root from a terminal"
+            print "  Open a terminal, and type : tux_updater"
+            sys.exit(2)
+
 def __isSomethingToUpdate(toInstall):
     """__isSomethingToUpdate
     Check if a new file has to be updated.
@@ -104,7 +117,7 @@
     """
     # Kill the services
     for service in processToKillList:
-        os.system("%s"%service)
+        os.system("%s %s"%(GRANT,service))
 
     pb = progressBar()
     pb.init(len(toInstall), 'Download', '%')
@@ -118,9 +131,9 @@
                 dest = MIRROR + dest
                 path, filename = os.path.split(dest)
                 if not os.path.isdir(path):
-                    os.system("mkdir -p %s"%path)
+                    os.system("%s mkdir -p %s"%(GRANT, path))
                 URLDownloadToFile(item['source'], dest)
-                os.system("chmod 755 %s"%dest)
+                os.system("%s chmod 755 %s"%(GRANT, dest))
             # Install a meta-package
             elif item['command'] == "INST":
                 os.system("mkdir -p /tmp/tuxdroid_upd")
@@ -134,13 +147,13 @@
                 cmd = "tar -xf /tmp/tuxdroid_upd/%s -C /tmp/tuxdroid_upd/ && " 
\
                         % filename
                 cmd = cmd + "cd /tmp/tuxdroid_upd/%s && 
"%filename.split("-")[0]
-                cmd = cmd + "/bin/bash install.sh %s %s %s && " \
-                        % (MIRROR + dest, MIRROR + PREFIX, dest)
+                cmd = cmd + "%s /bin/bash install.sh %s %s %s && " \
+                        % (GRANT, MIRROR + dest, MIRROR + PREFIX, dest)
                         # Mirror destination, Mirror prefix, Target destination
-                cmd = cmd + "rm -rf /tmp/tuxdroid_upd/"
+                cmd = cmd + "%s rm -rf /tmp/tuxdroid_upd/"%GRANT
                 os.system(cmd)
     print ''
-    writeDb(data, MIRROR + "/etc/tuxdroid/")
+    writeDb(data, MIRROR + "/etc/tuxdroid/", GRANT)
 
     # Uninstall the ununsed stuff
     for item in toRemove:
@@ -249,6 +262,7 @@
     toInstall, toRemove = __retrieveRules(data)
     
     if  __isSomethingToUpdate(toInstall):
+        __grantPrivilege()
         __updateSystem(data, toInstall, toRemove, processToKillList,
                 processToRelaunchList)
 


------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to