lecture-notes/init.sh

63 lines
2 KiB
Bash
Raw Normal View History

2022-02-15 23:24:20 +01:00
#!/bin/bash
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"
echo "The folder name must not contain the name 'template' or build will be aborted"
exit 1
fi
source config
# 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 " "
echo "YOUR GIVEN CONFIGURATION IS AS FOLLOWS: "
echo ""
cat config | tail -n 5
echo ""
read -p "ARE YOU SURE YOU WANT TO CONTINUE? (y/n) " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
exit 1
2022-02-15 23:51:27 +01:00
fi
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
cd template
2022-02-15 23:35:05 +01:00
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"
find -type f | xargs sed -i "s/\$term/$(printf '%s\n' "$term" | sed -e 's/[\/&]/\\&/g')/g"
2022-02-16 10:15:15 +01:00
cd ..
# clean up meta files
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 11:26:58 +01:00
mv template/* .
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
# 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-15 23:29:07 +01:00
}