diff --git a/Dockerfile b/Dockerfile index fc6bab3..0c354be 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,5 +15,8 @@ COPY --chown=ltxuser:ltxgroup startup.sh /app/startup.sh COPY --chown=ltxuser:ltxgroup setupFiles /app/setupFiles RUN chmod +x /app/startup.sh /app/setupFiles/install.sh +# Versioning file, positioned to run if project files changed. +# Change something below this to update the version. +RUN date +"%s" > /app/setupFiles/buildDate # Startup command CMD [ "sh", "-c", "/app/startup.sh ${mainFile}" ] diff --git a/README.md b/README.md index c1a7ab4..c72ab2b 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Use the following command to attach the project folder to the built container. docker run --rm -it -e "mainFile=" -v :/app/project:z --user 1000:1000 phanipavank/autoltx:latest ``` -replace `` with the primary tex file to compile, `` with the path to the project folder. +Replace `` with the primary tex file to compile, `` with the path to the project folder. This will compile your project whenever a change is observed in the `mainTEXfile` file. diff --git a/setupFiles/install.sh b/setupFiles/install.sh index 58e5483..9e1d650 100644 --- a/setupFiles/install.sh +++ b/setupFiles/install.sh @@ -1,6 +1,9 @@ #! /bin/bash # Adapted from github.com/gkilleen33/overleaf-offline under the MIT license +# .autoltx file contents as per line numbers: +# 1. build date in epoch, for checking for updates. + # CD into the main directory cd /app/project || exit 2 @@ -8,29 +11,47 @@ if test -d "pdf/"; then rm -r pdf/ fi -# Update old installation -if test -f ".autoltxXenon"; then # Intentional wrong file name checking, to ensure the files are updated everytime the container starts. To implement version checking in later version. - echo AutoLTX already installed, skipping steup -else - if test -f ".gitignore"; then - # Adding build files to .gitignore - grep -qxF 'pdf/' .gitignore || echo 'pdf/' >> .gitignore - grep -qxF 'latexmkrc' .gitignore || echo 'latexmkrc' >> .gitignore - grep -qxF 'compile.sh' .gitignore || echo 'compile.sh' >> .gitignore - grep -qxF '.autoltx' .gitignore || echo '.autoltx' >> .gitignore - grep -qxF 'output.pdf' .gitignore || echo 'output.pdf' >> .gitignore - touch .autoltx - echo Configuring AutoLTX for this project +requiresUpdate=0 +settingsExists=0 + +# Check for updates +if test -f "/app/project/.autoltx"; then + buildDate=`cat /app/setupFiles/buildDate` + installedVersion=`sed -n "1p" /app/project/.autoltx` + settingsExists=1 + if [[ installedVersion -eq buildDate ]]; then + requiresUpdate=0 + echo AutoLTX already installed, skipping steup... else - # Creating .gitignore file - printf 'pdf/\nlatexmkrc\ncompile.sh\n.autoltx\noutput.pdf\n' >> .gitignore - touch .autoltx + requiresUpdate=1 + echo Found old AutoLTX files, updating... fi - - # Add latexmk rc file to build files - cp /app/setupFiles/latexmkrc /app/project/ - - # Add compile script to build files - cp /app/setupFiles/compile.sh /app/project - chmod +x compile.sh +else + echo "1" > /app/project/.autoltx + requiresUpdate=1 + echo AutoLTX not installed, configuring... +fi + +# Update files if necessary +if [[ requiresUpdate -eq 1 ]]; then + # Add latexmk rc file to build files + cp /app/setupFiles/latexmkrc /app/project/ + # Add compile script to build files + cp /app/setupFiles/compile.sh /app/project/ + + chmod +x compile.sh + + if test -f "/app/project/.gitignore"; then + # Adding build files to .gitignore + grep -qxF 'pdf/' .gitignore || echo 'pdf/' >> .gitignore + grep -qxF 'latexmkrc' .gitignore || echo 'latexmkrc' >> .gitignore + grep -qxF 'compile.sh' .gitignore || echo 'compile.sh' >> .gitignore + grep -qxF '.autoltx' .gitignore || echo '.autoltx' >> .gitignore + grep -qxF 'output.pdf' .gitignore || echo 'output.pdf' >> .gitignore + else + # Creates .gitignore file + echo Configuring .gitignore for this project + printf 'pdf/\nlatexmkrc\ncompile.sh\n.autoltx\noutput.pdf\n' >> /app/project/.gitignore + fi + sed -i "1s/.*/$buildDate/" /app/project/.autoltx fi diff --git a/startup.sh b/startup.sh index bb6fa2b..f999a68 100644 --- a/startup.sh +++ b/startup.sh @@ -1,7 +1,5 @@ #! /bin/bash -echo Running as user: $USER - if [[ -z ${1} ]]; then echo Main file not spicified echo Restart the container with proper arguments @@ -24,6 +22,7 @@ fi # start auto compile loop echo Starting AutoLTX... +echo sleep 3 cd /app/project || exit 2