diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/archive | 43 | ||||
-rwxr-xr-x | bin/provision | 71 | ||||
-rwxr-xr-x | bin/provision-dict | 13 | ||||
-rwxr-xr-x | bin/provision-docker | 28 | ||||
-rwxr-xr-x | bin/provision-host | 84 | ||||
-rwxr-xr-x | bin/provision.R | 48 |
6 files changed, 287 insertions, 0 deletions
diff --git a/bin/archive b/bin/archive new file mode 100755 index 0000000..5b71ec8 --- /dev/null +++ b/bin/archive @@ -0,0 +1,43 @@ +#!/bin/bash +# +# Archiver +# + +# Parameters +BASENAME="`basename $0 | sed -e 's/\(.\)/\U\1/'`" +DIRNAME="`dirname $0`" +BASEDIR="$DIRNAME/.." +#ARCHIVE="$BASEDIR/archive" +ARCHIVE="archive" +REVISION="`git describe --tags 2> /dev/null || git log -1 --format=oneline | cut -d ' ' -f 1`" +REVFILE="$BASEDIR/compiled/revision" + +# Make sure the archive folder exist +mkdir -p $ARCHIVE + +# Check for previous build +if [ ! -e "$REVFILE" ]; then + echo "# $BASENAME: skipping: revision file not found" + exit +else + OLD_REVISION="`cat $REVFILE`" +fi + +# Check for non-null revision +if [ -z "$OLD_REVISION" ]; then + echo "# $BASENAME: skipping: old revision is null" + exit +fi + +# Check if it's a tag +if git tag | grep -q "^${OLD_REVISION}"; then + # Check if archive does not exists + if [ ! -d "$ARCHIVE/$OLD_REVISION" ]; then + echo "# $BASENAME: archiving $OLD_REVISION..." + cp -alf compiled $ARCHIVE/$OLD_REVISION + else + echo "# $BASENAME: revision $OLD_REVISION already archived" + fi +else + echo "# $BASENAME: not archiving: revision $OLD_REVISION is not a tag" +fi diff --git a/bin/provision b/bin/provision new file mode 100755 index 0000000..f438a5e --- /dev/null +++ b/bin/provision @@ -0,0 +1,71 @@ +#!/bin/bash +# +# Provisioner +# + +# Parameters +DIRNAME="`dirname $0`" +BOOKDOWN_PACKAGING="${BOOKDOWN_PACKAGING:-DEB}" + +# Dependencies +DEPENDENCIES="make" +DEPENDENCIES="$DEPENDENCIES texlive-latex-base texlive-latex-recommended texlive-latex-extra texlive-fonts-extra texlive-extra-utils texlive-xetex texlive-lang-portuguese vim-latexsuite" +DEPENDENCIES="$DEPENDENCIES pandoc pandoc-sidenote" +DEPENDENCIES="$DEPENDENCIES fonts-liberation fonts-linuxlibertine" +DEPENDENCIES="$DEPENDENCIES libfontconfig1-dev libharfbuzz-dev libfribidi-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev" +DEPENDENCIES="$DEPENDENCIES r-cran-rmarkdown r-cran-magick" +DEPENDENCIES="$DEPENDENCIES libpoppler-cpp-dev" +DEPENDENCIES="$DEPENDENCIES graphviz" +DEPENDENCIES="$DEPENDENCIES biber pybtex" + +# Additional BibTeX dependencies +#DEPENDENCIES="$DEPENDENCIES texlive-bibtex-extra" + +# For pdfcrop support +DEPENDENCIES="$DEPENDENCIES texlive-extra-utils" + +# Old dependencies +#DEPENDENCIES="$DEPENDENCIES python-yaml python-cheetah python-unidecode python-pycurl python-shortuuid" +#DEPENDNECIES="$DEPENDENCIES python-sphinx python-sphinx-bootstrap-theme python-sphinx-paramlinks python-sphinx-patchqueue python-sphinx-rtd-theme python-sphinx-gallery python-sphinxcontrib.bibtex-doc" +#DEPENDENCIES="$DEPENDENCIES pelican hugo jekyll" + +# Check for sudo +if [ "`whoami`" != "root" ]; then + SUDO="sudo" +fi + +# Configure Debian backports +if which trashman &> /dev/null; then + trashman install debian-backports +fi + +# Ensure an up-to-date system +$SUDO apt-get update && $SUDO apt-get dist-upgrade -y && \ + $SUDO apt-get autoremove -y && $SUDO apt-get clean + +# Install dependencies +$SUDO apt install -y $DEPENDENCIES + +# Additional software +#$SUDO apt install -y python3-pandocfilters + +# Try to install pandoc-citeproc, may be unavailable on Debian bookworm onwards +#$SUDO apt install -y pandoc-citeproc + +# Tufte CSS +#$SUDO apt install cabal-install +#$SUDO cabal update +#$SUDO cabal install pandoc-sidenote +#$SUDO apt install -y libghc-pandoc-sidenote-dev \ +# libghc-pandoc-sidenote-doc libghc-pandoc-sidenote-prof + +# Bookdown dependencies +$SUDO apt install -y libcurl4-openssl-dev libssl-dev + +if [ "$BOOKDOWN_PACKAGING" == "CRAN" ]; then + $SUDO $DIRNAME/provision.R +else + $SUDO apt install -y r-cran-bookdown + $SUDO apt install -y r-cran-pdftools + $SUDO Rscript -e 'install.packages("eulerr")' +fi diff --git a/bin/provision-dict b/bin/provision-dict new file mode 100755 index 0000000..a75ae71 --- /dev/null +++ b/bin/provision-dict @@ -0,0 +1,13 @@ +#!/bin/bash +# +# Provisioner for dictionaries +# + +# Check for sudo +if [ "`whoami`" != "root" ]; then + SUDO="sudo" +fi + +# Dictionaries +$SUDO apt install -y dict dict-gcide dict-freedict-eng-por \ + dict-freedict-eng-ell dict-freedict-eng-lat diff --git a/bin/provision-docker b/bin/provision-docker new file mode 100755 index 0000000..d24ea56 --- /dev/null +++ b/bin/provision-docker @@ -0,0 +1,28 @@ +#!/bin/bash +# +# Provisioner for Docker +# + +# Check for sudo +if [ "`whoami`" != "root" ]; then + SUDO="sudo" +fi + +# Parameters +# See https://wiki.debian.org/Backports#Finding_backports +COMPOSE_BACKPORT="`apt show docker-compose -a 2> /dev/null | grep backports | awk '{ print $3 }' | cut -d '/' -f 1`" + +# Ensure an up-to-date system +$SUDO apt-get update +$SUDO apt-get upgrade -y + +# Check for backport availability for Debian bookworm +if [ "$COMPOSE_BACKPORT" == "bookworm-backports" ]; then + COMPOSE_BACKPORTS="-t $COMPOSE_BACKPORT" +fi + +# Docker and docker-compose from distribution +$SUDO apt-get install $COMPOSE_BACKPORTS -y docker.io docker-compose + +# Put the regular user into docker group +$SUDO usermod -a -G docker $(whoami) diff --git a/bin/provision-host b/bin/provision-host new file mode 100755 index 0000000..16712fb --- /dev/null +++ b/bin/provision-host @@ -0,0 +1,84 @@ +#!/bin/bash +# +# Provisioner for a simple hosting environment +# + +# Parameters +PROJECT="${PROJECT:-bookup}" + +# Check for sudo +if [ "`whoami`" != "root" ]; then + SUDO="sudo" +fi + +# Apache +$SUDO apt install -y apache2 + +# Configure an Onion Service +if which trashman &> /dev/null; then + trashman install tor-onion-service +else + HIDDEN="/var/lib/tor/hidden/${PROJECT}" + + # Install Tor + $SUDO apt install -y tor + + # Tor config + cat <<-EOF | $SUDO tee -a /etc/tor/torrc > /dev/null +RunAsDaemon 1 +HiddenServiceDir $HIDDEN +HiddenServicePort 80 127.0.0.1:80 +EOF + + # Create folder structure + $SUDO mkdir -p $HIDDEN + $SUDO chmod -R 700 $HIDDEN + $SUDO chown -R debian-tor: $HIDDEN + + # Start Tor + $SUDO service tor restart +fi + +# Configure Onion Service virtual host +cat <<-EOF | $SUDO tee /etc/apache2/sites-available/onion.conf > /dev/null +<VirtualHost 127.0.0.1:80> + ServerName localhost + ServerAlias *.onion + DocumentRoot "/srv/shared/compiled" + + <Directory /srv/shared/compiled> + #AuthType Basic + #AuthName "Protected" + #AuthUserFile /srv/shared/.htpasswd + #Require valid-user + Options Indexes FollowSymLinks + AllowOverride All + Require all granted + </Directory> +</VirtualHost> +EOF + +# Configure local virtual host +cat <<-EOF | $SUDO tee /etc/apache2/sites-available/local.conf > /dev/null +<VirtualHost *:80> + ServerName ${PROJECT}.local + DocumentRoot "/srv/shared/compiled" + + <Directory /srv/shared/compiled> + #AuthType Basic + #AuthName "Protected" + #AuthUserFile /srv/shared/.htpasswd + #Require valid-user + Options Indexes FollowSymLinks + AllowOverride All + Require all granted + </Directory> +</VirtualHost> +EOF + +# Ensure that the DocumentRoot exists +$SUDO mkdir -p /srv/shared + +# Enable virtual host +$SUDO a2ensite onion local +$SUDO service apache2 restart diff --git a/bin/provision.R b/bin/provision.R new file mode 100755 index 0000000..a7b1bef --- /dev/null +++ b/bin/provision.R @@ -0,0 +1,48 @@ +#!/usr/bin/env Rscript +# +# Install bookdown and dependencies. +# See https://bookdown.org/yihui/bookdown/r-and-r-packages.html +# +# Environment variable "USE_DEVTOOLS" controls the way some +# packages are installed. Useful in situations like these: +# +# * https://github.com/r-lib/remotes/issues/641 +# * https://github.com/r-lib/remotes/issues/659 +# * https://github.com/r-lib/devtools/issues/1566 +# + +# Bookdown +if (Sys.getenv("USE_DEVTOOLS") == "FALSE") { + install.packages("bookdown", dependencies = TRUE) +} else { + if (!requireNamespace("devtools")) install.packages("devtools") + devtools::install_github("rstudio/bookdown") +} + +# PDF tools +# This adds support to knitr in the HTML output +# Requires libpoppler-cpp-dev and r-cran-magick +if (Sys.getenv("USE_DEVTOOLS") == "FALSE") { + install.packages("pdftools") +} else { + devtools::install_github("ropensci/pdftools") +} + +# For Euler and Venn diagrams +# See https://jolars.github.io/eulerr/ +install.packages("eulerr") + +# Tufte +install.packages('tufte') + +# Graphics support +install.packages('ggplot2') + +# The xfun package +# See https://bookdown.org/yihui/rmarkdown-cookbook/embed-file.html +# https://github.com/yihui/xfun +# https://yihui.org/xfun/ +#install.packages('xfun', repos = 'https://yihui.r-universe.dev') + +# Update everything +update.packages(ask = FALSE, checkBuilt = TRUE) |