Beispiel #1
0
def first(config, updater_version):
    clear_the_screen()
    print("\n\n")
    image_show()
    print(
        f"\t\t\t{Bcolors.BOLD} Updater version: {str(updater_version)}{Bcolors.ENDC}"
    )
    sleep(1)
    updated_check(config)
Beispiel #2
0
def first(parser, config, updater_version):
    parser.read(f'/home/{config.user}/.ota_markers/ota_config.txt')
    clear_the_screen()
    print("\n\n")
    image_show()
    print("\t\t\t " + Bcolors.BOLD + "Updater version: " +
          str(updater_version) + Bcolors.ENDC)
    sleep(1)
    updated_check(config)
Beispiel #3
0
def first():
    clear_the_screen()
    print("\n\n\n")
    image_show()
    sleep(0.5)
Beispiel #4
0
def update():
    if not linux_testing:
        os.system("sudo systemctl stop rotorhazard >/dev/null 2>&1 &")
    internet_flag = internet_check(user)
    if not internet_flag:
        print("\nLooks like you don't have internet connection. Update canceled.")
        sleep(2)
    else:
        print("\nInternet connection - OK")
        sleep(2)
        clear_the_screen()
        if not os.path.exists(f"/home/{user}/RotorHazard"):
            print(f"""{Bcolors.BOLD}
    Looks like you don't have RotorHazard server software installed for now. \n\t\t
    If so please install your server software first or you won't be able to use the timer.{Bcolors.ENDC}""")
            print(f"""\n\n{Bcolors.GREEN} 
        'i' - Install the software - recommended{Bcolors.ENDC}\n 
        'u' - Force update procedure\n{Bcolors.YELLOW}
        'a' - Abort both  \n\n{Bcolors.ENDC}""")
            selection = input()
            if selection == 'i':
                conf_allowed = True
                installation()
            if selection == 'u':
                update()
            if selection == 'a':
                clear_the_screen()
                sys.exit()
            else:
                main()
        else:
            clear_the_screen()
            print(f"\n\t{Bcolors.BOLD}Updating existing installation - please wait...{Bcolors.ENDC} \n")
            os.system("sudo -H python -m pip install --upgrade pip")
            os.system("sudo -H pip install pillow ")
            os.system("sudo apt-get install libjpeg-dev ntp -y")
            os.system("sudo apt-get update && sudo apt-get upgrade -y")
            if not linux_testing:
                os.system("sudo apt dist-upgrade -y")
            os.system("sudo apt autoremove -y")
            if not os.path.exists(f"/home/{user}/.old_RotorHazard.old"):
                os.system(f"sudo mkdir /home/{user}/.old_RotorHazard.old")
            os.system(f"sudo cp -r /home/{user}/RotorHazard-* /home/{user}/.old_RotorHazard.old/ >/dev/null 2>&1")
            os.system(f"sudo rm -r /home/{user}/RotorHazard-master >/dev/null 2>&1")  # just in case of weird sys cfg
            os.system(f"sudo rm -r /home/{user}/temp.zip >/dev/null 2>&1")  # just in case of weird sys config
            if os.path.exists(f"/home/{user}/RotorHazard.old"):
                os.system(f"sudo cp -r /home/{user}/RotorHazard.old /home/{user}/.old_RotorHazard.old/")
                os.system(f"sudo rm -r /home/{user}/RotorHazard.old")
            os.system(f"sudo mv /home/{user}/RotorHazard /home/{user}/RotorHazard.old")
            os.chdir(f"/home/{user}")
            os.system(f"wget https://codeload.github.com/RotorHazard/RotorHazard/zip/{server_version} -O temp.zip")
            os.system("unzip temp.zip")
            os.system(f"mv /home/{user}/RotorHazard-{server_version} /home/{user}/RotorHazard")
            os.system("sudo rm temp.zip")
            os.system(f"sudo mkdir /home/{user}/backup_RH_data >/dev/null 2>&1")
            os.system(f"sudo chmod 777 -R /home/{user}/RotorHazard/src/server")
            os.system(f"sudo chmod 777 -R /home/{user}/RotorHazard.old")
            os.system(f"sudo chmod 777 -R /home/{user}/.old_RotorHazard.old")
            os.system(f"sudo chmod 777 -R /home/{user}/backup_RH_data")
            os.system(f"sudo chmod 777 -R /home/{user}/.ota_markers")
            os.system(f"cp /home/{user}/RotorHazard.old/src/server/config.json \
            /home/{user}/RotorHazard/src/server/ >/dev/null 2>&1 &")
            os.system(f"cp -r /home/{user}/RotorHazard.old/src/server/static/image \
            /home/{user}/backup_RH_data")
            os.system(f"cp -r /home/{user}/RotorHazard.old/src/server/static/image \
            /home/{user}/RotorHazard/src/server/static")
            os.system(f"cp /home/{user}/RotorHazard.old/src/server/config.json \
            /home/{user}/backup_RH_data >/dev/null 2>&1 &")
            os.system(f"cp /home/{user}/RotorHazard.old/src/server/database.db \
            /home/{user}/RotorHazard/src/server/ >/dev/null 2>&1 &")
            os.system(f"cp /home/{user}/RotorHazard.old/src/server/database.db \
            /home/{user}/backup_RH_data >/dev/null 2>&1 &")
            os.chdir(f"/home/{user}/RotorHazard/src/server")
            os.system("sudo -H pip install --upgrade --no-cache-dir -r requirements.txt")
            # todo pip3 or pip or what?
            print("""\n\n\t
                ##############################################
                #                                            #
                #{bold}{green} Update completed!     {endc}  #
                #                                            #
                ############################################## 
                        """.format(bold=Bcolors.BOLD_S, endc=Bcolors.ENDC_S, green=Bcolors.GREEN_S)
            end_update()


def main():
    global config_flag
    global serv_installed_flag
    global conf_allowed
    global config_soft
    global server_version_name  # todo too much globals
    clear_the_screen()
    server_checker()
    config_checker()
    sleep(0.1)
    welcome = """
        \n\n{red} {bold}
        AUTOMATIC UPDATE AND INSTALLATION OF ROTORHAZARD RACING TIMER SOFTWARE\n\t
            {endc}{bold}
        You can automatically install and update RotorHazard timing software. 
        Additional dependencies and libraries also will be installed or updated.
        Current database, configs and custom bitmaps will stay on their place.
        Source of the software is set to '{blue}{server_version}{endc}'{bold} version from the official 
        RotorHazard repository.
         
        Perform self-updating of this software, before updating server software.
        Also make sure that you are logged as user {blue}'{user}'{endc}{bold}. \n
        
        You can change those in configuration wizard in Main Menu.\n
        Server installed right now: {server} {bold}
        RotorHazard configuration state: {config_soft}\n\n\n
        """.format(bold=Bcolors.BOLD, underline=Bcolors.UNDERLINE, endc=Bcolors.ENDC, blue=Bcolors.BLUE,
                   yellow=Bcolors.YELLOW, red=Bcolors.RED, orange=Bcolors.ORANGE, server_version=server_version,
                   user=user, config_soft=config_soft, server=server_version_name, )
    print(welcome)
    if not config_flag and serv_installed_flag:
        print(f"{Bcolors.GREEN}\t\t'c' - Configure RotorHazard server\n{Bcolors.ENDC}")
    else:
        print("\t\t'c' - Reconfigure RotorHazard server\n")
    if not serv_installed_flag:
        print(f"\t{Bcolors.GREEN}'i' - Install software from skratch{endc}")
    else:
        print("""\t\t'i' - Install software from skratch""")
    print("""
                'u' - Update existing installation\n {yellow}    
                'e' - Exit to Main Menu{endc}\n
            """.format(yellow=Bcolors.YELLOW, endc=Bcolors.ENDC))
    selection = input()
    if selection == 'c':
        if serv_installed_flag:
            os.system(". ./open_scripts.sh; rh_configuration_start")
        else:
            print("\n\t\tPlease install server software first")
            sleep(1.5)
    if selection == 'i':
        if parser.getint('added_functions', 'installation_done'):
            clear_the_screen()
            already_installed_prompt = """
            {bold}
    Looks like you already have RotorHazard server installed
    (or at least that your system was once configured).{endc}\n
    If that's the case please use {underline} update mode {endc} - 'u'
    or force installation {underline} without {endc} sys. config. - 'i'.
            
            {green} 
        'u' - Select update mode - recommended {endc}\n 
        'i' - Force installation without sys. config.\n
        'c' - Force installation and sys. config.\n {yellow}
        'a' - Abort both  \n {endc}""").format(bold=Bcolors.BOLD, endc=Bcolors.ENDC, underline=Bcolors.UNDERLINE,
                                                yellow=Bcolors.YELLOW)
            print(already_installed_prompt)
            selection = input()
            if selection == 'u':
                update()
            if selection == 'i':
                conf_allowed = False
                installation()
            if selection == 'c':
                confirm_valid_options = ['y', 'yes', 'n', 'no', 'abort', 'a']
                while True:
                    confirm = input("\n\t\tAre you sure? [yes/abort]\t").strip()
                    if confirm in confirm_valid_options:
                        break
                    else:
                        print("\ntoo big fingers :( wrong command. try again! :)")
                if confirm == 'y' or confirm == 'yes':
                    conf_allowed = True
                    installation()
                if confirm in ['n', 'no', 'abort', 'a']:
                    pass
            if selection == 'a':
                clear_the_screen()
                image_show()
                sleep(0.5)
                sys.exit()
            else:
                main()
        else:
Beispiel #5
0
                    else:
                        print("\ntoo big fingers :( wrong command. try again! :)")
                if confirm == 'y' or confirm == 'yes':
                    conf_allowed = True
                    installation()
                if confirm in ['n', 'no', 'abort', 'a']:
                    pass
            if selection == 'a':
                clear_the_screen()
                image_show()
                sleep(0.5)
                sys.exit()
            else:
                main()
        else:
            conf_allowed = True
            installation()
    if selection == 'u':
        update()
    if selection == 'e':
        clear_the_screen()
        os.chdir(f"/home/{user}/RH-ota")
        image_show()
        sleep(0.3)
        sys.exit()
    else:
        main()


main()
Beispiel #6
0
def main_window(serv_installed_flag, server_version_name, conf_flag):
    sleep(0.1)
    welcome_text = """
        \n\n{red} {bold}
        AUTOMATIC UPDATE AND INSTALLATION OF ROTORHAZARD RACING TIMER SOFTWARE
            {endc}{bold}
        You can automatically install and update RotorHazard timing software. 
        Additional dependencies and libraries also will be installed or updated.
        Current database, configs and custom bitmaps will stay on their place.
        Source of the software is set to {underline}{blue}{server_version}{endc}{bold} version from the official 
        RotorHazard repository.
         
        Perform self-updating of this software, before updating server software.
        Also make sure that you are logged as user {underline}{blue}{user}{endc}{bold}.
        
        You can change those in configuration wizard in Main Menu.
        
        Server installed right now: {server} {bold}
        RotorHazard configuration state: {config_soft}\n\n
        """.format(bold=Bcolors.BOLD,
                   underline=Bcolors.UNDERLINE,
                   endc=Bcolors.ENDC,
                   blue=Bcolors.BLUE,
                   yellow=Bcolors.YELLOW,
                   red=Bcolors.RED,
                   orange=Bcolors.ORANGE,
                   server_version=server_version,
                   user=user,
                   config_soft=conf_flag,
                   server=server_version_name)
    print(welcome_text)
    if not conf_flag and serv_installed_flag:
        print(
            f"{Bcolors.GREEN}\t\t'c' - Configure RotorHazard server\n{Bcolors.ENDC}"
        )
    else:
        print("\t\t'c' - Reconfigure RotorHazard server\n")
    if not serv_installed_flag:
        print(
            f"\t\t{Bcolors.GREEN}'i' - Install software from scratch{Bcolors.ENDC}"
        )
    else:
        print("""\t\t'i' - Install software from scratch""")
    print("""
                'u' - Update existing installation\n {yellow}    
                'e' - Exit to Main Menu{endc}\n
            """.format(yellow=Bcolors.YELLOW, endc=Bcolors.ENDC))
    selection = input()
    if selection == 'c':
        if serv_installed_flag:
            conf_ota()
        else:
            print("\n\t\tPlease install server software first")
            sleep(1.5)
    if selection == 'i':
        if config[installation_done]:
            clear_the_screen()
            already_installed_prompt = """
            {bold}
    Looks like you already have RotorHazard server installed
    (or at least that your system was once configured).{endc}
    
    If that's the case please use {underline} update mode {endc} - 'u'
    or force installation {underline} without {endc} sys. config. - 'i'.
            
            {green} 
        'u' - Select update mode - recommended {endc}\n 
        'i' - Force installation without sys. config.\n
        'c' - Force installation and sys. config.\n {yellow}
        'a' - Abort both  \n {endc}""".format(bold=Bcolors.BOLD,
                                              endc=Bcolors.ENDC,
                                              underline=Bcolors.UNDERLINE,
                                              yellow=Bcolors.YELLOW,
                                              green=Bcolors.GREEN)
            print(already_installed_prompt)
            selection = input()
            if selection == 'u':
                update()
            if selection == 'i':
                conf_allowed = False
                installation()
            if selection == 'c':
                confirm_valid_options = ['y', 'yes', 'n', 'no', 'abort', 'a']
                while True:
                    confirm = input(
                        "\n\t\tAre you sure? [yes/abort]\t").strip()
                    if confirm in confirm_valid_options:
                        break
                    else:
                        print(
                            "\ntoo big fingers :( wrong command. try again! :)"
                        )
                if confirm == 'y' or confirm == 'yes':
                    conf_allowed = True
                    installation()
                if confirm in ['n', 'no', 'abort', 'a']:
                    pass
            if selection == 'a':
                clear_the_screen()
                image_show()
                sleep(0.5)
                sys.exit()
            else:
                main()
        else:
            conf_allowed = True
            installation()
    if selection == 'u':
        update()
    if selection == 'e':
        clear_the_screen()
        os.chdir(f"/home/{user}/RH-ota")
        image_show()
        sleep(0.3)
        sys.exit()
    else:
        main()