Advertisement
clockworkpc

Generate BASH and Python Script Generators

Sep 1st, 2016
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.13 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import os
  4. import datetime
  5.  
  6. # Create time-stamp string for folder and file names
  7. now = datetime.datetime.now()
  8. now_string = str(now.strftime("%Y-%m-%d, %A, %H:%M:%S"))
  9. now_string_with_text = "The current details for today are... " + now_string
  10.  
  11. #%Y = Year
  12. #%m = Month
  13. #%d = Day
  14. #%A = Day of the week
  15. #%H = Hour
  16. #%M = Minute
  17. #%S = Second
  18.  
  19. print now_string
  20. print now_string_with_text
  21.  
  22. #os.system("touch demo_file" + now_string)
  23.  
  24. bin_path_name = os.getenv("HOME")+"/bin/"
  25. usr_bin_path_name = "/usr/bin/"
  26.  
  27. print bin_path_name
  28.  
  29. if not os.path.isdir == bin_path_name:
  30.     os.mkdir(bin_path_name)
  31. else:
  32.     print bin_path_name
  33.  
  34. #BASH Generator
  35.  
  36. bashGen = '''#!/bin/bash
  37. #cpcbash.sh
  38.  
  39. # Released under a GPLv3 Licence by Clockwork PC ''' + now_string + '''
  40. # http//www.clockworkpc.com.au
  41.  
  42. # You are entitled to the following four freedoms:
  43. # Freedom 0: To run this program for any purpose
  44. # Freedom 1: To study how this program works and change it to make it do what you wish
  45. # Freedom 2: To redistribute copies so you can help your neighbour
  46. # Freedom 3: To distribute copies of your modified version to others
  47.  
  48. echo "What do you want to call your BASH script?"
  49. read RESPONSE
  50.  
  51. #Create the script
  52. echo "#!/bin/bash" | tee ~/bin/$RESPONSE.sh
  53. echo "#Filename:$RESPONSE.sh" | tee -a ~/bin/$RESPONSE.sh
  54. echo "#Released under a GPLv3 Licence by Clockwork PC" | tee -a ~/bin/$RESPONSE.sh
  55.  
  56. #Create removal script
  57. echo "#!/bin/bash" | tee ~/bin/remove_$RESPONSE.sh
  58. echo "#Filename:remove_$RESPONSE.sh" | tee -a ~/bin/remove_$RESPONSE.sh
  59. echo "#Released under a GPLv3 Licence by Clockwork PC" | tee -a ~/bin/remove_$RESPONSE.sh
  60. echo "sudo rm -v -rf ~/bin/$RESPONSE.SH /usr/bin/$RESPONSE.sh ~/bin/remove_$RESPONSE.sh /usr/bin/remove_$RESPONSE.sh" | tee -a ~/bin/remove_$RESPONSE.sh
  61.  
  62. sudo chmod +x ~/bin/$RESPONSE.sh
  63. sudo chmod +x ~/bin/remove_$RESPONSE.sh
  64.  
  65. sudo ln -s ~/bin/$RESPONSE.sh /usr/bin/$RESPONSE.sh
  66. sudo chmod +x /usr/bin/$RESPONSE.sh
  67.  
  68. nano ~/bin/$RESPONSE.sh
  69.  
  70. '''
  71.  
  72. #Python script generator
  73.  
  74. pythonGen = '''#!/usr/bin/python
  75.  
  76. # Released under a GPLv3 Licence by Clockwork PC ''' + now_string + '''
  77. # www.clockworkpc.com.au
  78.  
  79. # You are entitled to the following four freedoms:
  80. # Freedom 0: To run this program for any purpose
  81. # Freedom 1: To study how this program works and change it to make it do what you wish
  82. # Freedom 2: To redistribute copies so you can help your neighbour
  83. # Freedom 3: To distribute copies of your modified version to others
  84.  
  85. import os
  86.  
  87. filename=raw_input("What do you want to call your Python file? ")
  88.  
  89. folder = os.getenv("HOME")+"/bin/"
  90. pythonfile = folder + filename + ".py"
  91. rm_pythonfile = "remove_" + filename + ".sh"
  92. print folder
  93. print pythonfile
  94.  
  95. os.system('echo "#!/usr/bin/python" | tee ' + pythonfile)
  96.  
  97. f = open(pythonfile, "a")
  98.  
  99. f.write("#"+pythonfile+"""
  100.  
  101. # Released under a GPLv3 Licence by Clockwork PC
  102. # www.clockworkpc.com.au
  103.  
  104. # You are entitled to the following four freedoms:
  105. # Freedom 0: To run this program for any purpose
  106. # Freedom 1: To study how this program works and change it to make it do what you wish
  107. # Freedom 2: To redistribute copies so you can help your neighbour
  108. # Freedom 3: To distribute copies of your modified version to others
  109. """)
  110. f.close()
  111.  
  112. os.system('echo "#!/usr/bin/python" | tee ' + rm_pythonfile)
  113.  
  114. f = open(rm_pythonfile, "a")
  115.  
  116. f.write("#"+rm_pythonfile+"""
  117.  
  118. sudo rm -vrf """ + pythonfile + " " + "/usr/bin/" + filename + ".py" + " " + "~/bin/" + rm_pythonfile + " " + "/usr/bin/" + rm_pythonfile
  119. """)
  120. f.close()
  121.  
  122. os.system("chmod -v +x " + pythonfile)
  123. os.system("sudo ln -sv " + pythonfile + " /" + "usr/bin/" + filename + ".py")
  124. os.system("chmod -v +x " + "~/bin/" + rm_pythonfile)
  125. os.system("sudo ln -sv " + "~/bin/" + rm_pythonfile + " /" + "usr/bin/" + rm_pythonfile)
  126. os.system("nano " + pythonfile)
  127. os.system("xcowsay 'Your Python script is ready!'")
  128. '''
  129.  
  130. bashGenName = "cpcbash.sh"
  131. bashGenFile = bin_path_name + bashGenName
  132. bashGenUsr = usr_bin_path_name+bashGenName
  133.  
  134. pythonGenName = "cpcpython.py"
  135. pythonGenFile = bin_path_name + pythonGenName
  136. pythonGenUsr = usr_bin_path_name+pythonGenName
  137.  
  138. rmScriptsName = "rmscripts.sh"
  139. rmScriptsFile = bin_path_name + rmScriptsName
  140. rmScriptsUsr = usr_bin_path_name+rmScriptsName
  141.  
  142. #Remove scripts and symlinks
  143.  
  144. rmScripts = "#!/bin/bash"+"""
  145. """+"sudo rm -v"+ " " + bashGenFile + " " + bashGenUsr + " " + pythonGenFile + " " + pythonGenUsr + " " + rmScriptsFile + " " + rmScriptsUsr
  146.  
  147. print bashGenFile
  148. print pythonGenFile
  149. print rmScriptsFile
  150.  
  151. os.system("touch " + bashGenFile)
  152. f = open(bashGenFile, "a")
  153. f.write(bashGen)
  154. f.close()
  155. os.system("sudo ln -s " + bashGenFile + " " + bashGenUsr)
  156.  
  157. os.system("touch " + pythonGenFile)
  158. g = open(pythonGenFile, "a")
  159. g.write(pythonGen)
  160. g.close()
  161. os.system("sudo ln -s " + pythonGenFile + " " + pythonGenUsr)
  162.  
  163. os.system("touch " + rmScriptsFile)
  164. h = open(rmScriptsFile, "a")
  165. h.write(rmScripts)
  166. h.close()
  167. os.system ("sudo ln -s " + rmScriptsFile + " " + rmScriptsUsr)
  168.  
  169. os.system("chmod +x -v " + bashGenFile)
  170. os.system("chmod +x -v " + pythonGenFile)
  171. #os.system("chmod u+x -v " + rmScripts)
  172.  
  173. #os.system("xcowsay Your scripts are ready")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement