Skip to content

Commit

Permalink
testing new section headers
Browse files Browse the repository at this point in the history
  • Loading branch information
devsecfranklin committed May 19, 2024
1 parent ab6232d commit c0018e1
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 99 deletions.
9 changes: 4 additions & 5 deletions .admin/bin/formatting.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ function path_setup() {
fi
}


function shell_script_fmt() {
echo -e "${CYAN}Formatting shell scripts...${NC}"
shfmt -i 2 -l -w ../bootstrap.sh
Expand All @@ -76,15 +75,15 @@ function convert_rst_to_md() {
fi
}

function format_markdown(){
function format_markdown() {
FILES=*.md
for f in $FILES; do
filename="${f%.*}"
echo "Removing spaces from ${filename}.md"
cat ${filename}.md | tr -s ' ' > /tmp/tmp_file
cat ${filename}.md | tr -s ' ' >/tmp/tmp_file
mv /tmp/tmp_file ${filename}.md
echo "Running markdown lint on ${filename}.md"
mdl ${filename}.md
mdl ${filename}.md
done
}

Expand All @@ -94,4 +93,4 @@ function main() {
format_markdown
}

main "$@"
main "$@"
89 changes: 52 additions & 37 deletions .admin/bin/generate_book.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,66 +27,81 @@ NC='\033[0m' # No Color

# --- Some config Variables ----------------------------------------
CATEGORIES=("APPETIZERS" "BREAKFAST" "COOKWARE" "DESSERTS" "DRINKS" "ENTREES" "SAUCES" "SIDES" "SNACKS")
LOGGING_DIR="/tmp/cookbook/log"
MY_DATE=$(date '+%Y-%m-%d-%H')
RAW_OUTPUT="generate_cookbook_${MY_DATE}.txt" # log file name
TEX_OUTPUT="cookbook/hacker_cookbook.tex"

function path_setup() {
# path madness
CURRENT_DIR="${PWD}"
#echo -e "${LGREEN}Current dir: ${LCYAN}${CURRENT_DIR}${NC}" | tee -a "${RAW_OUTPUT}"
PROG_DIR="$0"

SCRIPT_DIR=$(echo $PROG_DIR | sed 's|\(.*\)/.*|\1|')
#echo -e "${LGREEN}Found script dir: ${LCYAN}${SCRIPT_DIR}${NC}" | tee -a "${RAW_OUTPUT}"
SUB_DIR=$(echo $SCRIPT_DIR | rev | cut -d'/' -f2- | rev)
#echo "Sub dir: $SUB_DIR"
if [ "$SUB_DIR" != "bin" ]; then
LOGGING_DIR="$CURRENT_DIR/$SUB_DIR/logs"
DATA_DIR="$CURRENT_DIR/$SUB_DIR/data"
else
LOGGING_DIR="$CURRENT_DIR/logs"
DATA_DIR="$CURRENT_DIR/data"
MY_PWD="${PWD}"
RAW_OUTPUT="${LOGGING_DIR}/generate_cookbook_${MY_DATE}.txt" # log file name
TEX_DIR="/tmp/cookbook"
TEX_OUTPUT="${TEX_DIR}/hacker_cookbook.tex"

function directory_setup() {

# ##### LaTeX #####
if [ ! -d "${TEX_DIR}" ]; then
#echo -e "${LRED}Creating LaTeX dir: ${LCYAN}${TEX_DIR}${NC}"
mkdir -p ${TEX_DIR}
fi

if [ -d "${LOGGING_DIR}" ]; then
RAW_OUTPUT="${LOGGING_DIR}/${RAW_OUTPUT}"
echo -e "\n${LCYAN}------------------ Starting Backup Tool ------------------${NC}" | tee -a "${RAW_OUTPUT}"
echo -e "${LGREEN}Found log dir: ${LCYAN}${LOGGING_DIR}${NC}" | tee -a "${RAW_OUTPUT}"
echo -e "${LGREEN}Log file path is: ${LCYAN}${RAW_OUTPUT}${NC}" | tee -a "${RAW_OUTPUT}"
echo -e "${LGREEN}LaTeX file path is: ${LCYAN}${TEX_OUTPUT}${NC}" | tee -a "${RAW_OUTPUT}"
else
echo -e "${LRED}Did not find log dir: ${LCYAN}${RAW_OUTPUT}${NC}"
LOGGING_DIR="."
RAW_OUTPUT="${LOGGING_DIR}/${RAW_OUTPUT}"
# ##### Logging #####
if [ ! -d "${LOGGING_DIR}" ]; then
#echo -e "${LRED}Creating log dir: ${LCYAN}${LOGGING_DIR}${NC}"
mkdir -p ${LOGGING_DIR}
fi

# output the results
echo -e "\n${LCYAN}------------------ Building Cookbook ------------------${NC}" | tee -a "${RAW_OUTPUT}"
echo -e "${LGREEN}Log file path is: ${LCYAN}${RAW_OUTPUT}${NC}" | tee -a "${RAW_OUTPUT}"
echo -e "${LGREEN}LaTeX directory is: ${LCYAN}${TEX_DIR}${NC}" | tee -a "${RAW_OUTPUT}"
}

# The frontmatter includes ToC, colophon, etc.
function frontmatter() {
cat ${CURRENT_DIR}/cookbook/frontmatter/header.tex \
${CURRENT_DIR}/cookbook/frontmatter/frontmatter.tex | tee -a "${TEX_OUTPUT}"
echo -e "${LGREEN}Adding frontmatter...${NC}" | tee -a "${RAW_OUTPUT}"
cp .admin/tex/preamble.tex ${TEX_DIR}
cat .admin/tex/frontmatter/header.tex \
.admin/tex/frontmatter/frontmatter.tex | tee -a "${TEX_OUTPUT}"
echo -e "\n" | tee -a "${TEX_OUTPUT}"
}

# the recipes
function mainmatter() {
cat ${CURRENT_DIR}/cookbook/mainmatter/mainmatter.tex | tee -a "${TEX_OUTPUT}"
COUNTER=0
echo -e "${LGREEN}Adding mainmatter...${NC}" | tee -a "${RAW_OUTPUT}"
cat .admin/tex/mainmatter/mainmatter.tex | tee -a "${TEX_OUTPUT}"

for i in ${CATEGORIES[@]}; do
THESE_FILES=$(ls ../${i}/*.md)
cp -Rp ${i} ${TEX_DIR}

# start with the section header
# convert section headers to tex files

THESE_FILES=$(ls ${TEX_DIR}/${i}/*.md)
for j in $THESE_FILES; do
echo "\markdownInput{../${j}}"
sed -i -e "s/images\//${i}\/images\//g" ${j}
echo "\markdownInput{${j}}" | tee -a "${TEX_OUTPUT}"
((COUNTER+=1)) # increment recipe count
done
done
}

function backmatter() {
cat ${CURRENT_DIR}/cookbook/backmatter/backmatter.tex \
${CURRENT_DIR}/cookbook/backmatter/end.tex | tee -a "${TEX_OUTPUT}"
echo -e "${LGREEN}Adding backmatter...${NC}" | tee -a "${RAW_OUTPUT}"
cat .admin/tex/backmatter/backmatter.tex \
.admin/tex/backmatter/end.tex | tee -a "${TEX_OUTPUT}"
}

function main() {
path_setup
directory_setup

# remove any stale output file
if [ -f "${TEX_OUTPUT}" ]; then rm ${TEX_OUTPUT} && touch ${TEX_OUTPUT}; fi

frontmatter
mainmatter
backmatter

cp ${TEX_OUTPUT} ${MY_PWD}/.admin/tex
cd ${TEX_DIR} && latexmk -pdf -file-line-error -interaction=nonstopmode -synctex=1 -shell-escape hacker_cookbook
}

main "$@"
54 changes: 0 additions & 54 deletions .admin/cookbook/hacker_cookbook.tex

This file was deleted.

2 changes: 1 addition & 1 deletion .admin/cookbook/Makefile.am → .admin/tex/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ clean:
rm -rf _build *.egg-info
@find . -name '*.pyc' | xargs rm -rf
@find . -name '__pycache__' | xargs rm -rf
@for trash in *.aux *.bbl *.blg *.lof *.log *.lot *.out *.pdf *.synctex.gz *.toc ; do \
@for trash in *.aux *.bbl *.blg *.err *.fdb_latexmk *.fls *.idx *.lof *.log *.lot *.lua *.out *.pdf *.synctex.gz *.toc Makefile Makefile.in _markdown_hacker_cookbook; do \
if [ -f "$$trash" ]; then rm -rf $$trash ; fi ; \
done

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.swp
*.pdf
_build/
hacker_cookbook.tex
**/logs/*
**/_markdown_hacker_cookbook/*

Expand Down
File renamed without changes.
7 changes: 5 additions & 2 deletions CREDITS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Credits
=======
# Credits

- [This link shows who worked on this project](https://github.com/DEAD10C5/1337-Noms-The-Hacker-Cookbook/graphs/contributors)

These folks have added their recipes to the project:

- [@iHeartMalware](https://twitter.com/iheartmalware)
- Organizing the project
Expand Down

0 comments on commit c0018e1

Please sign in to comment.