2019-12-25 02:33:19 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
from getpass import getuser
|
|
|
|
from os import getuid, getgid, getlogin
|
2019-12-29 12:10:08 -05:00
|
|
|
from shutil import which
|
2019-12-25 02:33:19 -05:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
parser = ArgumentParser(description="Install AUR packages into a Docker container")
|
|
|
|
parser.add_argument("package_name", type=str, help="name of the AUR package")
|
|
|
|
parser.add_argument("-x", type=str, metavar='EXECUTABLE', help="name of executable")
|
2020-01-01 23:27:39 -05:00
|
|
|
parser.add_argument("-e", type=str, help="add extra step in dockerfile")
|
2019-12-25 02:33:19 -05:00
|
|
|
args = vars(parser.parse_args())
|
|
|
|
|
|
|
|
package_name = args['package_name']
|
|
|
|
command = args['x']
|
2019-12-30 14:13:43 -05:00
|
|
|
edit_flag = args['e']
|
2019-12-25 02:33:19 -05:00
|
|
|
user = getlogin()
|
|
|
|
uid = getuid()
|
|
|
|
gid = getgid()
|
|
|
|
|
|
|
|
if command is None:
|
|
|
|
print(f"Assuming executable shares the same name as package_name {package_name}")
|
|
|
|
command = package_name
|
|
|
|
|
|
|
|
|
|
|
|
dockerfile = f"""FROM archlinux:latest
|
|
|
|
|
|
|
|
# Install latest build packages and git
|
|
|
|
RUN pacman -Sy --noconfirm base-devel git
|
|
|
|
|
|
|
|
# Set up new user {user} with passwordless sudo
|
|
|
|
RUN useradd {user} -u {uid} -m && \\
|
|
|
|
passwd -d {user} && \\
|
|
|
|
set -o pipefail && \\
|
|
|
|
printf '{user} ALL=(ALL) ALL\\n' | tee -a /etc/sudoers
|
|
|
|
|
|
|
|
# Set up AUR helper yay
|
|
|
|
USER {user}
|
|
|
|
WORKDIR /home/{user}
|
|
|
|
RUN git clone https://aur.archlinux.org/yay.git
|
|
|
|
WORKDIR /home/{user}/yay
|
|
|
|
RUN makepkg -si --noconfirm
|
|
|
|
|
2020-01-01 23:05:05 -05:00
|
|
|
#add extra step
|
2020-01-01 23:23:45 -05:00
|
|
|
{"RUN " + edit_flag if edit_flag is not None else ""}
|
2019-12-30 14:13:43 -05:00
|
|
|
|
2020-01-01 23:25:58 -05:00
|
|
|
|
2019-12-25 02:33:19 -05:00
|
|
|
# Now you can play with whatever package you'd like
|
|
|
|
RUN yay -S --noconfirm {package_name}
|
|
|
|
|
|
|
|
ENTRYPOINT [\"/usr/bin/env\", \"{command}\"]"
|
|
|
|
"""
|
|
|
|
|
2019-12-28 19:38:58 -05:00
|
|
|
# check if either docker or podman are installed
|
2019-12-28 14:10:43 -05:00
|
|
|
|
2019-12-29 13:00:19 -05:00
|
|
|
try:
|
|
|
|
if which("docker") is None:
|
|
|
|
print("Docker not installed, building with Podman")
|
|
|
|
engine = "podman"
|
|
|
|
elif which("podman") is None:
|
|
|
|
engine = "docker"
|
|
|
|
else:
|
|
|
|
print("Podman/Docker are not installed! Exiting...")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
subprocess.run([engine, "build", "-t", command, "-"], input = dockerfile, encoding = 'UTF-8')
|
|
|
|
except FileNotFoundError:
|
|
|
|
print("An Error has occured while attempting to build the image.")
|
2019-12-29 12:10:08 -05:00
|
|
|
exit(1)
|