diff --git a/src/update_all/constants.py b/src/update_all/constants.py index 3780cc0..5116817 100644 --- a/src/update_all/constants.py +++ b/src/update_all/constants.py @@ -128,5 +128,6 @@ class PathType(Enum): ARCADE_ORGANIZER_URL = "https://raw.githubusercontent.com/theypsilon/_arcade-organizer/master/_arcade-organizer.sh" DOWNLOADER_INI_STANDARD_PATH = "downloader.ini" DOWNLOADER_STORE_STANDARD_PATH = "Scripts/.config/downloader/downloader.json" +DOWNLOADER_LATEST_ZIP_PATH = "Scripts/.config/downloader/downloader_latest.zip" TEST_UNSTABLE_SPINNER_FIRMWARE_MD5 = "b76bc57d75afce8b1040bc4d225ea3aa" FILE_MiSTer_version = '/MiSTer.version' diff --git a/src/update_all/downloader_utils.py b/src/update_all/downloader_utils.py new file mode 100644 index 0000000..608a550 --- /dev/null +++ b/src/update_all/downloader_utils.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# Copyright (c) 2022-2024 José Manuel Barroso Galindo +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# You can download the latest version of this tool from: +# https://github.com/theypsilon/Update_All_MiSTer + + +from update_all.os_utils import OsUtils +from update_all.constants import DOWNLOADER_URL, DOWNLOADER_LATEST_ZIP_PATH +from update_all.file_system import FileSystem +from typing import Optional + + +def prepare_latest_downloader(os_utils: OsUtils, file_system: FileSystem) -> Optional[str]: + if file_system.is_file(DOWNLOADER_LATEST_ZIP_PATH): + temp_file = file_system.temp_file_by_id('downloader.sh') + file_system.copy(DOWNLOADER_LATEST_ZIP_PATH, temp_file.name) + return temp_file.name + else: + content = os_utils.download(DOWNLOADER_URL) + if content is None: + return None + + temp_file = file_system.temp_file_by_id('downloader.sh') + file_system.write_file_bytes(temp_file.name, content) + return temp_file.name diff --git a/src/update_all/ini_repository.py b/src/update_all/ini_repository.py index 9932b74..0903763 100644 --- a/src/update_all/ini_repository.py +++ b/src/update_all/ini_repository.py @@ -19,7 +19,7 @@ import io import json import re -from typing import Optional, Dict, List, Tuple, Any, Set +from typing import Optional, Dict, List, Tuple, Any from update_all.config import Config from update_all.constants import DOWNLOADER_INI_STANDARD_PATH, ARCADE_ORGANIZER_INI, FILE_downloader_temp_ini, DOWNLOADER_STORE_STANDARD_PATH diff --git a/src/update_all/settings_screen.py b/src/update_all/settings_screen.py index f9c9d02..d408927 100644 --- a/src/update_all/settings_screen.py +++ b/src/update_all/settings_screen.py @@ -25,6 +25,7 @@ TEST_UNSTABLE_SPINNER_FIRMWARE_MD5, DOWNLOADER_URL, FILE_MiSTer_ini, ARCADE_ORGANIZER_URL, \ ARCADE_ORGANIZER_INSTALLED_NAMES_TXT, STANDARD_UI_THEME, FILE_downloader_temp_ini, FILE_MiSTer_delme from update_all.databases import db_ids_by_model_variables, DB_ID_NAMES_TXT, AllDBs, DB_ID_ARCADE_NAMES_TXT +from update_all.downloader_utils import prepare_latest_downloader from update_all.ini_repository import IniRepository from update_all.file_system import FileSystem from update_all.local_repository import LocalRepository @@ -186,13 +187,10 @@ def _set_spinner_options(self, ui: UiContext): ui.set_value('firmware_needs_reboot', 'true' if self._original_firmware != firmware_md5 else 'false') def play_bad_apple(self, _ui) -> None: - content = self._os_utils.download(DOWNLOADER_URL) - if content is None: + downloader_file = prepare_latest_downloader(self._os_utils, self._file_system) + if downloader_file is None: return None - temp_file = self._file_system.temp_file_by_id('downloader.sh') - self._file_system.write_file_bytes(temp_file.name, content) - mister_ini = self._read_mister_ini() bad_apple_db_url = "https://github.com/theypsilon/BadAppleDB_MiSTer/releases/download/v1/bad_apple_full_res_db.json.zip" @@ -211,7 +209,7 @@ def play_bad_apple(self, _ui) -> None: self._ui_runtime.interrupt() - self._os_utils.execute_process(temp_file.name, env) + self._os_utils.execute_process(downloader_file, env) self._ui_runtime.resume() diff --git a/src/update_all/update_all_service.py b/src/update_all/update_all_service.py index a0dbf94..a053dab 100644 --- a/src/update_all/update_all_service.py +++ b/src/update_all/update_all_service.py @@ -26,6 +26,7 @@ from update_all.analogue_pocket.utils import is_pocket_mounted from update_all.cli_output_formatting import CLEAR_SCREEN from update_all.config import Config +from update_all.downloader_utils import prepare_latest_downloader from update_all.environment_setup import EnvironmentSetup, EnvironmentSetupImpl from update_all.constants import UPDATE_ALL_VERSION, DOWNLOADER_URL, ARCADE_ORGANIZER_URL, FILE_update_all_log, \ FILE_mister_downloader_needs_reboot, MEDIA_FAT, ARCADE_ORGANIZER_INI, MISTER_DOWNLOADER_VERSION, \ @@ -264,13 +265,10 @@ def _run_downloader(self) -> None: self._draw_separator() self._logger.print('Running MiSTer Downloader') - content = self._os_utils.download(DOWNLOADER_URL) - if content is None: + downloader_file = prepare_latest_downloader(self._os_utils, self._file_system) + if downloader_file is None: return_code = 1 else: - temp_file = self._file_system.temp_file_by_id('downloader.sh') - self._file_system.write_file_bytes(temp_file.name, content) - self._logger.print() update_linux = config.update_linux @@ -292,7 +290,7 @@ def _run_downloader(self) -> None: if config.not_mister: env['DEBUG'] = 'true' - return_code = self._os_utils.execute_process(temp_file.name, env) + return_code = self._os_utils.execute_process(downloader_file, env) if return_code != 0: self._exit_code = 1 diff --git a/update_all.sh b/update_all.sh index fb05c4e..28f8694 100755 --- a/update_all.sh +++ b/update_all.sh @@ -19,6 +19,9 @@ set -euo pipefail +SCRIPT_PATH="/tmp/update_all.sh" +CACERT_PEM="/etc/ssl/certs/cacert.pem" + if (( $(date +%Y) < 2000 )) ; then NTP_SERVER="0.pool.ntp.org" echo "Syncing date and time with $NTP_SERVER" @@ -34,6 +37,10 @@ if (( $(date +%Y) < 2000 )) ; then fi fi +if [ -s "${CACERT_PEM}" ] ; then + export CURL_CA_BUNDLE="${CACERT_PEM}" +fi + download_file() { local DOWNLOAD_PATH="${1}" local DOWNLOAD_URL="${2}" @@ -52,11 +59,6 @@ download_file() { return ;; 60|77|35|51|58|59|82|83) - if [ -s /etc/ssl/certs/cacert.pem ] ; then - export CURL_SSL="--cacert /etc/ssl/certs/cacert.pem" - continue - fi - set +e dialog --keep-window --title "Bad Certificates" --defaultno \ --yesno "CA certificates need to be fixed, do you want me to fix them?\n\nNOTE: This operation will delete files at /etc/ssl/certs" \ @@ -126,8 +128,6 @@ download_file() { echo "Launching Update All" echo -SCRIPT_PATH="/tmp/update_all.sh" - rm ${SCRIPT_PATH} 2> /dev/null || true download_file "${SCRIPT_PATH}" "https://raw.githubusercontent.com/theypsilon/Update_All_MiSTer/master/dont_download2.sh"