2022-02-15 23:24:20 +01:00
|
|
|
#!/bin/bash
|
2022-02-16 12:23:53 +01:00
|
|
|
|
|
|
|
set -e # Exit with error code if subcommand does
|
|
|
|
|
2022-02-16 10:15:15 +01:00
|
|
|
# safety first
|
2022-02-15 23:51:27 +01:00
|
|
|
if [[ $(pwd) == *template* ]]
|
|
|
|
then
|
|
|
|
echo "Don't run this in the template directory!"
|
|
|
|
echo "Rename the current folder or edit init.sh to do this anyways"
|
2022-02-16 12:00:42 +01:00
|
|
|
echo "The folder name must not contain the name 'template' or build will be aborted"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# More safety second
|
|
|
|
echo "--------------------------------------------------------"
|
|
|
|
echo "THIS SCRIPT WILL NOW IRREVOCABLY DESTROY THIS TEMPLATE "
|
|
|
|
echo "REPOSITORY AND REPLACE IT WITH A NEW ONE WITH YOUR GIVEN"
|
|
|
|
echo "PARAMETERS IN 'config'. "
|
|
|
|
echo "ALL PRIOR DATA, INCLUDING BUT NOT LIMITED TO THE GIT "
|
|
|
|
echo "HISTORY IN THIS DIRECTORY AND ALL ITS SUBDIRECTORIES "
|
|
|
|
echo "WILL BE LOST. "
|
|
|
|
echo " "
|
2022-02-16 12:03:53 +01:00
|
|
|
echo "YOUR GIVEN CONFIGURATION IS AS FOLLOWS: "
|
|
|
|
echo ""
|
|
|
|
cat config | tail -n 5
|
|
|
|
echo ""
|
2022-02-16 12:00:42 +01:00
|
|
|
|
2022-02-16 12:03:53 +01:00
|
|
|
read -p "ARE YOU SURE YOU WANT TO CONTINUE? (y/n) " -n 1 -r
|
2022-02-16 12:00:42 +01:00
|
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]
|
|
|
|
then
|
|
|
|
exit 1
|
2022-02-15 23:51:27 +01:00
|
|
|
fi
|
2022-02-16 12:03:53 +01:00
|
|
|
echo "" # Move to new line
|
2022-02-16 10:15:15 +01:00
|
|
|
|
2022-02-15 23:39:10 +01:00
|
|
|
{ ## DO NOT REMOVE THIS OR EVERYTHING BLOWS UP
|
2022-02-16 10:15:15 +01:00
|
|
|
|
2022-02-16 12:26:00 +01:00
|
|
|
# Read in config as environment variables
|
|
|
|
source config
|
|
|
|
|
|
|
|
# clean up meta files from template repository
|
2022-02-16 12:14:56 +01:00
|
|
|
rm init.sh config README.md LICENSE
|
2022-02-16 10:15:15 +01:00
|
|
|
rm -rf .git
|
|
|
|
|
|
|
|
# move template files into this directory
|
2022-02-16 13:03:04 +01:00
|
|
|
ls -a template | sed -r '/^\.+$/'d | xargs -I '{}' mv template/'{}' .
|
2022-02-16 12:07:40 +01:00
|
|
|
rmdir template
|
|
|
|
|
|
|
|
# Rename files
|
2022-02-16 10:15:15 +01:00
|
|
|
mv mainfile.tex $mainfile.tex
|
|
|
|
mv stylefile.sty $stylefile.sty
|
|
|
|
|
2022-02-16 12:26:00 +01:00
|
|
|
# replace config parameters
|
|
|
|
find -type f | xargs sed -i "s/\$mainfile/$(printf '%s\n' "$mainfile" | sed -e 's/[\/&]/\\&/g')/g"
|
|
|
|
find -type f | xargs sed -i "s/\$course/$(printf '%s\n' "$course" | sed -e 's/[\/&]/\\&/g')/g"
|
|
|
|
find -type f | xargs sed -i "s/\$stylefile/$(printf '%s\n' "$stylefile" | sed -e 's/[\/&]/\\&/g')/g"
|
|
|
|
find -type f | xargs sed -i "s/\$repo/$(printf '%s\n' "$repo" | sed -e 's/[\/&]/\\&/g')/g"
|
2023-10-07 13:32:20 +02:00
|
|
|
find -type f | xargs sed -i "s/\$namespace/$(printf '%s\n' "$namespace" | sed -e 's/[\/&]/\\&/g')/g"
|
2022-02-16 12:26:00 +01:00
|
|
|
find -type f | xargs sed -i "s/\$term/$(printf '%s\n' "$term" | sed -e 's/[\/&]/\\&/g')/g"
|
2023-10-07 13:32:20 +02:00
|
|
|
find -type f | xargs sed -i "s/\$lecturer/$(printf '%s\n' "$lecturer" | sed -e 's/[\/&]/\\&/g')/g"
|
|
|
|
find -type f | xargs sed -i "s/\$assistant/$(printf '%s\n' "$assistant" | sed -e 's/[\/&]/\\&/g')/g"
|
|
|
|
find -type f | xargs sed -i "s/\$author/$(printf '%s\n' "$author" | sed -e 's/[\/&]/\\&/g')/g"
|
2023-10-07 13:45:21 +02:00
|
|
|
find -type f | xargs sed -i "s/\$gitlab/$(printf '%s\n' "$gitlab" | sed -e 's/[\/&]/\\&/g')/g"
|
2022-02-16 12:26:00 +01:00
|
|
|
|
2022-02-16 10:15:15 +01:00
|
|
|
# init new repo
|
2022-02-15 23:39:10 +01:00
|
|
|
git init
|
2022-02-16 00:14:00 +01:00
|
|
|
git submodule add https://gitlab.com/latexci/packages/LatexPackagesBuild.git
|
|
|
|
git submodule foreach git checkout master-build
|
2022-02-16 00:22:29 +01:00
|
|
|
git add .
|
2022-02-15 23:39:10 +01:00
|
|
|
git commit -m "initial commit"
|
2022-02-16 12:26:00 +01:00
|
|
|
|
2022-02-15 23:29:07 +01:00
|
|
|
}
|