22
33set -e
44
5+ # === CLI arguments and help ===
6+ # defaults:
7+ SKIP_DOCKER=false
8+ SILENT=false
9+
10+ show_help () {
11+ cat << EOF
12+ $( basename " $0 " ) is a script for installing the installation requirements of
13+ FACT and should be run before running "python3 install.py".
14+ Usage: $( basename " $0 " ) [OPTIONS]
15+
16+ Options:
17+ -D, --skip-docker Skip Docker installation
18+ -d, --debug Show debugging output
19+ -s, --silent No CLI output
20+ -h, --help Show this help
21+ EOF
22+ }
23+
24+ log () {
25+ if [[ " $SILENT " == true ]]; then
26+ echo " $@ "
27+ fi
28+ }
29+
30+ # parse CLI arguments
31+ while [[ $# -gt 0 ]]; do
32+ case $1 in
33+ -D|--skip-docker)
34+ SKIP_DOCKER=true
35+ shift
36+ ;;
37+ -s|--silent)
38+ SILENT=true
39+ shift
40+ ;;
41+ -d|--debug)
42+ set -x
43+ shift
44+ ;;
45+ -h|--help)
46+ show_help
47+ exit 0
48+ ;;
49+ * )
50+ echo " Unknown option: $1 " >&2
51+ show_help
52+ exit 1
53+ ;;
54+ esac
55+ done
56+
557# cd in this files directory for relative paths to work
658cd " $( dirname " ${BASH_SOURCE[0]} " ) " || exit 1
759
860FACTUSER=$( whoami)
961
10- echo " Installing pre-install requirements..."
62+ log " Installing pre-install requirements..."
63+
64+ # === step 1: apt packages ===
1165sudo apt-get update
12- sudo apt-get -y install python3-pip git libffi-dev lsb-release
66+ grep -vE ' ^\s*(#|$) ' apt-pkgs-pre_install.txt | sudo xargs apt-get install -y
1367
14- # distro and codename detection
68+ # === step 2: distro and codename detection ===
1569. /etc/os-release
1670if [ -n " ${ID_LIKE} " ]; then
1771 if [ " ${ID} " = " ubuntu" ]; then
@@ -36,70 +90,68 @@ elif [ -n "${DEBIAN_CODENAME}" ]; then
3690elif [ " ${CODENAME} " = " kali-rolling" ]; then
3791 CODENAME=bookworm
3892elif [ -z " ${CODENAME} " ]; then
39- echo " Could not get distribution codename. Please make sure that your distribution is compatible to ubuntu/debian."
40- exit 1
93+ echo " Could not get distribution codename. Please make sure that your distribution is compatible to ubuntu/debian." >&2
94+ exit 1
4195fi
4296
43- echo " detected distro ${DISTRO} and codename ${CODENAME} "
97+ log " detected distro ${DISTRO} and codename ${CODENAME} "
4498
4599supported_codenames=(" jammy" " noble" " bookworm" " trixie" " kali-rolling" )
46100if [[ ! " ${supported_codenames[*]} " =~ ${CODENAME} ]]; then
47- echo " Warning: your distribution is outdated or unsupported and the installation may not work as expected."
101+ log " Warning: your distribution is outdated or unsupported and the installation may not work as expected."
48102fi
49103
50- # docker installation (source: https://docs.docker.com/engine/install/{ubuntu|debian})
51- echo " Installing Docker"
52-
53- # uninstall old docker versions
54- for i in docker.io docker-doc docker-compose podman-docker containerd runc; do
55- sudo apt-get remove -y $i || true
56- done
57-
58- # install prerequisites
59- sudo apt-get install -y \
60- ca-certificates \
61- curl \
62- gnupg
63-
64- # add Docker's GPG key
65- sudo install -m 0755 -d /etc/apt/keyrings
66- echo " curl -fsSL \" https://download.docker.com/linux/${DISTRO} /gpg\" "
67- curl -fsSL " https://download.docker.com/linux/${DISTRO} /gpg" | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg --batch --yes
68- sudo chmod a+r /etc/apt/keyrings/docker.gpg
69-
70- # set up repository
71- echo \
72- " deb [arch=$( dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/${DISTRO} \
73- ${CODENAME} stable" | sudo tee /etc/apt/sources.list.d/docker.list
74-
75- # Install Docker Engine
76- sudo apt-get update
77- sudo apt-get -o Dpkg::Options::=" --force-confnew" install -y \
78- docker-ce \
79- docker-ce-cli \
80- containerd.io \
81- docker-buildx-plugin \
82- docker-compose-plugin
83-
84- sudo systemctl enable docker
85-
86- # add fact-user to docker group
87- if [ ! " $( getent group docker) " ]
88- then
89- sudo groupadd docker
104+ # === step 3: docker installation ===
105+ if [[ " $SKIP_DOCKER " == false ]]; then
106+ # docker installation (source: https://docs.docker.com/engine/install/{ubuntu|debian})
107+ log " Installing Docker"
108+
109+ # uninstall old docker versions
110+ sudo apt-get remove -y " $( dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc podman-docker containerd runc | cut -f1) "
111+
112+ # add Docker's GPG key
113+ sudo install -m 0755 -d /etc/apt/keyrings
114+ echo " curl -fsSL \" https://download.docker.com/linux/${DISTRO} /gpg\" "
115+ curl -fsSL " https://download.docker.com/linux/${DISTRO} /gpg" | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg --batch --yes
116+ sudo chmod a+r /etc/apt/keyrings/docker.gpg
117+
118+ # set up repository
119+ echo \
120+ " deb [arch=$( dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/${DISTRO} \
121+ ${CODENAME} stable" | sudo tee /etc/apt/sources.list.d/docker.list
122+
123+ # Install Docker Engine
124+ sudo apt-get update
125+ sudo apt-get -o Dpkg::Options::=" --force-confnew" install -y \
126+ docker-ce \
127+ docker-ce-cli \
128+ containerd.io \
129+ docker-buildx-plugin \
130+ docker-compose-plugin
131+
132+ sudo systemctl enable docker
133+
134+ # add fact-user to docker group
135+ if [ ! " $( getent group docker) " ]
136+ then
137+ sudo groupadd docker
138+ fi
139+ sudo usermod -aG docker " $FACTUSER "
140+ else
141+ log " Skipping Docker installation"
90142fi
91- sudo usermod -aG docker " $FACTUSER "
92143
144+ # === step 4: python packages ===
93145IS_VENV=$( python3 -c ' import sys; print(sys.exec_prefix!=sys.base_prefix)' )
94146PREFIX=" "
95147if [[ $IS_VENV == " False" ]]
96148then
97- echo -e " \\ 033[31mWarning: It is highly discouraged to install FACT without a virtual environment because of the risk of conflicts with system Python packages!\\ 033[0m"
149+ log -e " \\ 033[31mWarning: It is highly discouraged to install FACT without a virtual environment because of the risk of conflicts with system Python packages!\\ 033[0m"
98150 PREFIX=" sudo -EH python3 -m"
99151fi
100152$PREFIX pip install -U pip setuptools wheel
101153$PREFIX pip install -r ./requirements_pre_install.txt --prefer-binary
102154
103- echo -e " Pre-Install-Routine complete! \\ 033[31mPlease reboot before running install.py\\ 033[0m"
155+ log -e " Pre-Install-Routine complete! \\ 033[31mPlease make sure you can run docker containers (e.g. reboot) before running install.py\\ 033[0m"
104156
105157exit 0
0 commit comments