diff options
author | tdro <tdro@users.noreply.github.com> | 2022-03-11 19:49:26 -0500 |
---|---|---|
committer | tdro <tdro@users.noreply.github.com> | 2022-03-11 19:49:26 -0500 |
commit | a257c143b10a7ff42a4e4cc6610b85698669fcbb (patch) | |
tree | 3c13fdd7d6b908b7eb291a7388300c5d87e00c01 /.local | |
parent | 5bffa79831a25b59ee6d9424e9ac5c3380b62d06 (diff) | |
download | dotfiles-a257c143b10a7ff42a4e4cc6610b85698669fcbb.tar.gz dotfiles-a257c143b10a7ff42a4e4cc6610b85698669fcbb.tar.bz2 dotfiles-a257c143b10a7ff42a4e4cc6610b85698669fcbb.zip |
.config/lxc: Add build files
Diffstat (limited to '.local')
-rwxr-xr-x | .local/bin/lxc-build | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/.local/bin/lxc-build b/.local/bin/lxc-build new file mode 100755 index 0000000..c9e41f5 --- /dev/null +++ b/.local/bin/lxc-build @@ -0,0 +1,95 @@ +#!/usr/bin/env runhaskell + +import System.Console.GetOpt +import System.Environment +import System.Exit +import System.Process + +version :: Fractional p => p +version = 0.01 + +help :: [Char] +help = unlines + [ "" + , "NAME" + , "" + , " lxc-build" + , "" + , "SYNOPSIS" + , "" + , " Create an lxc container named rockylinux with the specified Dockerfile" + , "" + , " lxc-build --name rockylinux rockylinux8.dockerfile" + , "" + , " Start the container after building" + , "" + , " lxc-build --start --name rockylinux rockylinux8.dockerfile" + , "" + , " Replace a container of the same name with the new build" + , "" + , " lxc-build --replace --name rockylinux rockylinux8.dockerfile" + , "" + , "DESCRIPTION" + , "" + , " Builds a lxc container from a Dockerfile" + , "" + , "COMMANDS" + , "" + , " -n, -name, --name The container name" + , " -c, -create, --create Create the container" + , " -h, -help, --help Shows this help menu" + , " -u, -user-map, --user-map User mapping id" + , " -g, -group-map, --group-map Group mapping id" + , " -r, -replace, --replace Replace container with new build" + , " -v, -version, --version Prints program version" + ] + +display = putStrLn + +main = do + arguments <- getArgs + case arguments of + ["--replace", "--name", name, dockerfile] -> do + callCommand ("\\lxc-destroy --force --name " ++ name ++ " |& \\true") + callCommand + ( "\\lxc-create --name " + ++ name + ++ " --template=none && \\mkdir ~/.local/share/lxc/" + ++ name + ++ "/rootfs" + ) + callCommand ("\\docker build --file " ++ dockerfile) + callCommand + ( "id=$(\\docker run --detach \"$(\\docker build --file " + ++ dockerfile + ++ " | tail --lines=1)\" /bin/true) && \\docker export \"$id\" | \\tar --extract --directory ~/.local/share/lxc/" + ++ name + ++ "/rootfs && \\docker container rm \"$id\"" + ) + callCommand + ( "\\printf 'doas chown --recursive 200000:200000 ~/.local/share/lxc/" + ++ name + ++ "/rootfs\n'" + ) + callCommand + ( "\\doas chown --recursive 200000:200000 ~/.local/share/lxc/" + ++ name + ++ "/rootfs" + ) + callCommand + ( "\\printf 'lxc.uts.name = " + ++ name + ++ "\n' >> ~/.local/share/lxc/" + ++ name + ++ "/config" + ) + callCommand + ( "\\printf \"lxc.rootfs.path = dir:$HOME/.local/share/lxc/" + ++ name + ++ "/rootfs\n\" >> ~/.local/share/lxc/" + ++ name + ++ "/config" + ) + callCommand ("\\lxc-start --name " ++ name) + _ -> do + die help |