lecture-notes/init.sh

58 lines
1.9 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 " "
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
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-15 23:58:47 +01:00
cat config
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-15 23:39:10 +01:00
rm init.sh
2022-02-15 23:58:47 +01:00
rm config
2022-02-16 10:15:15 +01:00
rm README.md
rm -rf .git
# move template files into this directory
2022-02-16 11:26:58 +01:00
mv template/* .
mv template/.* .
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
}