%
% forksand-it-manual.tex
% Main LaTeX document for formatting forksand-it-manual
%
% Fork Sand IT Manual
%
% Copyright (C) 2018, Fork Sand, Inc.
% Copyright (C) 2017, Jeff Moe
%
% Document template:
% Copyright (C) 2018, Fork Sand, Inc.
% Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017 Aleph Objects, Inc.
% Copyright (C) 2009, 2010 Jeff Moe
%
% This document is licensed under the Creative Commons Attribution 4.0
% International Public License (CC BY-SA 4.0) by Fork Sand, Inc.
%

%%% XXX NOTE
%%% Glossaries and indices are broken:
%%% https://sharelatex.tenderapp.com/help/discussions/questions/19378-glossaries-indices-and-speed
%%% XXX NOTE

% LaTeX Docs:
% http://en.wikibooks.org/wiki/Category:LaTeX

% LaTeX Memoir Class
% Docs: /usr/share/doc/texlive-doc/latex/memoir/memman.pdf
\special{pdf:minorversion 5}
%\pdfminorversion=6          %   Make pdf include minor version tolerant
%\pdfinclusioncopyfonts=1    %   Make pdf include minor version tolerant
\documentclass[twoside,10pt,openright,final,english,table]{memoir}

\usepackage[table]{xcolor}
\usepackage{etoolbox}
\makeatletter
\def\gnewcommand{\g@star@or@long\gnew@command}
\def\grenewcommand{\g@star@or@long\grenew@command}
\def\g@star@or@long#1{% 
  \@ifstar{\let\l@ngrel@x\global#1}{\def\l@ngrel@x{\long\global}#1}}
\def\gnew@command#1{\@testopt{\@gnewcommand#1}0}
\def\@gnewcommand#1[#2]{%
  \kernel@ifnextchar [{\@gxargdef#1[#2]}%
                {\@argdef#1[#2]}}
\let\@gxargdef\@xargdef
\patchcmd{\@gxargdef}{\def}{\gdef}{}{}
\let\grenew@command\renew@command
\patchcmd{\grenew@command}{\new@command}{\gnew@command}{}{}
\makeatother

\usepackage{tikz}
\usetikzlibrary{shadows,shapes,arrows,chains,calc,decorations.pathmorphing,patterns,trees,positioning,automata,fit}
% This breaks things, but would be great to use
%\usepackage{tikz-qtree,tikz-qtree-compat}
\usepackage{rotating}
\usepackage{forest}

\usetikzlibrary{arrows,shapes}
\usetikzlibrary{positioning,calendar,er}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shapes.geometric}

% Source code highlighting
\usepackage{mdframed} % /usr/share/doc/texlive-doc/latex/mdframed/mdframed.pdf
\usepackage{minted}   % /usr/share/doc/texlive-doc/latex/minted/minted.pdf
\setminted{autogobble, breaklines, breakanywhere, breakautoindent, funcnamehighlighting,style=manni,fontsize=\scriptsize}
% fontsize
\setmintedinline{breaklines, breakanywhere}
\surroundwithmdframed{minted}
\mdfsetup{roundcorner=10pt,
linewidth=3pt,
linecolor=ao-light-blue,
backgroundcolor=white,
leftmargin=1cm,rightmargin=1cm
}

\usepackage{longtable}
\usepackage{tabu}
\usepackage{datatool}
\DTLsetseparator{,}
\DTLloaddb{sharkforkorder}{resources/spreadsheets/sharkfork_order.csv}
\providecommand\includedDBName{sharkforkorder}
\newcommand{\DTLfetchrelax}[2]{ {\let\_\relax \DTLfetch{\includedDBName}{1}{#1}{#2}} }
\usepackage{smartdiagram}
%\usepackage{svg}
\usesmartdiagramlibrary{additions}
\usepackage{comment}  % /usr/share/doc/texlive-doc/latex/comment/comment.pdf
\usepackage{pdfpages} % Be able to include pdf
\usepackage{pict2e} 
\usepackage{graphicx} % /usr/share/doc/texlive-doc/latex/graphics/graphicx.pdf
%\usepackage{epstopdf} % /usr/share/doc/texlive-doc/latex/oberdiek/epstopdf.pdf
% http://www.tug.org/applications/hyperref/manual.html
% /usr/share/doc/texlive-doc/latex/hyperref/hyperref.pdf
\usepackage[colorlinks=true,linkcolor=ao-dark-orange,urlcolor=ao-dark-orange]{hyperref}
%\usepackage{url} % /usr/share/doc/texlive-doc/latex/url/url.pdf % Use hyperref.
\graphicspath{{./resources/}{./resources/images/}{./resources/drawings/}}

\usepackage
  [
  %  acronym,
  %  %nopostdot,
  %  toc,
  %  shortcuts,
  %  xindy
  automake
  ]
  {glossaries-extra}
\renewcommand*{\glstextformat}[1]{\textcolor{secondary-dark-brown}{\textbf{#1}}}
%\makeindex
%\makeglossary
\makeglossaries

\usepackage{color} % Docs: /usr/share/doc/texlive-latex-base-doc/latex/graphics/grfguide.pdf
\usepackage{colortbl}
%\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}

%%% PREAMBLE FONTS %%%
% For XeTeX
% http://www.ctan.org/pkg/fontspec
% http://mirrors.ctan.org/macros/latex/contrib/fontspec/fontspec.pdf
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX} % To support LaTeX quoting style
\setmainfont{lmroman12}[
    Extension=.otf ,
    UprightFont = *-regular ,
    SmallCapsFont = *-regular ,
    BoldFont = *-bold ,
    BoldItalicFont = *-bold ,
    BoldSlantedFont = *-italic ,
    ItalicFont  = *-italic ,
    SlantedFont = *-italic
    %,
    %SmallCapsFeatures = {Letters=SmallCaps}
    ,
    SlantedFeatures = {FakeSlant,Colour=FF0000}
]


\usepackage[normalem]{ulem} % underline

\usepackage{floatpag} % Full page figures without page numbers.

%%% END PREAMBLE FONTS %%%

%%% PAGE, STOCK, AND MARGIN SIZE %%%
% "Crown Quarto/Crown 4vo" at Lulu and Lightning Source 
% 7.44 x  9.68"   18.90 x 24.58cm
%\setstocksize{24.58cm}{18.90cm} % { height }{ width }
% US Letter
% 8.50 x 11.00"   21.59 x 27.94cm
%\setstocksize{27.94cm}{21.59cm} % { height }{ width }
% A4
% 8.27 x 11.70"   21.00 x 29.70cm
%\setstocksize{29.70cm}{21.00cm} % { height }{ width }
% Lulu Largest Hardcover, 24-800 pages
% 8.25 x 10.75"   20.96 x 27.31cm
\setstocksize{27.31cm}{20.96cm} % { height }{ width }

\settrimmedsize{\stockheight}{\stockwidth}{*}

%\settypeblocksize{ height }{ width }{ ratio }
% "Crown Quarto/Crown 4vo" at Lulu and Lightning Source 
%\settypeblocksize{19.0cm}{*}{*}
% US Letter
%\settypeblocksize{23.0cm}{*}{*}
% A4
%\settypeblocksize{24.0cm}{*}{*}
% Lulu Largest Hardcover, 24-800 pages
\settypeblocksize{22.0cm}{*}{*}

%\setlrmarginsandblock{ spine }{ edge }{ ratio }
% make the spine have more space than outer edge
% "Crown Quarto/Crown 4vo" at Lulu and Lightning Source 
%\setlrmarginsandblock{*}{2.5cm}{1.2}
% US Letter
%\setlrmarginsandblock{*}{2.0cm}{1.4}
% A4
%\setlrmarginsandblock{*}{2.0cm}{1.4}
% Lulu Largest Hardcover, 24-800 pages
\setlrmarginsandblock{*}{2.0cm}{1.4}

% \setulmargins{ upper }{ lower }{ ratio }
\setulmargins{2.0cm}{*}{*}

% \setheadfoot{ headheight }{ footskip }
\setheadfoot{12pt}{2cm}

\checkandfixthelayout[fixed]
%%% END PAGE, STOCK, AND MARGIN SIZE %%%

\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\setsecnumdepth{subsection}

\usepackage[english]{babel}
\usepackage{datetime} % Docs: /usr/share/doc/texlive-doc/latex/datetime/datetime.pdf
\usepackage{ucs}

%%% PDFLATEX %%%
\usepackage{etex}

%%% Not all features are used in XeTeX
\usepackage[protrusion,babel,final]{microtype}
%%% Conflicts with package fontspec
%\usepackage[utf8x]{inputenc}

% Docs: /usr/share/doc/texlive-humanities-doc/latex/ledmac/ledmac.pdf
%\usepackage{eledmac}

%\usepackage{jebba}

%%% forksand-it-manual PAGE STYLE %%%
\makepagestyle{aocstyle}
\pagestyle{aocstyle}
\makeevenhead{aocstyle}{}{\hspace{2em}\itshape\small\leftmark}{}
\makeoddhead{aocstyle}{}{\scshape\small\rightmark}{}
\makeevenfoot{aocstyle}{}{\hspace{2em}\thepage}{}
\makeoddfoot{aocstyle}{}{\thepage}{}
%%% END forksand-it-manual PAGE STYLE %%%

%%% forksand-it-manual SKI CHAPTER STYLE %%%
\makechapterstyle{aocski}{%
  \renewcommand*{\printchaptername}{}	% Clear out the chapter name (e.g. capítulo)
  \renewcommand*{\printchapternum}{}	% Clear out the chapter number
  \renewcommand*{\chaptitlefont}{\fontspec{lmroman12-regular.otf}\fontsize{20pt}{3em}\selectfont}	% Set chapter title font
  \renewcommand*{\printchaptertitle}[1]{%
     \hrule\vskip\onelineskip \centering \chaptitlefont{##1}\par}
  % Set chapter title font
  \renewcommand*{\afterchaptertitle}{\vskip\onelineskip \hrule\vskip
     \afterchapskip}
}
%%% END forksand-it-manual SKI CHAPTER STYLE %%%

%%% FORMATTING... %%%
\midsloppy
\setlength{\emergencystretch}{3em}
\tolerance=5000
\hyphenpenalty=500
\setlength{\topskip}{1.6\topskip}
\checkandfixthelayout
\raggedbottom
\widowpenalty=10000
\clubpenalty=10000
%%% END FORMATTING... %%%

%%% FOOTNOTES %%%
% no horizontal rule before footnotes:
\let\oldfootnoterule\footnoterule
\renewcommand*{\footnoterule}{}
\setlength{\footmarkwidth}{3.5em}
%%% END FOOTNOTES %%%

%%% COLORS %%%
\definecolor{ao-purple}{cmyk}{0.50,0.60,0.00,0.43}
\definecolor{ao-fork}{cmyk}{1.00 0.00 0.00 0.80}
\definecolor{ao-dark-blue}{cmyk}{0.83 0.24 0.00 0.12}
\definecolor{ao-light-blue}{cmyk}{0.41 0.15 0.00 0.09}
\definecolor{ao-light-orange}{cmyk}{0.00 0.40 0.88 0.03}
\definecolor{ao-dark-orange}{cmyk}{0.00 0.51 0.83 0.11}
\definecolor{ao-gold}{cmyk}{0.00 0.18 0.75 0.00}
\definecolor{ao-greyblack}{cmyk}{0.00 0.11 0.09 0.86}
\definecolor{ao-white}{cmyk}{0.00 0.00 0.00 0.00}
\definecolor{ao-black}{cmyk}{1.00 1.00 1.00 1.00}
\definecolor{lulzbot-green}{cmyk}{0.11 0.00 0.78 0.15}
\definecolor{secondary-dark-brown}{cmyk}{0.00 0.38 0.74 0.48}
\definecolor{secondary-brown}{cmyk}{0.00 0.07 0.20 0.05}
\definecolor{primary-blue}{cmyk}{0.37 0.04 0.00 0.00}
\definecolor{primary-brown}{cmyk}{0.00 0.28 0.68 0.31}
\definecolor{nonbrand-dark-blue}{cmyk}{0.83 0.28 0.00 0.57}
%%% END COLORS %%%


%%% DEBUG %%%
%\showoutput
%\typeoutlayout
%\typeoutstandardlayout
%%% END DEBUG %%%

\newglossaryentry{cluster}{
    name={Cluster},plural={Clusters},
    description={, computer cluster is a set of loosely or
    tightly connected computers that work together so that, in
    many respects, they can be viewed as a single system.}}
\newglossaryentry{dedicatedserver}{
    name={Dedicated Server},plural={Dedicated Servers},
    description={, or managed hosting service
    is a type of Internet hosting in which the client leases
    an entire server not shared with anyone else.}}
\newglossaryentry{sharkfork}{
    name={SharkFork},
    description={is a SharkTech provided Colocation for a
    Cluster with Fork Sand Colocation Cabinet}}
\newglossaryentry{colocation}{
    name={Colocation},plural={Colocations},
    description={ centre (also spelled co-location, or colo) or "carrier
    hotel", is a type of data centre where equipment, space,
    and bandwidth are available for rental to retail customers.}}
\newglossaryentry{cabinet}{
    name={Cabinet},plural={Cabinets},
    description={, inside a data center, is a locking unit
    that holds a server rack.}}
\newglossaryentry{backbone}{
    name={Backbone},plural={Backbones},
    description={ is a part of computer network that interconnects
    various pieces of network, providing a path for the exchange
    of information between different LANs or subnetworks.}}
\newglossaryentry{corosynk}{
    name={Corosynk},
    description={ is what Proxmox uses to keep the cluster nodes in sync.
    It is used for clustering besides proxmox too:
    \url{https://en.wikipedia.org/wiki/Corosync_Cluster_Engine}.
    Proxmox recommends applying two Corosynk instances if available.
    And also a third one for migrating from host to host.
    }}
\newglossaryentry{migration}{
    name={Migration},
    description={ see Corosynk description for details}}
\newglossaryentry{gnulinux}{
    name={GNU/Linux},
    description={ is a term promoted by the Free Software Foundation
    (FSF) and its founder Richard Stallman. Proponents call for
    the correction of the more extended term, on the grounds that it
    doesn't give credit to the major contributor and the associated
    free software philosophy.}}
\newglossaryentry{firewall}{
    name={Firewall},plural={Firewalls},
    description={ (in computing) is a network security system
    that monitors and controls incoming and outgoing network traffic
    based on predetermined security rules. A firewall typically
    establishes a barrier between a trusted internal network and
    untrusted external network, such as the Internet.}}
\newglossaryentry{coreboot}{
    name={Coreboot},
    description={, formerly known as LinuxBIOS, is a software
    project aimed at replacing proprietary firmware (BIOS or UEFI)
    found in most computers with a lightweight firmware designed to
    perform only the minimum number of tasks necessary to load and
    run a modern 32-bit or 64-bit operating system.}}
\newglossaryentry{ipmi}{
    name={IPMI},
    description={, the Intelligent Platform Management Interface
    (IPMI) is a set of computer interface specifications for an
    autonomous computer subsystem that provides management and
    monitoring capabilities independently of the host system's CPU,
    firmware (BIOS or UEFI) and operating system. IPMI defines a set
    of interfaces used by system administrators for out-of-band
    management of computer systems and monitoring of their operation.
    For example, IPMI provides a way to manage a computer that may
    be powered off or otherwise unresponsive by using a network
    connection to the hardware rather than to an operating system
    or login shell.}}
\newglossaryentry{openbmc}{
    name={OpenBMC},
    description={ project is a Linux Foundation Collaborative
    open-source project whose goal is to produce an open source
    implementation of the Baseboard Management Controllers (BMC)
    Firmware Stack. OpenBMC is a Linux distribution for
    BMCs meant to work across heterogeneous systems that include
    enterprise, High-performance computing (HPC),
    Telecommunications, and cloud-scale data centers.}}
\newglossaryentry{tor}{
    name={Tor},
    description={ is free software for enabling anonymous
    communication. The name is derived from an acronym for the
    original software project name "The Onion Router". Tor
    directs Internet traffic through a free, worldwide,
    volunteer overlay network consisting of thousands of relays
    to conceal a user's location and usage from anyone
    conducting network surveillance or traffic analysis.}}
\newglossaryentry{kvm}{
    name={KVM}, plural={KVMs},
    description={, the Kernel-based Virtual Machine is a
    virtualization infrastructure for the Linux kernel that
    turns it into a hypervisor. It was merged into the Linux
    kernel mainline in kernel version 2.6.20, which was
    released on February 5, 2007. KVM requires a processor
    with hardware virtualization extensions. KVM has also been
    ported to FreeBSD and illumos in the form of loadable
    kernel modules.}}
\newglossaryentry{ddos}{
    name={DDoS},
    description={, a distributed denial-of-service (DDoS) is a
    large-scale DoS attack where the perpetrator uses more than
    one unique IP address, often thousands of them. Since
    the incoming traffic flooding the victim originates from
    many different sources, it is impossible to stop the attack
    simply by using ingress filtering. It also makes it very
    difficult to distinguish legitimate user traffic from
    attack traffic when spread across so many points of origin.
    As an alternative or augmentation of a DDoS, attacks may
    involve forging of IP sender addresses (IP address spoofing)
    further complicating identifying and defeating the attack.}}
\newglossaryentry{ceph}{
    name={Ceph},
    description={ is a free-software storage platform,
    implements object storage on a single distributed computer
    cluster, and provides interfaces for object-, block- and
    file-level storage. Ceph aims primarily for completely
    distributed operation without a single point of failure,
    scalable to the exabyte level, and freely available.}}
\newglossaryentry{docker}{
    name={Docker}, plural={Dockers},
    description={ is a program that performs operating-system-level
    virtualization also known as containerization. It is
    developed by Docker, Inc. Docker is primarily developed for
    Linux, where it uses the resource isolation features of the
    Linux kernel such as cgroups and kernel namespaces, and a
    union-capable file system such as OverlayFS and others to
    allow independent "containers" to run within a single Linux
    instance, avoiding the overhead of starting and maintaining
    virtual machines (VMs).}}

%%% END OF PREAMBLE %%%

\begin{document}
%%% Global pdf include directives 
\includepdfset{pages=-,noautoscale}

%%% BEGIN FRONT MATTER %%%
\frontmatter

% Set page numbers to lowercase roman numerals, and reset the count to 1 (no *)
\pagenumbering{roman}

%%% TITLE PAGE %%%
% We want the title to be on the right hand page.
% If we pad a page, it gives us two with openright
\include{Title}
%%% END TITLE PAGE

%%% COPYRIGHT PAGE %%%
\include{Copyright}
%%% END COPYRIGHT PAGE %%%

% Set page numbering to arabic, but don't reset numbering (*)
\pagenumbering*{arabic}

%%% TABLE OF CONTENTS %%%
{
\fontspec{lmroman12-regular.otf}[
    BoldFont = lmroman12-regular.otf
]
\maxtocdepth{subsection}
\settocdepth{subsection}
%\setsecnumdepth{subsection}
% space between dots
\renewcommand{\cftchapterdotsep}{15}
% dot symbol (default is period)
\renewcommand{\cftdot}{\textperiodcentered}	% centered period
% Set space between each entry in ToC
\setlength{\cftbeforechapterskip}{5pt}
\tableofcontents*}
%%% END TABLE OF CONTENTS %%%

%%% LIST OF FIGURES %%%
\renewcommand*{\lofheadstart}{\vspace{1cm}}
\clearpage
\listoffigures*
%%% END LIST OF FIGURES %%%

%%% LIST OF LISTINGS %%%
%\renewcommand*{\lofheadstart}{\vspace{1cm}}
%\clearpage
%\listoflistings
%%% END LIST OF LISTINGS %%%

%%% CHAPTER STYLE %%%
\chapterstyle{aocski} % defined in preamble
\def\topblockvspace{0.11}
%%% END CHAPTER STYLE %%%

%%% INVISIBLE CHAPTERS %%%
\newcommand{\invisiblechapter}[1]{%
  \par\refstepcounter{chapter}% Increase section counter
  \sectionmark{#1}% Add section mark (header)
  \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}% Add chapter to ToC
  % Add more content here, if needed.
}
%%% END INVISIBLE CHAPTERS %%%

%%% CHAPTER CONFIG %%%
\newcommand{\chapterheader}{Fork Sand IT Manual}
% See \chapterconf below for examples of how this is used.
% value 1 is file to include
% value 2 is title of chapter
% value 3 is sub title of chapter
\newcommand{\chapterconf}[3]{
    \includepdf[width=210mm%
        ,%
        picturecommand*={%
            \put(200,650){%
                \invisiblechapter{{#2}\qquad\qquad{#3}}%
            }%
            \color[rgb]{0.631,0.957,1}%     HEX # A1F4FF    R:161 G:244 B:255   C:37 M:4 Y:0 K:0
            \linethickness{30mm}
            \put( 100,378){\line(1,0){397.50793}}
            \color[rgb]{0.361,0.922,1}%     HEX # 5CEBFF    R:92 G:235 B:255    C:64 M:8 Y:0 K:0
            \put(   0,378){\line(1,0){100}}
            \put( 497.50793,378){\line(1,0){100}}
            \color[rgb]{0,0.2,0.2}
            \linethickness{0.3mm}
            \put(   0,420){\line(1,0){597.50793}}
            \put(   0,336){\line(1,0){597.50793}}
            \put(120,395){\begin{minipage}{357.50793pt}\centering \Huge{#2}\end{minipage}}
            \put(120,355){\begin{minipage}{357.50793pt}\centering \Huge{#3}\end{minipage}}
            \color[rgb]{0,0,0}
        }%
        ]{LetterheadPDF.pdf}
    \thispagestyle{empty}
    \markboth{#2}{\chapterheader}
{\include{#1}}
}
%%% END CHAPTER CONFIG %%%

%%% FRONTMATTER CHAPTERS %%%

% Format:
% \chapterconf{Name of file to include}{Title of Chapter}
\chapterconf{Introduction}{Introduction}{Fork Sand IT Manual}
%%% END FRONTMATTER CHAPTERS %%%

%%% END FRONTMATTER %%%

%%% BEGIN MAINMATTER %%%
\mainmatter*

%% MAINMATTER CHAPTERS %%%
% Default chapter font

% Format:
% \chapterconf{Name of file to include}{Title of Chapter}{Subtitle}
% Comment out a line to not render that chapter
\chapterconf{Hardware}{Hardware}{Metal and Chips}
\chapterconf{Network}{Network}{Switch}
\chapterconf{Switches}{Network Switches}{Free Switches (none found)}
\chapterconf{Clouds}{Clouds}{Software as a Surveillance State}
\chapterconf{Distros}{Distributions}{Free Software Distributions}
\chapterconf{Software-daemons}{Server Software}{Server Software Daemons}
\chapterconf{Firewalls}{Firewalls}{Firewalls}
\chapterconf{Firewall-opnsense}{OPNSense Firewall}{Use OPNSense}
\chapterconf{Proxmox}{Proxmox}{Virtual Machines}
\chapterconf{Ansible}{Ansible}{Cluster Administration}
\chapterconf{DNS}{Domain Name Service (DNS)}{Who Names You?}
\chapterconf{NTP}{Network Time Protocol}{A Hole in Time}
\chapterconf{Firmware}{Firmware}{Embedded Software}
\chapterconf{History}{History}{Evolution History}
%%% Appendix %%%
%\part{Appendix} % XXX
\appendix
\chapterconf{Source}{Free Software}{Free Software and Configurations}

%% END MAINMATTER CHAPTERS %%%

%%% END MAINMATTER %%%

%%% BEGIN BACKMATTER %%%
\backmatter

%%% INDEX %%%
\clearpage
\printindex
%%% END INDEX %%%

%%% GLOSSARY %%%
\renewcommand{\memgloterm}[1]{\textbf{#1}}
\renewcommand{\memglodesc}[1]{\textit{#1}}
\renewcommand{\memglonum}[1]{}

\clearpage
%\addcontentsline{toc}{chapter}{Glossary}
\printglossaries
%%% END GLOSSARY %%%

%%% CONTACT %%%
\chapterconf{Contact}{Contact}{Phone, Email, Web, Location}
%%% END CONTACT %%%


%%% COLOPHON %%%
%%% skip a couple pages
\pagebreak{}
\thispagestyle{empty}
\begingroup 
\vfill\null 
\endgroup
\pagebreak{}
\thispagestyle{empty}
{\include{Colophon}}
%%% END COLOPHON %%%

%%% END BACKMATTER %%%

\end{document}

