Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.50 KB | None | 0 0
  1. #!/usr/bin/python
  2. import os
  3. import sys
  4.  
  5. tarfile = "installfile.tar.gz"
  6. install_contents = ["bin", "lib"]
  7. cleanup = ["*.o", "*.c", "*.h", "*.y", "*.l", "*.java", "adt", "libpm.a", "Makefile"]
  8.  
  9. def PerformCommand(command, information="", mode=None):
  10.     print information
  11.     if mode:
  12.         return os.popen(command + " > /dev/null", mode)
  13.     else:
  14.         return os.popen(command + " > /dev/null")
  15.  
  16. def Build():
  17.     stream = PerformCommand("uudecode -o " + tarfile, "Creating temporary packfile...", 'w')
  18.     stream.write(source)
  19.     stream.close()
  20.  
  21.     PerformCommand("tar -xzvf " + tarfile, "Decompressing...")
  22.     PerformCommand("cp README bin/README", "...")
  23.  
  24. def Install():
  25.     if not os.path.exists("Makefile"):
  26.         print "Build has not been completed yet. Please run --build before calling --install."
  27.         sys.exit()
  28.  
  29.     path = raw_input("Type in the path to install the build into: ")
  30.     if not os.path.exists(path):
  31.         decision = ""
  32.         while 1:
  33.             decision = raw_input("Directory doesn't exist. Do you want to create it now? (Y/N):")
  34.             if decision[0].lower() == "y":
  35.                 PerformCommand("mkdir " + path, "Creating directory '" + path +"' ...")
  36.                 break
  37.             elif decision[0].lower() == "n":
  38.                 print "Installation was cancelled."
  39.                 sys.exit()
  40.     else:
  41.         print "Ensuring write permissions for folder '" + path + "'..."
  42.         os.chmod(path, 0777)
  43.  
  44.     PerformCommand("make", "Making build...")
  45.     PerformCommand("cp -f README " + path + "/README", "...")
  46.     for content in install_contents:
  47.         PerformCommand("mv -f " + content + " " + path + "/" + content,
  48.                 "Moving '" + content + "' into '" + path + "/" + content + "'...")
  49.  
  50.     decision = ""
  51.     while 1:
  52.         decision = raw_input("Do you want to add the library export to your ~/.bashrc? (Y/N):")
  53.         if decision[0].lower() == "y":
  54.             stream = open(os.path.expanduser("~") + "/.bashrc", 'a')
  55.             stream.write("# Added by dialogc install script\n")
  56.             stream.write("export LD_LIBRARY_PATH=" + os.path.abspath(path + "/lib/") + ":${LD_LIBRARY_PATH}\n")
  57.             stream.close()
  58.             print "Added to the ~/.bashrc file."
  59.             print "You'll need to restart your terminal after installation is done."
  60.             break
  61.         elif decision[0].lower() == "n":
  62.             print "Omitted the ~/.bashrc insertion."
  63.             print "Be sure to run this command manually, then:"
  64.             print "\texport LD_LIBRARY_PATH=" + os.path.abspath(path + "/lib/") + ":${LD_LIBRARY_PATH}"
  65.             break
  66.     print "Performing cleanup..."
  67.     for item in cleanup:
  68.         PerformCommand("rm -rf " + item, "Removing " + item + "...")
  69.  
  70. def main():
  71.     if len(sys.argv) >= 2:
  72.         if sys.argv[1] == "--wip":
  73.             print "WIP FILE! Installing..."
  74.             print ""
  75.             Build()
  76.             print ""
  77.             print "Done!"      
  78.         elif sys.argv[1] == "--install":
  79.             print "Installing..."
  80.             print ""
  81.             Install()
  82.             print ""
  83.             print "Done!"
  84.         elif sys.argv[1] == "--build":
  85.             print "Building..."
  86.             print ""
  87.             Build()
  88.             PerformCommand("rm " + tarfile, "Removing extractable...")
  89.             print ""
  90.             print "Done!"
  91.         elif sys.argv[1] == "--help":
  92.             print sys.argv[0]
  93.             print ""
  94.             print "  Commandline arguments:"
  95.             print "       --install"
  96.             print "            a release mode installation"
  97.             print "            (only binaries and essential resources)"
  98.             print "       --build"
  99.             print "            compiles the code but leaves the source behind"
  100.         else:
  101.             print "Invalid command. Type " + sys.argv[0] + " --help for additional information"
  102.     else:
  103.         print "Performing full install..."
  104.         print ""
  105.         Build()
  106.         PerformCommand("rm " + tarfile, "Removing extractable...")
  107.         Install()
  108.         print ""
  109.         print "Done!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement