Skip to content

Commit

Permalink
Using pre-installed downloader when available.
Browse files Browse the repository at this point in the history
  • Loading branch information
theypsilon committed Mar 3, 2024
1 parent e8d3067 commit 4ccb78a
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/update_all/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
38 changes: 38 additions & 0 deletions src/update_all/downloader_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python3
# Copyright (c) 2022-2024 José Manuel Barroso Galindo <[email protected]>
# 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 <http://www.gnu.org/licenses/>.

# 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
2 changes: 1 addition & 1 deletion src/update_all/ini_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions src/update_all/settings_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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()

Expand Down
10 changes: 4 additions & 6 deletions src/update_all/update_all_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions update_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}"
Expand All @@ -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" \
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 4ccb78a

Please sign in to comment.