From f8943c6f2597101db46064435ef6a2af09cd0d79 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 6 Aug 2021 15:23:31 -0400 Subject: [PATCH] Fleshing out the command line options for run-citadel.sh --- Dockerfile | 48 +++++++++++++++++++++++++------------ ctdlvisor.c | 27 --------------------- run-citadel.sh | 64 +++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 86 insertions(+), 53 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8dc69f8..cf9baea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,5 @@ +# Dockerfile for Citadel + FROM bitnami/minideb:latest VOLUME /citadel-data @@ -5,25 +7,41 @@ VOLUME /citadel-data # Install prerequisites RUN install_packages make build-essential zlib1g-dev libldap2-dev libssl-dev gettext libical-dev libexpat1-dev curl libcurl4-openssl-dev git autoconf automake netbase libreadline-dev -# Download and build Citadel -WORKDIR /tmp/ctdl_build -RUN sh -c 'git clone git://git.citadel.org/appl/gitroot/citadel.git' -RUN sh -c 'cd /tmp/ctdl_build/citadel/libcitadel && ./bootstrap && ./configure --prefix=/usr && make && make install' -RUN sh -c 'cd /tmp/ctdl_build/citadel/citadel && ./bootstrap && ./configure && make && make install' -RUN sh -c 'cd /tmp/ctdl_build/citadel/webcit && ./bootstrap && ./configure && make && make install' -RUN sh -c 'cd /tmp/ctdl_build/citadel/textclient && ./bootstrap && ./configure --prefix=/usr && make && make install' -RUN sh -c 'cd /tmp && rm -vfr /tmp/ctdl_build' -RUN sh -c 'rm -vrf /usr/local/citadel/data /usr/local/citadel/files /usr/local/citadel/keys /usr/local/webcit/keys' +# Deploy "ctdlvisor", a small supervisor program which runs inside the container to wrangle the various services +ADD ctdlvisor.c /tmp -# ctdlvisor is a supervisor process that handles all of the components -ADD ctdlvisor.c /tmp/ctdl_build -RUN sh -c 'cd /tmp/ctdl_build && cc ctdlvisor.c -o /usr/local/bin/ctdlvisor' +# Download and build Citadel +RUN sh -c 'mkdir /tmp/ctdl_build && \ + cd /tmp/ctdl_build && \ + git clone git://git.citadel.org/appl/gitroot/citadel.git && \ + cd /tmp/ctdl_build/citadel/libcitadel && \ + ./bootstrap && \ + ./configure --prefix=/usr && \ + make && \ + make install && \ + cd /tmp/ctdl_build/citadel/citadel && \ + ./bootstrap && \ + ./configure && \ + make && \ + make install && \ + cd /tmp/ctdl_build/citadel/webcit && \ + ./bootstrap && \ + ./configure && \ + make && \ + make install && \ + cd /tmp/ctdl_build/citadel/textclient && \ + ./bootstrap && \ + ./configure --prefix=/usr --ctdldir=/citadel_data && \ + make && make install && \ + cd /tmp && \ + cc ctdlvisor.c -o /usr/local/bin/ctdlvisor && \ + rm -vf /tmp/ctdlvisor.c && \ + cd /tmp && \ + rm -vfr /tmp/ctdl_build && \ + rm -vrf /usr/local/citadel/data /usr/local/citadel/files /usr/local/citadel/keys /usr/local/webcit/keys' # Ports EXPOSE 25 80 110 119 143 443 465 504 563 587 993 995 2020 5222 -# We don't need the workdir anymore -RUN rm -fr /tmp/ctdl_build - # Let's go! ENTRYPOINT ["/usr/local/bin/ctdlvisor"] diff --git a/ctdlvisor.c b/ctdlvisor.c index 18b4202..ece2e9d 100644 --- a/ctdlvisor.c +++ b/ctdlvisor.c @@ -179,31 +179,6 @@ void main_loop(void) { } -void install_client_link(void) { // FIXME this is all furkokt and needs to be rethought now that it's docker and not appimage - - FILE *fp; - char path_to_link[PATH_MAX]; - snprintf(path_to_link, sizeof path_to_link, CTDL_DIR "citadel"); - fp = fopen(path_to_link, "w"); - if (!fp) { - fprintf(stderr, "%s\n", strerror(errno)); - return; - } - - fprintf(fp, "#!/bin/bash\n" - "export APPDIR=%s\n" - "export LD_LIBRARY_PATH=${APPDIR}/usr/bin:$LD_LIBRARY_PATH\n" - "export PATH=${APPDIR}/usr/bin:$PATH\n" - "exec citadel\n" - , - getenv("APPDIR") - ); - - fchmod(fileno(fp), 0755); - fclose(fp); -} - - int main(int argc, char **argv) { int a; int migrate_mode = 0; @@ -279,8 +254,6 @@ int main(int argc, char **argv) { webcit_pid = start_webcit(); // start WebCit HTTP webcits_pid = start_webcits(); // start WebCit HTTPS - install_client_link(); - main_loop(); } diff --git a/run-citadel.sh b/run-citadel.sh index 6ff9a03..a763998 100755 --- a/run-citadel.sh +++ b/run-citadel.sh @@ -5,18 +5,60 @@ # The container expects a persistent volume called "citadel-data" in which it will keep everything. # The remainder of the container is ephermal and can be deleted at any time. -# If you want to keep your Citadel data in a specific directory on the host, -# set CTDL_VOL to "bind" and CTDL_DIR to the full pathname of that directory. -# This is what you want if you are switching from Easy Install to Docker. -# -#CTDL_VOL=bind -#CTDL_DIR=/usr/local/citadel -# If you want to keep your Citadel data in a Docker volume, -# set CTDL_VOL to "volume" and CTDL_DIR to the name of the volume. -# -CTDL_VOL=volume -CTDL_DIR=citadel-data +# Parse the command line arguments + +migrate_mode=false +database_cleanup_mode=false +volume_mode=false +bind_mode=false + +while getopts ":mdv:h:" o +do + case "${o}" in + m) + echo "migrate mode" + migrate_mode=true + ;; + d) + echo "database cleanup mode"; + database_cleanup_mode=true + ;; + v) + volume_mode=true + CTDL_DIR=${OPTARG} + ;; + h) + bind_mode=true + CTDL_DIR=${OPTARG} + ;; + *) + echo "$0: usage: $0 [-v volume_name] [-h home_directory] [-m] [-v] container_image_name [other parameters]" + exit 1 + ;; + esac +done +shift $((OPTIND-1)) + +if ( ${volume_mode} && ${bind_mode} ) ; then + echo "$0: -v and -h cannot both be specified." + exit 2 +fi + +if ${volume_mode} ; then + CTDL_VOL=volume +elif ${bind_mode} ; then + CTDL_VOL=bind +else + volume_mode=true + CTDL_VOL=volume + CTDL_DIR=citadel-data +fi + +if ( ${migrate_mode} && ${database_cleanup_mode} ) ; then + echo "$0: -m and -d cannot both be specified." + exit 3 +fi docker version >/dev/null 2>&1 || { echo Docker engine is not installed on this host. -- 2.30.2