Skip to content

Commit

Permalink
Replace ugly docker build env by qemu setup script.
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddenalpha committed Aug 24, 2023
1 parent f5432f6 commit e05741f
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 144 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.







60 changes: 60 additions & 0 deletions contrib/build-env-setup/README.md
Original file line number Diff line number Diff line change
@@ -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.






32 changes: 32 additions & 0 deletions contrib/build-env-setup/setup
Original file line number Diff line number Diff line change
@@ -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

35 changes: 0 additions & 35 deletions contrib/build-using-docker/Dockerfile

This file was deleted.

69 changes: 0 additions & 69 deletions contrib/build-using-docker/README.md

This file was deleted.

77 changes: 42 additions & 35 deletions src/bulk_ln/bulk_ln.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/* This */
#include "bulk_ln.h"

/* System */
#include <assert.h>
#include <errno.h>
Expand Down Expand Up @@ -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");
}


Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -232,7 +239,7 @@ static int mkdirs( char*path, BulkLn*bulkLn ){
}

err = 0;
finally:
finally:
return err;
}

Expand Down Expand Up @@ -272,7 +279,7 @@ static int createHardlink( char*srcPath, char*dstPath, BulkLn*bulkLn ){
bulkLn->createdLinksCount += 1;

err = 0;
finally:
finally:
return err;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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' ){
Expand All @@ -379,7 +386,7 @@ static int parseDataFileAsPairPerLine( BulkLn*bulkLn ){
}

err = 0;
finally:
finally:
free(buf);
return err;
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit e05741f

Please sign in to comment.