Skip to content

Commit

Permalink
fix quotes, create separate env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
cbusillo committed Jun 13, 2024
1 parent 3d23551 commit 87685ab
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
49 changes: 29 additions & 20 deletions bd_to_avp/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from bd_to_avp.modules.util import run_command


def prompt_for_password() -> Path:
def prompt_for_password() -> tuple[Path, dict[str, str]]:
script = f"""
with timeout of 3600 seconds
tell app "System Events"
Expand All @@ -26,21 +26,24 @@ def prompt_for_password() -> Path:
pw_file_path = Path(pw_file.name)
pw_file_path.chmod(0o700)
password_correct = False
sudo_env = {}
while not password_correct:
password = subprocess.check_output(["osascript", "-e", script], text=True).strip()

os.environ["HOMEBREW_PASSWORD"] = password
sudo_env = os.environ.copy()
sudo_env["HOMEBREW_PASSWORD"] = password

os.environ["SUDO_ASKPASS"] = pw_file_path.as_posix()
sudo_env["SUDO_ASKPASS"] = pw_file_path.as_posix()
check_sudo_password = subprocess.run(
["/usr/bin/sudo", "-A", "ls"],
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
input=password,
env=sudo_env,
)
password_correct = check_sudo_password.returncode == 0
return pw_file_path
return pw_file_path, sudo_env


def add_homebrew_to_path() -> None:
Expand All @@ -67,32 +70,34 @@ def install_deps(is_gui: bool) -> None:
raise ValueError("This script is only supported on Apple Silicon Macs.")
print("Installing dependencies...")
pw_file_path = None
sudo_env = os.environ.copy()

if is_gui:
pw_file_path = prompt_for_password()
pw_file_path, sudo_env = prompt_for_password()

if not Path(config.HOMEBREW_PREFIX_BIN / "brew").exists():
install_brew(is_gui)
install_brew(is_gui, sudo_env)
else:
update_brew(is_gui)
update_brew(is_gui, sudo_env)

if not check_for_homebrew_in_path():
add_homebrew_to_path()

upgrade_brew(is_gui)
upgrade_brew(is_gui, sudo_env)

manage_brew_package("makemkv", is_gui, True, "uninstall")
manage_brew_package("makemkv", is_gui, sudo_env, True, "uninstall")

for package in config.BREW_CASKS_TO_INSTALL:
if not check_is_package_installed(package):
manage_brew_package(package, is_gui, True)
manage_brew_package(package, is_gui, sudo_env, True)

manage_brew_package(config.BREW_PACKAGES_TO_INSTALL, is_gui)
manage_brew_package(config.BREW_PACKAGES_TO_INSTALL, is_gui, sudo_env)

if not check_rosetta():
install_rosetta(is_gui)

check_mp4box(is_gui)
if should_install_mp4box():
install_mp4box(is_gui, sudo_env)

wine_boot()

Expand Down Expand Up @@ -124,13 +129,14 @@ def install_rosetta(is_gui: bool) -> None:
print("Rosetta installed.")


def check_mp4box(is_gui: bool) -> None:
def should_install_mp4box() -> bool:
if not config.MP4BOX_PATH.exists() or not check_mp4box_version(config.MP4BOX_VERSION):
if config.MP4BOX_PATH.exists():
print("Removing old MP4Box...")
shutil.rmtree("/Applications/GPAC.app", ignore_errors=True)
print("Installing MP4Box...")
install_mp4box(is_gui)
return True
return False


def check_install_version() -> bool:
Expand Down Expand Up @@ -191,7 +197,7 @@ def check_is_package_installed(package: str) -> bool:


def manage_brew_package(
packages: str | list[str], is_gui: bool, cask: bool = False, operation: str = "install"
packages: str | list[str], is_gui: bool, sudo_env: dict[str, str], cask: bool = False, operation: str = "install"
) -> None:
if isinstance(packages, str):
packages = [packages]
Expand All @@ -217,6 +223,7 @@ def manage_brew_package(
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=sudo_env,
)

if operation == "uninstall" and process.returncode == 1:
Expand All @@ -229,29 +236,31 @@ def manage_brew_package(
print(f"{packages_str} {operation}ed.")


def update_brew(is_gui: bool) -> None:
def update_brew(is_gui: bool, sudo_env: dict[str, str]) -> None:
print("Updating Homebrew...")
brew_command = ["/opt/homebrew/bin/brew", "update"]
process = subprocess.run(
brew_command,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=sudo_env,
)

if process.returncode != 0:
on_error_process("Homebrew", process, is_gui)
print("Homebrew updated.")


def upgrade_brew(is_gui: bool) -> None:
def upgrade_brew(is_gui: bool, sudo_env: dict[str, str]) -> None:
print("Upgrading Homebrew...")
brew_command = ["/opt/homebrew/bin/brew", "upgrade"]
process = subprocess.run(
brew_command,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=sudo_env,
)

if process.returncode != 0:
Expand All @@ -269,9 +278,8 @@ def check_mp4box_version(version: str) -> bool:
return version in processs.stderr


def install_mp4box(is_gui: bool) -> None:
def install_mp4box(is_gui: bool, sudo_env: dict[str, str]) -> None:
print("Installing MP4Box...")
sudo_env = os.environ.copy()

response = requests.get(
"https://download.tsi.telecom-paristech.fr/gpac/release/2.2.1/gpac-2.2.1-rev0-gb34e3851-release-2.2.pkg"
Expand Down Expand Up @@ -318,7 +326,7 @@ def wine_boot() -> None:
print("Wine booted.")


def install_brew(is_gui: bool) -> None:
def install_brew(is_gui: bool, sudo_env: dict[str, str]) -> None:
print("Installing Homebrew for arm64...")

response = requests.get("https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh")
Expand All @@ -336,6 +344,7 @@ def install_brew(is_gui: bool) -> None:
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=sudo_env,
)

if process.returncode != 0:
Expand Down
2 changes: 1 addition & 1 deletion push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fi
git checkout "$SOURCE_BRANCH"
git pull origin "$SOURCE_BRANCH"
git checkout "$DESTINATION_BRANCH"
git merge "$SOURCE_BRANCH" -m "merge "$SOURCE_BRANCH" into "$DESTINATION_BRANCH""
git merge "$SOURCE_BRANCH" -m "merge $SOURCE_BRANCH into $DESTINATION_BRANCH"
git push
git checkout "$SOURCE_BRANCH"
git pull origin "$SOURCE_BRANCH"
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "bd_to_avp"
version = "0.2.66"
version = "0.2.67"
description = "Script to convert 3D Blu-ray Discs (and mts) to Apple Vision Pro (MV-HEVC) files"
authors = ["Chris Busillo <info@shinycomputers.com>"]
readme = "README.md"
Expand Down Expand Up @@ -40,7 +40,7 @@ build-backend = "poetry.core.masonry.api"
project_name = "3D Blu-ray to Vision pro"
bundle = "com.shinycomputers"
architectures = ["arm64"]
version = "0.2.66"
version = "0.2.67"
icon = "bd_to_avp/resources/app_icon"
organization = "Shiny Computers"

Expand Down

0 comments on commit 87685ab

Please sign in to comment.