-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
env: Enable passing through Hetzner Arch Linux repo to distrobox
Make function easy to run to allow enabling easily in virtual machines as well. Signed-off-by: Nathan Chancellor <[email protected]>
- Loading branch information
1 parent
a9a8862
commit 79a12c9
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env fish | ||
# SPDX-License-Identifier: MIT | ||
# Copyright (C) 2024 Nathan Chancellor | ||
|
||
function add_hetzner_mirror_to_repos -d "Add Hetzner's internal Arch Linux mirror to /etc/pacman.conf" | ||
set program "import arch | ||
from pathlib import Path | ||
import sys | ||
# Not using pacman, bail out gracefully | ||
if not (pacman_conf := Path('/etc/pacman.conf')).exists(): | ||
sys.exit(0) | ||
orig_pacman_conf_txt = pacman_conf.read_text(encoding='utf-8') | ||
new_pacman_conf_txt = arch.add_hetzner_mirror_to_repos(orig_pacman_conf_txt) | ||
if orig_pacman_conf_txt != new_pacman_conf_txt: | ||
pacman_conf.write_text(new_pacman_conf_txt, encoding='utf-8')" | ||
|
||
if test (count $argv) -eq 0 | ||
sudo env PYTHONPATH=$PYTHON_FOLDER/setup python -c "$program" | ||
return | ||
end | ||
|
||
for arg in $argv | ||
switch $arg | ||
case -p --print-container-routine | ||
printf '\n%s\n%s\n%s%s%s\n%s\n' \ | ||
'# Import Hetzner mirror from the host configuration if using pacman' \ | ||
'if command -v python3 >/dev/null 2>&1; then' \ | ||
' PYTHONPATH=/run/host'$PYTHON_FOLDER'/setup python3 -c "' \ | ||
"$program" \ | ||
'" || exit' \ | ||
'fi' | ||
|
||
case '*' | ||
print_error "Unknown argument: $arg" | ||
return 1 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env fish | ||
# SPDX-License-Identifier: MIT | ||
# Copyright (C) 2024 Nathan Chancellor | ||
|
||
function is_hetzner -d "Checks if current running machine is a Hetzner machine" | ||
if test $LOCATION = hetzner # duh | ||
return 0 | ||
end | ||
PYTHONPATH=$PYTHON_FOLDER/setup python3 -c 'from arch import is_hetzner; import sys; sys.exit(0 if is_hetzner() else 1)' | ||
end |