-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsetup_ctf_env.sh
More file actions
executable file
·78 lines (64 loc) · 2.34 KB
/
setup_ctf_env.sh
File metadata and controls
executable file
·78 lines (64 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# ANSI color codes for terminal output
yellow='\033[0;33m'
reset='\e[0m'
# the following packages need to be installed to compile pyenv
# sudo yum install gcc zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel -y
# Introduce --clean option to remove previous setup dirs
if [ "$1" = "--clean" ] || [ "$1" = "-c" ]; then
echo "Removing ~/ctf_env, ~/.pyenv, and ~/.nvm..."
rm -rf ~/ctf_env
rm -rf ~/.pyenv
rm -rf ~/.nvm
echo "Done."
else
if [ -e ~/.pyenv ] || [ -e ~/ctf_env ] || [ -e ~/.nvm ]; then
# -e flag for color coded output
echo -e "${yellow}Found existing ~/ctf_env, ~/.pyenv and/or ~/.nvm directories."
echo -e "It is recommended to remove these before re-attempting ctf_env setup. ${reset}"
read -p "Remove these directories before proceeding? [y/n]: " usr_clean_res
if [ "$usr_clean_res" = "y" ]; then
rm -rf ~/ctf_env
rm -rf ~/.pyenv
rm -rf ~/.nvm
fi
fi
fi
# Determine available package manager: yum or dnf
if command -v yum >/dev/null 2>&1; then
PKG_MANAGER="yum"
elif command -v dnf >/dev/null 2>&1; then
PKG_MANAGER="dnf"
else
echo "Error: Neither 'dnf' nor 'yum' is available on this system."
return 1
fi
SQLITE_PACKAGE="sqlite-devel"
if ! $PKG_MANAGER list installed "$SQLITE_PACKAGE" >/dev/null 2>&1; then
echo "Error: Package '$SQLITE_PACKAGE' is not installed."
return 1
fi
# pyenv will be installed under ~/.pyenv/
curl https://pyenv.run | bash
# if want to use pyenv for other shell sessions, put the following 3 lines in ~/.bashrc
#export PYENV_ROOT="$HOME/.pyenv"
#command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
#eval "$(pyenv init -)"
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
#python is installed under ~/.pyenv/versions/
pyenv install -v 3.8.12
pyenv versions
# set python to 3.8.12 only for this shell session
pyenv shell 3.8.12
python -V
# create virtual environment for package management under home directory
python -m venv ~/ctf_env
source ~/ctf_env/bin/activate
# install required ctf packages
python -m pip install pip==22.3.1
pip install -r ./requirements.txt
# if no intention to use CTF editor, the next line could be commented out
source setup_editor.sh
python --version
deactivate