Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import os
- import sys
- tarfile = "installfile.tar.gz"
- install_contents = ["bin", "lib"]
- cleanup = ["*.o", "*.c", "*.h", "*.y", "*.l", "*.java", "adt", "libpm.a", "Makefile"]
- def PerformCommand(command, information="", mode=None):
- print information
- if mode:
- return os.popen(command + " > /dev/null", mode)
- else:
- return os.popen(command + " > /dev/null")
- def Build():
- stream = PerformCommand("uudecode -o " + tarfile, "Creating temporary packfile...", 'w')
- stream.write(source)
- stream.close()
- PerformCommand("tar -xzvf " + tarfile, "Decompressing...")
- PerformCommand("cp README bin/README", "...")
- def Install():
- if not os.path.exists("Makefile"):
- print "Build has not been completed yet. Please run --build before calling --install."
- sys.exit()
- path = raw_input("Type in the path to install the build into: ")
- if not os.path.exists(path):
- decision = ""
- while 1:
- decision = raw_input("Directory doesn't exist. Do you want to create it now? (Y/N):")
- if decision[0].lower() == "y":
- PerformCommand("mkdir " + path, "Creating directory '" + path +"' ...")
- break
- elif decision[0].lower() == "n":
- print "Installation was cancelled."
- sys.exit()
- else:
- print "Ensuring write permissions for folder '" + path + "'..."
- os.chmod(path, 0777)
- PerformCommand("make", "Making build...")
- PerformCommand("cp -f README " + path + "/README", "...")
- for content in install_contents:
- PerformCommand("mv -f " + content + " " + path + "/" + content,
- "Moving '" + content + "' into '" + path + "/" + content + "'...")
- decision = ""
- while 1:
- decision = raw_input("Do you want to add the library export to your ~/.bashrc? (Y/N):")
- if decision[0].lower() == "y":
- stream = open(os.path.expanduser("~") + "/.bashrc", 'a')
- stream.write("# Added by dialogc install script\n")
- stream.write("export LD_LIBRARY_PATH=" + os.path.abspath(path + "/lib/") + ":${LD_LIBRARY_PATH}\n")
- stream.close()
- print "Added to the ~/.bashrc file."
- print "You'll need to restart your terminal after installation is done."
- break
- elif decision[0].lower() == "n":
- print "Omitted the ~/.bashrc insertion."
- print "Be sure to run this command manually, then:"
- print "\texport LD_LIBRARY_PATH=" + os.path.abspath(path + "/lib/") + ":${LD_LIBRARY_PATH}"
- break
- print "Performing cleanup..."
- for item in cleanup:
- PerformCommand("rm -rf " + item, "Removing " + item + "...")
- def main():
- if len(sys.argv) >= 2:
- if sys.argv[1] == "--wip":
- print "WIP FILE! Installing..."
- print ""
- Build()
- print ""
- print "Done!"
- elif sys.argv[1] == "--install":
- print "Installing..."
- print ""
- Install()
- print ""
- print "Done!"
- elif sys.argv[1] == "--build":
- print "Building..."
- print ""
- Build()
- PerformCommand("rm " + tarfile, "Removing extractable...")
- print ""
- print "Done!"
- elif sys.argv[1] == "--help":
- print sys.argv[0]
- print ""
- print " Commandline arguments:"
- print " --install"
- print " a release mode installation"
- print " (only binaries and essential resources)"
- print " --build"
- print " compiles the code but leaves the source behind"
- else:
- print "Invalid command. Type " + sys.argv[0] + " --help for additional information"
- else:
- print "Performing full install..."
- print ""
- Build()
- PerformCommand("rm " + tarfile, "Removing extractable...")
- Install()
- print ""
- print "Done!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement