Skip to content

Commit

Permalink
Update wizard (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
martialblog authored Dec 13, 2023
1 parent 0ee9afb commit 17f98e6
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 14 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
stats
.vagrant
*.pdf
.DS_Store
*.pdf
stats/
static/
25 changes: 25 additions & 0 deletions global/Pre/Title/04_Licence.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
!SLIDE printonly

# Licence

This work is licensed under a Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) License.

This is a human-readable summary of (and not a substitute for) the license.

You are free to:

* Share — copy and redistribute the material in any medium or format
* Adapt — remix, transform, and build upon the material for any purpose, even commercially.

Under the following terms:

* Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
* ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
* No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.

The licensor cannot revoke these freedoms as long as you follow the license terms.

Full Licence:

* https://creativecommons.org/licenses/by-sa/4.0/
* https://creativecommons.org/licenses/by-sa/4.0/deed.de
64 changes: 51 additions & 13 deletions global/wizard.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
#!/bin/bash
DIR=$(pwd)
CLANG=${CLANG:-C.UTF-8}
IMAGE=${IMAGE:-netways/showoff:0.19.6}
IMAGE=${IMAGE:-netways/showoff:0.20.4}
CNAME=${CNAME:-showoff}
TRAINING=${TRAINING:-$(basename "$DIR")}
DOCKER=${DOCKER:-$(command -v docker)}
RUNTIME=${RUNTIME:-$(command -v docker)}
GIT=${GIT:-$(command -v git)}
SCRIPT_DIR=$(cd $(dirname $0); pwd -P)
NO_RESET=${NO_RESET:-""}

# Functions

# Run given command in the showoff container
execdocker () {
if [[ -n $($DOCKER ps -aq -f name=$CNAME 2> /dev/null) ]]; then
$DOCKER rm -f $CNAME 2> /dev/null
if [[ -n $($RUNTIME ps -aq -f name=$CNAME 2> /dev/null) ]]; then
$RUNTIME rm -f $CNAME 2> /dev/null
fi

$DOCKER run \
case $($RUNTIME -v) in
*podman*) USERNS=keep-id;;
*) USERNS=host;;
esac

$RUNTIME run \
-it \
--name=$CNAME \
--rm \
-p 9090:9090 \
--user $(id -u) \
--userns=$USERNS \
-v "$DIR:/training:z" \
-e "LANG=$CLANG" \
-e "LANGUAGE=$CLANG" \
Expand All @@ -29,34 +35,46 @@ execdocker () {
$1
}

# Generate handouts as showoff HTML and convert HTML to PDF
printhandouts () {
echo -e "\n--- RUN SHOWOFF STATIC FOR HANDOUTS ---"
execdocker "showoff static print"
# Removes showoff's Section markers for PDF output
sed -i 's/~~~.*~~~ //g' static/index.html
echo -e "\n--- RUN WKHTMLTOPDF FOR HANDOUTS ---"
execdocker "wkhtmltopdf --load-error-handling ignore -s A5 --print-media-type --footer-left [page] --footer-right ©NETWAYS static/index.html ${TRAINING}_${1}-handouts.pdf"
execdocker "wkhtmltopdf --enable-local-file-access --load-error-handling ignore -s ${FORMAT} --print-media-type --footer-left [page] --footer-right ©NETWAYS static/index.html ${TRAINING}_${1}_${FORMAT}-handouts.pdf"
}

# Generate exercises as showoff HTML and convert HTML to PDF
printexercises () {
echo -e "\n--- RUN SHOWOFF STATIC FOR EXERCISES ---"
execdocker "showoff static supplemental exercises"
# Removes showoff's Section markers for PDF output
sed -i 's/~~~.*~~~ //g' static/index.html
echo -e "\n--- RUN WKHTMLTOPDF FOR EXERCISES ---"
execdocker "wkhtmltopdf --load-error-handling ignore -s A5 --print-media-type --footer-left [page] --footer-right ©NETWAYS static/index.html ${TRAINING}_${1}-exercises.pdf"
execdocker "wkhtmltopdf --enable-local-file-access --load-error-handling ignore -s ${FORMAT} --print-media-type --footer-left [page] --footer-right ©NETWAYS static/index.html ${TRAINING}_${1}_${FORMAT}-exercises.pdf"
}

# Generate solutions as showoff HTML and convert HTML to PDF
printsolutions () {
echo -e "\n--- RUN SHOWOFF STATIC FOR SOLUTIONS ---"
execdocker "showoff static supplemental solutions"
# Removes showoff's Section markers for PDF output
sed -i 's/~~~.*~~~ //g' static/index.html
echo -e "\n--- RUN WKHTMLTOPDF FOR SOLUTIONS ---"
execdocker "wkhtmltopdf --load-error-handling ignore -s A5 --print-media-type --footer-left [page] --footer-right ©NETWAYS static/index.html ${TRAINING}_${1}-solutions.pdf"
execdocker "wkhtmltopdf --enable-local-file-access --load-error-handling ignore -s ${FORMAT} --print-media-type --footer-left [page] --footer-right ©NETWAYS static/index.html ${TRAINING}_${1}_${FORMAT}-solutions.pdf"
}

setlayout () {
find . -maxdepth 1 -type l -name *.css -delete
ln -s global/layouts/$1.css .
}

if [[ ! -x $DOCKER ]]; then
echo "Command 'docker' not found, exit"
# Create reference if it doesn't exist
ln -sf . global

if [[ ! -x $RUNTIME ]]; then
echo "Command '${RUNTIME}' not found, exit"
exit 1
fi

Expand Down Expand Up @@ -96,6 +114,27 @@ esac

setlayout $LAYOUT

echo -e "\n### FORMAT ###"

echo -e "
[1] A5
[2] A4\n"

FORMAT_DEFAULT=1
read -p "Which format? [1-2] (Default: "$FORMAT_DEFAULT"): " FORMAT
FORMAT="${FORMAT:-$FORMAT_DEFAULT}"

while [[ $FORMAT != [1-2] ]]; do
echo "Invalid option, try again..."
read -p "Which format? [1-2] (Default: "$FORMAT_DEFAULT"): " FORMAT
FORMAT="${FORMAT:-$FORMAT_DEFAULT}"
done

case "$FORMAT" in
1) FORMAT=A5;;
2) FORMAT=A4;;
esac

echo -e "\n### MODE ###"

echo -e "
Expand Down Expand Up @@ -143,4 +182,3 @@ elif [[ $MODE == 2 ]]; then
printsolutions $VERSION;;
esac
fi

0 comments on commit 17f98e6

Please sign in to comment.