From 48df2468d52b568751c7c6c3c882825e985f806e Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Thu, 12 May 2022 23:17:10 -0400 Subject: [PATCH] Switch to pkgconf. Add make and dnsutils to deb-based distro install. Move the build process from (docker commands in) lmk.devuan-chimaera.sh to a script inside the container: build-lmk.rc. Include a local copy of the dependencies script (install-minetest-build-deps.sh) in the container instead of the web copy. --- .gitignore | 1 + containers/lmk.devuan-chimaera.sh | 150 +++++++------------- containers/lmk.devuan-chimaera/Dockerfile | 6 +- containers/lmk.devuan-chimaera/build-lmk.sh | 106 ++++++++++++++ containers/lmk.devuan-chimaera/lmk.rc | 23 +-- install-minetest-build-deps.sh | 20 ++- 6 files changed, 185 insertions(+), 121 deletions(-) diff --git a/.gitignore b/.gitignore index 9a16bcc..cc6756a 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ nohup.out err.txt *.continuified.tmp linux-minetest-kit.zip +/containers/lmk.devuan-chimaera/install-minetest-build-deps.sh diff --git a/containers/lmk.devuan-chimaera.sh b/containers/lmk.devuan-chimaera.sh index 589b7c3..016727b 100755 --- a/containers/lmk.devuan-chimaera.sh +++ b/containers/lmk.devuan-chimaera.sh @@ -1,8 +1,7 @@ #!/bin/bash # See https://nextbreakpoint.com/posts/article-compile-code-with-docker.html # sudo docker build -t lmk-devuan-chimaera-img dyne/devuan:chimaera -me=lmk.devuan-chimera.sh -docker_path="`sudo command -v docker`" +docker_path="`sudo bash -c 'command -v docker'`" if [ ! -f "$docker_path" ]; then cat < /dev/null sudo docker image inspect $image_name --format "* docker is looking for the image..." @@ -25,8 +43,8 @@ sudo docker image inspect $image_name --format "* docker is looking for the imag # ^ Get matching images as a JSON list (where each has "Id" and other # metadata). if [ $? -ne 0 ]; then - if [ ! -d "$local_img_dir" ]; then - echo "Error: \"$local_img_dir\" (local_img_dir for storing $SRC_URL) doesn't exist." + if [ ! -d "$docker_image_dir" ]; then + echo "Error: \"$docker_image_dir\" (docker_image_dir for storing $SRC_URL) doesn't exist in \"`pwd`\"." exit 1 fi @@ -43,6 +61,12 @@ if [ $? -ne 0 ]; then else echo "* using existing \"$container_build_blob\" to build the container image" fi + cp ../install-minetest-build-deps.sh $docker_image_dir/ + # ^ This copy of it is in .gitignore. + if [ $? -ne 0 ]; then + echo "Error: 'cp ../install-minetest-build-deps.sh $docker_image_dir/' failed." + exit 1 + fi move_back="false" prerelease_path=~/Downloads/minetest.org/insider-prerelease/linux-minetest-kit-220509.zip if [ ! -f $container_build_blob ]; then @@ -56,7 +80,7 @@ if [ $? -ne 0 ]; then fi fi fi - sudo docker build -t $image_name $local_img_dir + sudo docker build -t $image_name $docker_image_dir code=$? if [ "@move_back" = "@true" ]; then echo "mv \"$prerelease_path\" \"$container_build_blob\"" @@ -97,8 +121,10 @@ How to use the image: # ^ "run" is merely a combination of "create" and "start" sudo docker -w $contained_repo exec $container_name ls -l $contained_repos + sudo docker -w $contained_repo exec $container_name $run_all_build_commands_script # ^ Execute a command in a running container (exec shows an error if the container isn't running). # This will not work if the run/start command that started the container isn't a command that keeps it open (runs indefinitely)! + # If you need a container that has changes after $run_all_build_commands_script runs, you must use the "commit" subcommand. # w: working directory sudo docker stop $container_name @@ -142,113 +168,39 @@ fi echo "container_Id=$container_Id" END -printf "starting the docker image..." +echo "building within the container..." # sudo docker start $container_name # ^ NOTE: start is useless here since it won't stay open unless the # command is set to "bash" or something, which isn't desirable. # Therefore, use run instead of exec below. # ^ output is $container_name -sudo docker run --name $container_name $image_name /opt/build-lmk.sh -if [ $? -ne 0 ]; then - echo "FAILED" - exit 1 -else - echo "OK" -fi -# ^ NOTE: start is useless here since it won't stay open unless the -# command is set to "bash" or something, which isn't desirable. -# Therefore, use run instead of exec below. - - -if [ "@$contained_repo" = "@" ]; then - echo "Error: contained_repo can't be blank or checking for its files in the container won't work." - exit 1 -fi - -contained_good_repo_flag_path="$contained_repo/$good_repo_flag_name" - -# sudo docker exec $container_name ls $contained_repo -echo "* checking for $contained_good_repo_flag_path on the destination..." -sudo docker exec $container_name ls $contained_good_repo_flag_path > /dev/null +sudo docker run --name $container_name $image_name $run_all_build_commands_script if [ $? -ne 0 ]; then - printf "NO...checking for unzip..." - container_unzip="`sudo docker exec $container_name which unzip`" - if [ "@$container_unzip" = "@" ]; then - echo "NO. Installing..." - # This should never happen if the Dockerfile was used. - sudo docker exec $container_name apt-get update - if [ $? -ne 0 ]; then exit 1; fi - sudo docker exec $container_name apt-get install -y unzip - if [ $? -ne 0 ]; then exit 1; fi - container_unzip="`sudo docker exec $container_name which unzip`" - if [ "@$container_unzip" = "@" ]; then - echo "Error: Installing unzip in the container did not succeed. Install unzip inside the container manually then try again, or extract linux-minetest-kit such that $contained_good_repo_flag_path exists." - exit 1 - fi - else - echo "FOUND" - fi - # sudo docker container run $image_name unzip xvf $contained_arc -d $contained_repos - echo "* extracting $contained_arc" - sudo docker exec $container_name unzip $contained_arc -d $contained_repos - # -d: is destination, like -C or --directory for tar. - # -v: verbose (prevents extraction) - if [ $? -ne 0 ]; then - echo "Error: unzip failed within the container. Install unzip inside the container manually then try again, or extract linux-minetest-kit such that $contained_good_repo_flag_path exists." - exit 1 - fi -else - echo "FOUND (already extracted)" -fi + cat < /dev/null -sudo docker exec $container_name ls $contained_good_repo_flag_path > /dev/null -if [ $? -ne 0 ]; then - echo "Error: extracting linux-minetest-kit.zip in the container didn't work. Extract linux-minetest-kit.zip to $contained_repos such that $contained_good_repo_flag_path exists in the container and try again." - exit 1 -else - echo "* detected $contained_good_repo_flag_path (So the source directory is assumed to be ok)" -fi +- Update the image as follows: + sudo docker rm --force $container_name + sudo docker rmi $image_name + sudo docker image prune --force + # --force: Don't prompt for confirmation. +- Then try again: + $0 -if [ "@$contained_user" = "@" ]; then - echo "Error: contained_user can't be blank, or checking for the user within the container will not work." +END exit 1 -fi - -sudo docker exec $container_name id -u $contained_user -if [ $? -ne 0 ]; then - printf "* creating $contained_user in container $container_name..." - sudo docker exec $container_name adduser --disabled-password --gecos "" $contained_user --home $contained_home - if [ $? -ne 0 ]; then - echo "FAILED" - exit 1 - else - echo "OK" - fi else - echo "* using the $container_name container's existing contained_user: $contained_user" + echo "* building within the container completed OK" fi +# ^ NOTE: start is useless here since it won't stay open unless the +# command is set to "bash" or something, which isn't desirable. +# Therefore, use run instead of exec below. -# sudo docker container run --name $container_name $image_name ls $contained_repos - -# sudo docker exec $container_name chown -R $contained_user $contained_repos -# ^ Usually you could do this, but run as root since this script is used to test the safety of linux-minetest-kit: - -# sudo docker exec $container_name curl https://raw.githubusercontent.com/poikilos/EnlivenMinetest/master/install-minetest-build-deps.sh --output /opt/install-minetest-build-deps.sh -# sudo docker exec $container_name chmod +x $repo_build_assumptions_cmd -# sudo docker exec $container_name $repo_build_assumptions_cmd - -# ^ moved to Dockerfile - -echo "* building libraries using $repo_build_libs_cmd..." -sudo docker exec -w $contained_src $container_name $repo_build_libs_cmd -if [ $? -ne 0 ]; then exit 1; fi -# echo "* building program using $repo_build_cmd..." -# sudo docker exec -w $contained_src $container_name $repo_build_cmd -if [ $? -ne 0 ]; then exit 1; fi -# -w: working directory +# - Run again as follows: +# sudo docker start $container_name +# ^ doesn't work (The script specified by "run" earlier doesn't run). # How to use docker-compose (See ): diff --git a/containers/lmk.devuan-chimaera/Dockerfile b/containers/lmk.devuan-chimaera/Dockerfile index 6335531..7bc9065 100644 --- a/containers/lmk.devuan-chimaera/Dockerfile +++ b/containers/lmk.devuan-chimaera/Dockerfile @@ -3,10 +3,12 @@ FROM dyne/devuan:chimaera COPY linux-minetest-kit.zip /opt COPY lmk.rc /opt COPY build-lmk.sh /opt +COPY install-minetest-build-deps.sh /opt RUN apt-get update RUN apt-get install -y unzip +RUN apt-get install -y perl RUN unzip /opt/linux-minetest-kit.zip -d /opt # RUN apt-get install -y sudo -RUN curl https://raw.githubusercontent.com/poikilos/EnlivenMinetest/master/install-minetest-build-deps.sh --output /opt/install-minetest-build-deps.sh -RUN chmod +x /opt/install-minetest-build-deps.sh +# RUN curl https://raw.githubusercontent.com/poikilos/EnlivenMinetest/master/install-minetest-build-deps.sh --output /opt/install-minetest-build-deps.sh +# RUN chmod +x /opt/install-minetest-build-deps.sh RUN /opt/install-minetest-build-deps.sh diff --git a/containers/lmk.devuan-chimaera/build-lmk.sh b/containers/lmk.devuan-chimaera/build-lmk.sh index b66d976..ffcee08 100755 --- a/containers/lmk.devuan-chimaera/build-lmk.sh +++ b/containers/lmk.devuan-chimaera/build-lmk.sh @@ -4,6 +4,112 @@ if [ $? -ne 0 ]; then exit 1 fi source lmk.rc +me=build-lmk.sh if [ $? -ne 0 ]; then exit 1 fi + +if [ "@$contained_repo" = "@" ]; then + echo "Error: contained_repo can't be blank or checking for its files in the container won't work." + exit 1 +fi + +# ls $contained_repo +echo "* checking for $contained_good_repo_flag_path on the destination..." +ls $contained_good_repo_flag_path > /dev/null +if [ $? -ne 0 ]; then + echo "NOT FOUND" + printf "Warning: the Docker image isn't up to date. Unzipping manually..." + printf "checking for unzip..." + container_unzip="`which unzip`" + if [ "@$container_unzip" = "@" ]; then + echo "NOT FOUND. Installing..." + # This should never happen if the Dockerfile was used. + apt-get update + if [ $? -ne 0 ]; then exit 1; fi + apt-get install -y unzip + if [ $? -ne 0 ]; then exit 1; fi + container_unzip="`which unzip`" + if [ "@$container_unzip" = "@" ]; then + echo "Error: Installing unzip in the container did not succeed. Install unzip inside the container manually then try again, or extract linux-minetest-kit such that $contained_good_repo_flag_path exists." + exit 1 + fi + else + echo "FOUND" + fi + # sudo docker container run $image_name unzip xvf $contained_arc -d $contained_repos + echo "* extracting $contained_arc" + unzip $contained_arc -d $contained_repos + # -d: is destination, like -C or --directory for tar. + # -v: verbose (prevents extraction) + if [ $? -ne 0 ]; then + echo "Error: unzip failed within the container. Install unzip inside the container manually then try again, or extract linux-minetest-kit such that $contained_good_repo_flag_path exists." + exit 1 + fi +else + echo "FOUND (already extracted)" +fi + +# ls $contained_repo > /dev/null +ls $contained_good_repo_flag_path > /dev/null +if [ $? -ne 0 ]; then + echo "Error: extracting linux-minetest-kit.zip in the container didn't work. Extract linux-minetest-kit.zip to $contained_repos such that $contained_good_repo_flag_path exists in the container and try again." + exit 1 +else + echo "* detected $contained_good_repo_flag_path (So the source directory is assumed to be ok)" +fi + + + +if [ "@$contained_user" = "@" ]; then + echo "Error: contained_user can't be blank, or checking for the user within the container will not work." + exit 1 +fi + +id -u $contained_user +if [ $? -ne 0 ]; then + printf "* creating $contained_user in container $container_name..." + adduser --disabled-password --gecos "" $contained_user --home $contained_home + if [ $? -ne 0 ]; then + echo "FAILED" + exit 1 + else + echo "OK" + fi +else + echo "* using the $container_name container's existing contained_user: $contained_user" +fi + +# sudo docker container run --name $container_name $image_name ls $contained_repos + +# chown -R $contained_user $contained_repos +# ^ Usually you could do this, but run as root since this script is used to test the safety of linux-minetest-kit: + +# curl https://raw.githubusercontent.com/poikilos/EnlivenMinetest/master/install-minetest-build-deps.sh --output /opt/install-minetest-build-deps.sh +# chmod +x $repo_build_assumptions_cmd +# $repo_build_assumptions_cmd + +# ^ moved to Dockerfile + +if [ ! -d "$contained_repo" ]; then + echo "Error: \"$contained_repo\" doesn't exist." + exit 1 +fi +echo "* building libraries using $repo_build_libs_cmd..." +cd "$contained_repo" +if [ $? -ne 0 ]; then exit 1; fi +$repo_build_libs_cmd +if [ $? -ne 0 ]; then exit 1; fi +echo +echo +echo +echo +echo +echo +echo "* building program using $repo_build_cmd..." +$repo_build_cmd +code=$? +if [ $code -ne 0 ]; then + echo "$repo_build_cmd FAILED (code $code)" + exit $code +fi diff --git a/containers/lmk.devuan-chimaera/lmk.rc b/containers/lmk.devuan-chimaera/lmk.rc index afd1707..b13755d 100644 --- a/containers/lmk.devuan-chimaera/lmk.rc +++ b/containers/lmk.devuan-chimaera/lmk.rc @@ -1,3 +1,4 @@ +#!/bin/bash contained_repos=/opt contained_arc="$contained_repos/linux-minetest-kit.zip" # ^ This must always be in sync with "COPY linux-minetest-kit.zip /opt" in Dockerfile @@ -10,24 +11,12 @@ fi #if [ "@$DL_SRC_NAME" = "@" ]; then DL_SRC_NAME=linux-minetest-kit.zip #fi -local_img_dir="lmk.devuan-chimaera" -if [ ! -d "$local_img_dir" ]; then - echo "* $me must run from the directory containing the container image directory: $local_img_dir" - exit 1 -fi -container_build_blob=$local_img_dir/linux-minetest-kit.zip -# ^ local_img_dir has to be in the same directory as Dockerfile or -# the COPY command in the Dockerfile won't work. -if [ "@$DL_SRC_PATH" = "@" ]; then - # DL_SRC_PATH="$HOME/Downloads/$DL_SRC_NAME" - DL_SRC_PATH="$local_img_dir" - # ^ $DL_SRC_PATH has to be in the same directory as Dockerfile or - # the COPY command in the Dockerfile won't work. - # The file should be added to .gitignore for the reason that it - # is in the repo in the docker image directory. -fi good_repo_flag_name="mtcompile-program.pl" repo_build_assumptions_cmd="/opt/install-minetest-build-deps.sh" -repo_build_libs_cmd="./mtcompile-libraries.sh" +repo_build_libs_cmd="bash -e ./mtcompile-libraries.sh build" repo_build_cmd="./mtcompile-program.pl --build --classic --client" +contained_good_repo_flag_path="$contained_repo/$good_repo_flag_name" + +run_all_build_commands_script=/opt/build-lmk.sh +echo "lmk.rc finished loading." diff --git a/install-minetest-build-deps.sh b/install-minetest-build-deps.sh index 606f929..59acadd 100755 --- a/install-minetest-build-deps.sh +++ b/install-minetest-build-deps.sh @@ -85,10 +85,11 @@ if [ ! -z "$this_apt" ]; then libsqlite3-dev libssl-dev libtool \ libvorbis-dev libx11-dev libxxf86vm-dev lynx \ nano nettle-dev p7zip-full patch \ - perl pkg-config python3 python3-dev \ + perl pkgconf python3 python3-dev \ python-dev rake ruby sed \ tar tcl unzip util-linux \ - wget xz-utils zip \ + wget xz-utils zip perl \ + dnsutils make \ \ libcurl4-openssl-dev \ libfreetype6-dev \ @@ -97,6 +98,17 @@ if [ ! -z "$this_apt" ]; then libxml-parser-perl \ xserver-xorg-dev \ ; + # NOTE: installing pkgconf removes pkg-config: + # "pkgconf is a newer, actively maintained implementation of pkg-config that supports more aspects of the pkg-config file specification and provides a library interface that applications can use to incorporate intelligent handling of pkg-config files into themselves (such as build file generators, IDEs, and compilers)." + # - + # NOTE: build-essentials installs the following according to : + cat > /dev/null <14.04 [not known in 15.x])" fi else - echo "* WARNING: VERSION_ID is not in /etc/os-release, so the libtool-bin package will be skipped (it is only in Ubuntu >14.04 [not known in 15.x])" + echo "* WARNING: VERSION_ID is not in /etc/os-release, so the libtool-bin package name is unknown (it is only in Ubuntu >14.04 [not known in 15.x])" + echo " * trying libtool-bin..." + $this_apt -y install libtool-bin fi fi #libcurl4-openssl-dev: for announce to work