diff options
author | Andreas Fankhauser hiddenalpha.ch | 2023-08-24 19:54:46 +0200 |
---|---|---|
committer | Andreas Fankhauser hiddenalpha.ch | 2023-08-24 19:54:46 +0200 |
commit | e05741fc1627c23d5811ad0c08bb372e87eeab94 (patch) | |
tree | 40b6f45327d5b2ee0bb8be65efb66f9e43f6f171 | |
parent | f5432f6c475c0ee158c84fe8fed686216418bf06 (diff) | |
download | bulk-ln-e05741fc1627c23d5811ad0c08bb372e87eeab94.zip bulk-ln-e05741fc1627c23d5811ad0c08bb372e87eeab94.tar.gz |
Replace ugly docker build env by qemu setup script.v0.0.2
-rw-r--r-- | README.md | 16 | ||||
-rw-r--r-- | contrib/build-env-setup/README.md | 60 | ||||
-rw-r--r-- | contrib/build-env-setup/setup | 32 | ||||
-rw-r--r-- | contrib/build-using-docker/Dockerfile | 35 | ||||
-rw-r--r-- | contrib/build-using-docker/README.md | 69 | ||||
-rw-r--r-- | src/bulk_ln/bulk_ln.c | 77 |
6 files changed, 145 insertions, 144 deletions
@@ -8,11 +8,7 @@ create many links. ## How to build / install -If you prefer to build within more isolated environment may -[contrib/build-using-docker/](contrib/build-using-docker/README.md) -could be interesting for you. - -If you prefer traditional, just do: +Classic way: ```sh curl -sSL http://git.hiddenalpha.ch/bulk-ln.git/snapshot/bulk-ln-master.tar.gz | tar xz @@ -22,3 +18,13 @@ make make install ``` +In case you prefer more sustainable build environments, +"./contrib/build-env-setup/README.md" +potentially is interesting for you. + + + + + + + diff --git a/contrib/build-env-setup/README.md b/contrib/build-env-setup/README.md new file mode 100644 index 0000000..90322f7 --- /dev/null +++ b/contrib/build-env-setup/README.md @@ -0,0 +1,60 @@ + +Showcase how to build and install +================================= + +WARN: Do NOT perform any of these steps on your host system! This script + MUST only be run on a system which is a + just-throw-it-away-if-broken system. + +Sometimes happy developers (like me) have no choice but using terribly +restricted systems where setting up tools to run even something as +trivial as configure/make/install becomes a nightmare if not impossible. +I found it to be very handy to have some independent qemu VM at hand +which lets me install whatever I need, neither with any special software +nor any annoying privileges on a host machine. Qemu runs portable and in +user mode even doesn't need any annoying permissions at all. + + +## Setup a minimal system in your qemu VM + +This setup mainly targets debian. Nevertheless it tries to stay POSIX +compatible as far as possible. So setup a minimal install of your system +of choice and then as soon you've SSH access to a (posix) shell, you're +ready for the next step. + +Still not sure which system to use? Link below provides some candidates. +HINT: Windows IMHO is a terrible choice. So stop complaining if you go +this route. + +https://en.wikipedia.org/wiki/POSIX#POSIX-oriented_operating_systems + + +## Start VM with SSH access + +Easiest way to work with your machine is via SSH. Therefore if you've +chosen to use a qemu VM, make sure you've setup and configured sshd +properly inside the VM. Then just pass args like those to qemu: + + --device e1000,netdev=n0 --netdev user,id=n0,hostfwd=tcp:127.0.0.1:2222-:22 + +Started this way, the SSHDaemon inside the VM is accessible from your +host via "localhost" at port "2222": + + ssh localhost -p2222 + + +## Finalize by build and install whole project + +Run the "./setup" script (which is a posix shell script btw) inside the +freshly setup system. This script does all the work. Like installing +required packages, configure and build the whole project and finally +installing it into the VM so it can be tried out right away from your +VMs shell. +BTW: The script is constructed so it can be copy-pasted into a terminal. +There is no need to transfer a file to the machine beforehand. + + + + + + diff --git a/contrib/build-env-setup/setup b/contrib/build-env-setup/setup new file mode 100644 index 0000000..31c5f11 --- /dev/null +++ b/contrib/build-env-setup/setup @@ -0,0 +1,32 @@ + +echo "WARN: read (AND UNDERSTAND) the README before running this script!" +sleep 3 +exit 1 + + +true \ + && GIT_TAG="master" \ + && CONFIGURE_OPTS= \ + && PKGS_TO_ADD="ca-certificates curl gcc git make libc-dev tar" \ + && PKGS_TO_DEL="curl gcc git make libc-dev" \ + && SUDO=sudo \ + && PKGINIT="$SUDO apt update" \ + && PKGADD="$SUDO apt install -y --no-install-recommends" \ + && PKGDEL="$SUDO apt purge -y" \ + && PKGCLEAN="$SUDO apt clean" \ + && WORKDIR="${HOME:?}/work" \ + && true \ + && mkdir -p "${WORKDIR:?}" && cd "${WORKDIR:?}" \ + && ${PKGINIT:?} && ${PKGADD:?} $PKGS_TO_ADD \ + && git clone --depth 42 --branch "${GIT_TAG:?}" https://github.com/hiddenalpha/bulk-ln.git . \ + && git config advice.detachedHead false \ + && git checkout "${GIT_TAG:?}" \ + && ./configure $CONFIGURE_OPTS \ + && make clean && make -j$(nproc) \ + && $SUDO make install \ + && find . -not -wholename './dist*' -delete \ + && ${PKGDEL:?} $PKGS_TO_DEL && ${PKGCLEAN:?} \ + && dirOfDistBundle="$(realpath dist)" \ + && printf '\n SUCCESS :) Distribution bundle is ready in:\n\n %s\n\n Tip: Before pulling out your hair about how to get that archive out of\n your qemu VM. STOP kluding around with silly tools and learn how\n basic tools do the job perfectly fine:\n\n ssh %s@localhost -p2222 -- sh -c '\''true && cd "%s" && tar c *'\'' | tar x\n\n BTW: In addition bulk-ln got installed and is ready-to-use.\n\n' "${dirOfDistBundle:?}" "$USER" "${dirOfDistBundle:?}" \ + && true + diff --git a/contrib/build-using-docker/Dockerfile b/contrib/build-using-docker/Dockerfile deleted file mode 100644 index 47b14f5..0000000 --- a/contrib/build-using-docker/Dockerfile +++ /dev/null @@ -1,35 +0,0 @@ - -ARG PARENT_IMAGE=alpine:3.16.0 -FROM $PARENT_IMAGE - -ARG GIT_TAG=master -ARG CONFIGURE_OPTS= -ARG PKGINIT=true -ARG PKGADD="apk add" -ARG PKGDEL="apk del" -ARG PKGCLEAN=true -ARG PKGS_TO_ADD="curl gcc git make musl-dev tar" -ARG PKGS_TO_DEL="curl gcc git make musl-dev tar" - -WORKDIR /work - -RUN true \ - && $PKGINIT \ - && $PKGADD $PKGS_TO_ADD \ - && git clone --depth 42 --branch "${GIT_TAG:?}" https://github.com/hiddenalpha/bulk-ln.git . \ - && git config advice.detachedHead false \ - && git checkout "$GIT_TAG" \ - && ./configure $CONFIGURE_OPTS \ - && make clean && make && make install \ - && find . -not -wholename './dist*' -delete \ - && find /work -exec chown 1000:1000 {} + \ - && $PKGDEL $PKGS_TO_DEL \ - && $PKGCLEAN \ - && true - -USER 1000:1000 - -# run for max 10 hrs. Because this container is not meant to stay running -# forever. -CMD ["sleep", "36000"] - diff --git a/contrib/build-using-docker/README.md b/contrib/build-using-docker/README.md deleted file mode 100644 index ec571e0..0000000 --- a/contrib/build-using-docker/README.md +++ /dev/null @@ -1,69 +0,0 @@ - -Showcase how to build and install -================================= - -Sometimes happy developers (like me) have no choice but using horribly -restricted systems where setting up tools to run even something as simple as -configure/make/install becomes a nightmare. I found it to be easier to have a -Dockerfile to build on a totally unrelated machine (but where I have the needed -privileges) and then just copy-paste the built result over to where I need it. - -WARN: Default configuration uses an alpine base image that means build will - dynamically link to musl libc and so won't run on most other systems. - This is because for a quick-n-dirty walktrough about what this tool does - this is ways enough. Consult "Other targets" further down and configure a - base image that fits your needs. - - -## Setup basic stuff to reduce annoyance - -```sh -mkdir /tmp/some-empty-dir -cd /tmp/some-empty-dir -IMG=bulk-ln-showcase:latest -``` - -## Make and install dockerimage - -```sh -curl -sSL http://git.hiddenalpha.ch/bulk-ln.git/plain/contrib/build-using-docker/Dockerfile | sudo docker build . -f - -t "${IMG:?}" -``` - -## Grab distribution archive - -Most probably we wanna get the distribution archive. We can copy it out the -dockerimage into our working dir on the host using: - -```sh -sudo docker run --rm -i "${IMG:?}" sh -c 'true && cd dist && tar c *' | tar x -``` - - -## Play around - -Or if we wanna browse the image or play around with the built utility we could -launch a shell. Once in the shell, try `bulk-ln --help`. - -```sh -sudo docker run --rm -ti "${IMG:?}" sh -``` - - -## Other targets - -The dockerfile is parameterized and should work for other systems too. For -example to compile for debian we could use example command as below. - -To build for other systems it should be enough to adjust below command. - -```sh -curl -sSL http://git.hiddenalpha.ch/bulk-ln.git/plain/contrib/build-using-docker/Dockerfile | sudo docker build . -f - -t "${IMG:?}" \ - --build-arg PARENT_IMAGE=debian:9-slim \ - --build-arg PKGS_TO_ADD="curl gcc git make libc-dev ca-certificates tar" \ - --build-arg PKGS_TO_DEL="curl gcc git make libc-dev" \ - --build-arg PKGINIT="apt-get update" \ - --build-arg PKGADD="apt-get install -y --no-install-recommends" \ - --build-arg PKGDEL="apt-get purge -y" \ - --build-arg PKGCLEAN="apt-get clean" -``` - diff --git a/src/bulk_ln/bulk_ln.c b/src/bulk_ln/bulk_ln.c index c03c2d9..ae9e51c 100644 --- a/src/bulk_ln/bulk_ln.c +++ b/src/bulk_ln/bulk_ln.c @@ -1,7 +1,7 @@ /* This */ #include "bulk_ln.h" - + /* System */ #include <assert.h> #include <errno.h> @@ -59,45 +59,52 @@ struct BulkLn { static void printHelp(){ - printf("\n %s%s\n", strrchr(__FILE__, '/') + 1, " @ " STR_QUOT(PROJECT_VERSION) "\n" - "\n" - "Utility to create links. Writing a custom implementation of 'ln' got necessary\n" - "as we found no way to instruct 'ln' to create a few thousand links in an\n" - "acceptable amount of time. So we just re-invented that wheel so it better fits\n" - "our use-case ;)\n" - "\n" - "Takes paths (pairwise) from stdin (see --stdin for details) and creates a\n" - "hardlink for each pair from the 1st path to the 2nd.\n" - "\n" - "Options:\n" - "\n" + printf(" \n %s%s\n", strrchr(__FILE__, '/') + 1, " @ " STR_QUOT(PROJECT_VERSION) "\n" + " \n" + " Takes paths (pairwise) from stdin (see --stdin for details) and\n" + " creates a hardlink for each pair from the 1st path to the 2nd.\n" + " \n" + " Writing a custom implementation of 'ln' got necessary as we found no\n" + " way to instruct 'ln' to create a few thousand links in an acceptable\n" + " amount of time. Remind that wheels that do not fit should be\n" + " re-invented (yes, no matter how much they already exist!). So now we\n" + " have it. Our re-invented wheel that finally fits our use-case ;) \n" + " \n" + " See also\n" + " https://pubs.opengroup.org/onlinepubs/009695399/utilities/ln.html\n" + " for info about the original 'ln'.\n" + " \n" + " Options:\n" + " \n" " --stdin\n" " Read the path pairs to link from stdin. The format is like:\n" - "\n" + " \n" " <src-path> <tab> <dst-path> <newline>\n" - "\n" + " \n" " Example:\n" - "\n" + " \n" " origin/foo.txt\tnew/gugg.txt\n" " origin/bar.txt\tnew/da.txt\n" - "\n" + " \n" " HINT: Preferred <newline> is LF. But CRLF should work too.\n" - "\n" + " \n" " --quiet\n" - " Don't print status or similar stuff. Errors will still be printed to\n" - " stderr.\n" - "\n" + " Don't print status or similar stuff. Errors will still be\n" + " printed to stderr.\n" + " \n" " --verbose\n" - " Print stupid amount of logs. Usually only helpful for debugging. Should\n" - " NOT be combined with --quiet as this would be nonsense anyway.\n" - "\n" + " Print stupid amount of logs. Usually only helpful for debugging.\n" + " Should NOT be combined with --quiet as this would be nonsense\n" + " anyway.\n" + " \n" " --dry-run\n" " Will print the actions to stdout instead executing them.\n" - " HINT: Directory count in summary will be inaccurate in this mode.\n" - "\n" + " HINT: Directory count in summary will be inaccurate in this\n" + " mode.\n" + " \n" " --force\n" " Same meaning as in original 'ln' command.\n" - "\n"); + " \n"); } @@ -140,7 +147,7 @@ static int parseArgs( int argc, char**argv, BulkLn*bulkLn ){ bulkLn->isPrintEachMkdir = !0; } else{ - fprintf(stderr, "Unknown arg '%s'.\n", arg); + fprintf(stderr, "EINVAL: '%s'\n", arg); return -1; } } @@ -150,7 +157,7 @@ static int parseArgs( int argc, char**argv, BulkLn*bulkLn ){ * accidentally) invokes the utility wihout args. Further this also makes * the utility easier to extend wihout breaking everything. */ if( bulkLn->dataFilePath == NULL ){ - fprintf(stderr, "Arg '--stdin' missing. Try --help\n"); + fprintf(stderr, "EINVAL: '--stdin' missing.\n"); return -1; } @@ -232,7 +239,7 @@ static int mkdirs( char*path, BulkLn*bulkLn ){ } err = 0; - finally: +finally: return err; } @@ -272,7 +279,7 @@ static int createHardlink( char*srcPath, char*dstPath, BulkLn*bulkLn ){ bulkLn->createdLinksCount += 1; err = 0; - finally: +finally: return err; } @@ -304,7 +311,7 @@ static int onPathPair( char*srcPath, char*dstPath, BulkLn*bulkLn ){ if( err ){ err = -1; goto finally; } err = 0; - finally: +finally: return err; } @@ -353,7 +360,7 @@ static int parseDataFileAsPairPerLine( BulkLn*bulkLn ){ char *dstPath_end = buf + buf_len; for(;; --dstPath_end ){ if(unlikely( dstPath_end < buf )){ - fprintf(stderr, "IMHO cannot happen (@%s:%d)\n", __FILE__, __LINE__); + fprintf(stderr, "IMHO cannot happen %s:%d\n", __FILE__, __LINE__); err = -1; goto finally; } if( dstPath_end[0]=='\n' || dstPath_end[0]=='\0' || dstPath_end[0]=='\r' ){ @@ -379,7 +386,7 @@ static int parseDataFileAsPairPerLine( BulkLn*bulkLn ){ } err = 0; - finally: +finally: free(buf); return err; } @@ -413,7 +420,7 @@ int bulk_ln_main( int argc, char**argv ){ } err = 0; - finally: +finally: if( bulkLn->dataFd != NULL && bulkLn->dataFd != stdin ){ fclose(bulkLn->dataFd); } |