Merge pull request #405 from spreedated/master

Siteinstaller v0.11
This commit is contained in:
deltax 2017-02-12 11:18:48 +01:00 committed by GitHub
commit 4f6f4bdc9a
3 changed files with 182 additions and 56 deletions

29
locale/de_DE.py Normal file
View File

@ -0,0 +1,29 @@
# -*- coding: cp852 -*-
#de_DE Locale
class language():
VERSION='Version'
CREATING_BACKUP='Erstelle Sicherung'
NO_PERM='Keine Rechte'
COPYING_FILES='Kopiervorgang'
COULD_NOT_COPY='Konnte Dateien nicht kopieren'
DONE='Fertig'
REWRITING_FLUXION_BASH='Schreibe fluxion bash neu'
RECONFIGURE_FLUXION_BASH='Rekonfiguriere fluxion bash'
INTERNAL_FAILURE='Interner Fehler'
ERROR='Fehler'
FATAL_ERROR='FATAL ERROR'
TRYING_TO_RESTORE_BACKUP='Versuche Sicherung wiederherzustellen'
BACKUP_RESTORED='Sicherung wiederhergestellt'
SETTING_MODES='Setze modi'
CONTINUE='weiter'
VERIFYING_INTEG='Überprüfe integrität'
DELETING_BACKUP='Lösche Sicherungsdatei'
SUCCESS='Erfolgreich in fluxion integriert'
BEGIN_INSTALL='Installation beginnen'
COULD_NOT_OPEN_FLUX='Konnte fluxion nicht ”ffnen, bitte Berechtigung <20>berpr<70>fen. Beenden...'
NO_FLUXION_FOUND='fluxion nicht gefunden.\nBitte den installer INNERHALB des fluxion Ordners ausf<73>hren. Beenden...'
CORRUPTED_FLUX='Besch„digtes fluxion. Beenden...'
DOUBLE_INSTALL='Es scheint bereits eine Site mit dem Namen zu geben'
CONTINUE_ANYWAY='Trotzdem installieren?'
NOTHING_CHANGED='Nichts ver„ndert. Beenden...'

29
locale/en_EN.py Normal file
View File

@ -0,0 +1,29 @@
# -*- coding: cp852 -*-
#en_EN Locale
class language():
VERSION='Version'
CREATING_BACKUP='Creating backup'
NO_PERM='No Permission'
COPYING_FILES='Copying files'
COULD_NOT_COPY='Could not copy files'
DONE='Done'
REWRITING_FLUXION_BASH='Rewriting fluxion bash'
RECONFIGURE_FLUXION_BASH='Reconfiguring fluxion bash'
INTERNAL_FAILURE='Internal failure'
ERROR='Error'
FATAL_ERROR='FATAL ERROR'
TRYING_TO_RESTORE_BACKUP='Trying to restore from backup'
BACKUP_RESTORED='Backup restored'
SETTING_MODES='Setting modes'
CONTINUE='continue'
VERIFYING_INTEG='Verifying integrity of fluxion'
DELETING_BACKUP='Deleting backup'
SUCCESS='Successfully installed "to your fluxion'
BEGIN_INSTALL='Begin installation'
COULD_NOT_OPEN_FLUX='Could not open fluxion, check permissions. Exiting...'
NO_FLUXION_FOUND='No fluxion installation found.\nPlease use this installer INSIDE the fluxion folder. Exiting...'
CORRUPTED_FLUX='Corrupted fluxion installation. Exiting...'
DOUBLE_INSTALL='Seems like there is already a site with the name'
CONTINUE_ANYWAY='Do you want to continue anyway?'
NOTHING_CHANGED='Nothing changed, your choice. Exiting...'

View File

@ -1,22 +1,40 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: cp852 -*-
import sys import sys
import getopt import getopt
import os import os
import subprocess import subprocess
sys.path.insert(0, './locale')
# ###################
# ## OPTIONS ########
# ###################
site_name = '' site_name = ''
site_language = '' site_language = ''
installed_sites = 0 installed_sites = 0
flux_cont = '' flux_cont = ''
#flux_comp_versions = ['0.24']
flinstall_version = '0.11'
# ###################
class color:
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARKCYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
END = '\033[0m'
def main(argv): def main(argv):
global site_name, site_language global site_name, site_language
if os.geteuid() != 0: if os.geteuid() != 0:
exit("You need to have root privileges to run this script.\nPlease try again, this time using 'sudo'. Exiting....") exit('You need to have root privileges to run this script.\nPlease try again, this time using \'sudo\'. Exiting....')
sys.exit() sys.exit()
usage = '>>>\tUsage:\n' +'\t\tsiteinstaller.pyc -f <filename>' +'\n\t\tsiteinstaller.pyc --file <file>\n\n>>>\tOnly *.tar.gz compressed files!' usage = '>>>\tUsage:\n' +'\t\tsiteinstaller.py -f <filename>' +'\n\t\tsiteinstaller.py --file <file>\n\n>>>\tOnly *.tar.gz compressed files!'
try: try:
opts, args = getopt.getopt(sys.argv[1:], 'f:h', ['file=', 'help']) opts, args = getopt.getopt(sys.argv[1:], 'f:h', ['file=', 'help'])
if(len(opts) <= 0): if(len(opts) <= 0):
@ -32,7 +50,7 @@ def main(argv):
sys.exit(2) sys.exit(2)
elif opt in ('-f', '--file'): elif opt in ('-f', '--file'):
if not('.tar.gz' in arg): if not('.tar.gz' in arg):
print('ONLY *.tar.gz files supported. Sorry bro') print('ONLY *.tar.gz files supported.')
sys.exit() sys.exit()
if(os.path.isfile(arg) == False): if(os.path.isfile(arg) == False):
print('Your file does not exist, maybe a typo?') print('Your file does not exist, maybe a typo?')
@ -46,6 +64,28 @@ def main(argv):
if __name__ == "__main__": if __name__ == "__main__":
main(sys.argv[1:]) main(sys.argv[1:])
# Language Selector
print('\033[1;91m [~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~]')
print(' [ ]')
print(' [ FluxIon - Site Installer v' + flinstall_version + ' ]')
print('\033[94m [ ]')
print(' [~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~]')
print('\033[39m')
print(' # Select your language:')
print('')
print('[1] English')
print('[2] German')
print('')
lang = raw_input(' [#]:')
if(lang == '1'):
from en_EN import language
elif(lang == '2'):
from de_DE import language
else:
from en_EN import language
# ###############
def check_fluxion(): def check_fluxion():
global installed_sites, flux_cont global installed_sites, flux_cont
try: try:
@ -53,10 +93,10 @@ def check_fluxion():
flux_cont = fl.read() flux_cont = fl.read()
fl.close() fl.close()
except: except:
print('Could not open fluxion, check permissions. Exiting...') print(language.COULD_NOT_OPEN_FLUX)
sys.exit() sys.exit()
if(flux_cont <= 100): if(flux_cont <= 100):
print('No fluxion installation found.\nPlease use this installer INSIDE the fluxion folder. Exiting...') print(language.NO_FLUXION_FOUND)
sys.exit() sys.exit()
flv = '' flv = ''
flr = '' flr = ''
@ -67,20 +107,32 @@ def check_fluxion():
flr = flux_cont[flux_cont.find('revision=')+9:] flr = flux_cont[flux_cont.find('revision=')+9:]
flr = flr[:flr.find('\n')] flr = flr[:flr.find('\n')]
else: else:
print('Corrupted fluxion installation. Exiting...') print(language.CORRUPTED_FLUX)
sys.exit() sys.exit()
installed_sites = int(flux_cont.count('elif [ "$fluxass" =')) # Version check
#vchk = False
#for version in flux_comp_versions:
# if(version == flv):
# vchk = True
#if(vchk == False):
# print('Your fluxion version '+color.BOLD + flv + color.END + '. \nSupported versions are - ' + ' - '.join(reversed(flux_comp_versions)))
# sys.exit()
# ###############
installed_sites = int(flux_cont.count('elif [ "$webconf" ='))
fls = str(installed_sites + 1) fls = str(installed_sites + 1)
# Check on double installation! # Check on double installation!
fld = flux_cont[flux_cont.find('$DUMP_PATH/data/index.htm'):] fld = flux_cont[flux_cont.find('$DUMP_PATH/data/index.htm'):]
if(site_name in fld): if(site_name in fld):
usdc = raw_input('Seems like there is already a site with the name "' + site_name + '" Do you want to continue anyway? [Y\\n]') usdc = raw_input(language.DOUBLE_INSTALL + ' "' + site_name + '" ' + language.CONTINUE_ANYWAY + ' [Y\\n]')
if(len(usdc) <= 0) or (usdc == 'y') or (usdc == 'yes'): if(len(usdc) <= 0) or (usdc == 'y') or (usdc == 'yes'):
pass pass
else: else:
sys.exit() sys.exit()
# ###############
return flv + '#' + flr + '#' + fls return flv + '#' + flr + '#' + fls
def welcome(): def welcome():
@ -98,33 +150,42 @@ def welcome():
if(i+1 == wsl) and (i+1 <= wsl): if(i+1 == wsl) and (i+1 <= wsl):
whitespacel += '#' whitespacel += '#'
print(' # ############################################') print('\033[1;91m [~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~]')
print(' # FluxIon - Site Installer v0.10 #') print(' [ ]')
print(' # ############################################') print(' [ FluxIon - Site Installer v'+ flinstall_version + ' ]')
print('') print('\033[94m [ ]')
print(' # ############## Fluxion found! ##############') print(' [~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~]')
print(' # Version: '+ flc[0] +' #') print('\033[39m')
print(' # Revision: '+ flc[1] +' #') print(' # ############## FluxIon found! ##############')
print(' # Installed Sites: '+ flc[2] +' #') print(' # \033[39mVersion: '+ flc[0] +' #')
print(' # \033[39mRevision: '+ flc[1] +' #')
print(' # \033[39mInstalled Sites: '+ flc[2] +' #')
print(' # ############################################') print(' # ############################################')
print('') print('')
print(' # ############################################') print(' # ############################################')
print(' # SiteName to install: ' + site_name + whitespacen) print(' # \033[39mSiteName to install: ' + site_name + whitespacen)
print(' # Language flag: ' + site_language + whitespacel) print(' # \033[39mLanguage flag: ' + site_language + whitespacel)
print(' # ############################################') print(' # ############################################')
print('') print('')
print(' # ########### Everything correct? ############') print(' # ########### Everything correct? ############')
print('') print('')
usc = raw_input(' # Begin installation? [Y\\n]').lower() usc = raw_input(' # ' + language.BEGIN_INSTALL + '? [Y\\n]').lower()
if(len(usc) <= 0) or (usc == 'y') or (usc == 'yes'): if(len(usc) <= 0) or (usc == 'y') or (usc == 'yes'):
pass pass
else: else:
print('\n\t # Nothing changed, your choice. Exiting...') print('\n\t # ' + language.NOTHING_CHANGED)
sys.exit() sys.exit()
# ########################################################################################
# ########################################################################################
# ########################################################################################
# ########################################################################################
# ########################################################################################
# ########################################################################################
# ########################################################################################
welcome() welcome()
# ###### First INSERT
def insert_at_secondlast_pos1(): def insert_at_secondlast_pos1():
global flux_cont, site_name, site_language global flux_cont, site_name, site_language
whitespaces = '' whitespaces = ''
@ -136,104 +197,111 @@ def insert_at_secondlast_pos1():
before = flux_cont[:int(flux_cont.rfind(search_string))] before = flux_cont[:int(flux_cont.rfind(search_string))]
after = '\t\t\t' + flux_cont[int(flux_cont.rfind(search_string)):] after = '\t\t\t' + flux_cont[int(flux_cont.rfind(search_string)):]
flux_cont = before + insert_site + after flux_cont = before + insert_site + after
# ##########################################
# ###### Second INSERT
def insert_at_secondlast_pos2(): def insert_at_secondlast_pos2():
global installed_sites, flux_cont, site_name global installed_sites, flux_cont, site_name
site_number = str(installed_sites +1) site_number = str(installed_sites +1)
insert_site = 'elif [ "$fluxass" = "'+ site_number +'" ]; then\n\t\t\t\t' + site_name + '\n\t\t\t\tbreak\n\n\t\t\t' insert_site = 'elif [ "$webconf" = "'+ site_number +'" ]; then\n\t\t\t\t' + site_name + '\n\t\t\t\tbreak\n\n\t\t\t'
flux_cont = flux_cont[:int(flux_cont.rfind('elif [ "$fluxass" ='))] + insert_site + flux_cont[int(flux_cont.rfind('elif [ "$fluxass" =')):] flux_cont = flux_cont[:int(flux_cont.rfind('elif [ "$webconf" ='))] + insert_site + flux_cont[int(flux_cont.rfind('elif [ "$webconf" =')):]
def last_option_correct_number2(): def last_option_correct_number2():
global installed_sites, flux_cont global installed_sites, flux_cont
acc = int(flux_cont.rfind('elif [ "$fluxass" =')) acc = int(flux_cont.rfind('elif [ "$webconf" ='))
acc0 = int(flux_cont[acc:].find('" = "')+5) acc0 = int(flux_cont[acc:].find('" = "')+5)
before = flux_cont[:acc+acc0] before = flux_cont[:acc+acc0]
after = flux_cont[acc+acc0+2:] after = flux_cont[acc+acc0+2:]
flux_cont = before + str(installed_sites+2) + after flux_cont = before + str(installed_sites+2) + after
# ##########################################
# ###### Third INSERT
def insert_at_last_pos3(): def insert_at_last_pos3():
global flux_cont, site_name global flux_cont, site_name
insert_site = '\n\nfunction ' + site_name + ' {\n\tmkdir $DUMP_PATH/data &>$flux_output_device\n\tcp $WORK_DIR/Sites/' + site_name + '/* $DUMP_PATH/data\n\t}' insert_site = '\n\nfunction ' + site_name + ' {\n\tmkdir $DUMP_PATH/data &>$flux_output_device\n\tcp $WORK_DIR/Sites/' + site_name + '/* $DUMP_PATH/data\n\t}'
before = flux_cont[:int(flux_cont.rfind('}'))+1] before = flux_cont[:int(flux_cont.rfind('}'))+1]
after = flux_cont[int(flux_cont.rfind('}'))+1:] after = flux_cont[int(flux_cont.rfind('}'))+1:]
flux_cont = before + insert_site + after flux_cont = before + insert_site + after
# ##########################################
print('') print('')
print(' # Creating backup...') print(' # '+ language.CREATING_BACKUP +'...')
try: try:
subprocess.Popen(['cp','fluxion', 'bckp_fluxion']) subprocess.Popen(['cp','fluxion', 'bckp_fluxion'])
except: except:
print('No Permission') print(language.NO_PERM)
sys.exit() sys.exit()
print(' # Done!') print(' # ' + language.DONE + '!')
print('') print('')
print(' # Copying files...') print(' # ' + language.COPYING_FILES + '...')
try: try:
subprocess.Popen(['tar','xfz', site_name + '.tar.gz', '-C', 'Sites/']) subprocess.Popen(['tar','xfz', site_name + '.tar.gz', '-C', 'Sites/'])
except: except:
print('Could not copy files...soz') print(language.COULD_NOT_COPY + '...')
sys.exit() sys.exit()
print(' # Done!') print(' # ' + language.DONE + '!')
print('') print('')
print(' # Reconfiguring fluxion bash...') print(' # ' + language.RECONFIGURE_FLUXION_BASH + '...')
try: try:
insert_at_secondlast_pos1() insert_at_secondlast_pos1()
insert_at_secondlast_pos2() insert_at_secondlast_pos2()
last_option_correct_number2() last_option_correct_number2()
insert_at_last_pos3() insert_at_last_pos3()
except: except:
print('Internal failure... we fucked it up') print(language.INTERNAL_FAILURE + '...')
e = sys.exc_info()[0] e = sys.exc_info()[0]
print("Error: %s" % e ) print(language.ERROR + ": %s" % e )
sys.exit() sys.exit()
print(' # Done!') print(' # ' + language.DONE + '!')
print('') print('')
print(' Rewriting fluxion bash...') print(' # '+ language.REWRITING_FLUXION_BASH + '...')
try: try:
wflux = open('fluxion','w') wflux = open('fluxion','w')
wflux.write(flux_cont) wflux.write(flux_cont)
wflux.close() wflux.close()
except: except:
print('FATAL ERROR[501]...') print(language.FATAL_ERROR + '[501]...')
print('Trying to restore from backup') print(language.TRYING_TO_RESTORE_BACKUP)
try: try:
subprocess.Popen(['mv','bckp_fluxion', 'fluxion']) subprocess.Popen(['mv','bckp_fluxion', 'fluxion'])
print('FluxIon Backup restored...') print('FluxIon ' + language.BACKUP_RESTORED + '...')
except: except:
print('FATAL ERROR[502]... sorry bro something went wrong, fluxion may be broken now...') print(language.FATAL_ERROR + '[502]...')
sys.exit() sys.exit()
print(' # Done!') print(' # ' + language.DONE + '!')
print('') print('')
print(' # Setting modes...') print(' # ' + language.SETTING_MODES + '...')
try: try:
subprocess.Popen(['chmod','755', 'Sites/'+site_name]) subprocess.Popen(['chmod','755', 'Sites/' + site_name +'/'])
subprocess.Popen(['chmod','644', '-R', 'Sites/'+site_name]) subprocess.Popen(['chmod','644', '-R', 'Sites/' + site_name +'/'])
print(' # Done!') print(' # ' + DONE + '!')
except: except:
print('ERROR[506]... continue...') pass
#print('ERROR[506]... ' + language.CONTINUE + '...')
#print("Unexpected error:", sys.exc_info()[0])
print('') print('')
print(' # Verifying integrity of fluxion...') print(' # ' + language.VERIFYING_INTEG + '...')
try: try:
fluxit = open('fluxion','r') fluxit = open('fluxion','r')
integ_fluxion = fluxit.read() integ_fluxion = fluxit.read()
fluxit.close() fluxit.close()
if(len(integ_fluxion) == len(flux_cont)): if(len(integ_fluxion) == len(flux_cont)):
print(' # Done!') print(' # ' + language.DONE + '!')
print(' # Deleting backup...') print(' # ' + language.DELETING_BACKUP + '...')
subprocess.Popen(['rm','bckp_fluxion']) subprocess.Popen(['rm','bckp_fluxion'])
else: else:
print('FATAL ERROR[509]... your fluxion might be messed up') print(language.FATAL_ERROR + '[509]...')
sys.exit() sys.exit()
except: except:
print('FATAL ERROR[503]... sorry bro something went wrong, fluxion may be broken now...') print(language.FATAL_ERROR + '[503]...')
sys.exit() sys.exit()
print('\n # Finished, successfully installed "' + site_name + '" to your fluxion!') print('\n # ' + site_name + '" ' + language.SUCCESS + '!')