-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup_prepnote.sh
executable file
·175 lines (147 loc) · 6.87 KB
/
setup_prepnote.sh
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
CONFIG_FILE="$(dirname "$0")/config.txt"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
DEFAULT_TEMPLATE_DIR="$SCRIPT_DIR/Template" # Path to the Template folder in the current directory
echo ""
echo ""
echo ' ____ _ ____ __ _____ __
/ __ \__ ______ ____ _____ ___ ____ ( )_____ / __ \________ ____ ____ ____ / /____ / ___/___ / /___ ______
/ / / / / / / __ \/ __ / __ __ \/ __ \|// ___/ / /_/ / ___/ _ \/ __ \/ __ \/ __ \/ __/ _ \ \__ \/ _ \/ __/ / / / __ \
/ /_/ / /_/ / / / / /_/ / / / / / / /_/ / (__ ) / ____/ / / __/ /_/ / / / / /_/ / /_/ __/ ___/ / __/ /_/ /_/ / /_/ /
/_____/\__, /_/ /_/\__,_/_/ /_/ /_/\____/ /____/ /_/ /_/ \___/ .___/_/ /_/\____/\__/\___/ /____/\___/\__/\__,_/ .___/
/____/ /_/ /_/ '
echo ""
echo ""
# Inform the user about the config.txt file
echo ""
echo "Note: The setup will be quicker if you fill out the 'config.txt' file with your paths beforehand."
read -p "Do you wish to continue with the interactive setup? (Y/n) [Y]: " continue_choice
continue_choice=${continue_choice:-Y}
if [[ ! "$continue_choice" =~ ^[Yy]$ ]]; then
echo "Exiting the setup. You can edit 'config.txt' manually and run this script again."
exit 0
fi
# Function to prompt for path input and create it if it doesn't exist
prompt_for_path() {
local prompt_message="$1"
local current_value="$2"
local path_variable
while true; do
read -p "$prompt_message (current: ${current_value:-not set}): " path_variable
path_variable=${path_variable:-$current_value} # Use the current value if Enter is pressed
if [[ -z "$path_variable" ]]; then
echo "Error: Path cannot be empty. Please enter a valid path."
elif [[ -d "$path_variable" ]]; then
echo "$path_variable"
break
else
read -p "The path '$path_variable' does not exist. Would you like to create it? (y/n) [Y]: " create_choice
create_choice=${create_choice:-Y} # Default to 'Y' if Enter is pressed
if [[ "$create_choice" == "y" || "$create_choice" == "Y" ]]; then
mkdir -p "$path_variable"
if [[ $? -eq 0 ]]; then
echo "$path_variable"
break # Directory successfully created
else
echo "Error: Failed to create directory '$path_variable'. Please check permissions."
exit 1
fi
else
echo "Please enter a valid path or choose to create it."
fi
fi
done
}
# Interactive prompts for setting up paths
echo "Please provide the paths for your setup. Press Enter to keep the current/suggested value."
echo ""
# Read current values from config file if it exists
if [[ -f "$CONFIG_FILE" ]]; then
source "$CONFIG_FILE"
fi
# Prompt for paths and assign them to variables
obsidian_notes_path=$(prompt_for_path "Enter the path to your Obsidian notes vault" "$OBSIDIAN_NOTES_PATH")
template_path=$(prompt_for_path "Enter the path where you want to store the template folder within your notes vault" "$TEMPLATE_PATH")
working_dir=$(prompt_for_path "Enter the path for your general working directory" "$WORKING_DIR")
exam_path=$(prompt_for_path "Enter the path for your OSCP Exam working folder" "$EXAM_PATH")
training_path=$(prompt_for_path "Enter the path for your OSCP Training working folder" "$TRAINING_PATH")
htb_path=$(prompt_for_path "Enter the path for your HackTheBox working folder" "$HTB_PATH")
pg_path=$(prompt_for_path "Enter the path for your Proving Grounds working folder" "$PG_PATH")
oscp_path=$(prompt_for_path "Enter the path for your OSCP Challenge Labs working folder" "$OSCP_PATH")
oscp_ad_path=$(prompt_for_path "Enter the path for your OSCP AD Challenge Labs working folder" "$OSCP_AD_PATH")
# Copy the default template to the designated location if needed
if [[ -d "$DEFAULT_TEMPLATE_DIR" ]]; then
echo "Default template directory found at $DEFAULT_TEMPLATE_DIR."
if [[ ! -d "$template_path" || -z "$(ls -A "$template_path" 2>/dev/null)" ]]; then
echo "Copying the default template folder to: $template_path"
cp -r "$DEFAULT_TEMPLATE_DIR"/* "$template_path"
if [[ $? -eq 0 ]]; then
echo "Default template successfully copied to $template_path."
else
echo "Error: Failed to copy the default template. Please check the paths and permissions."
exit 1
fi
else
echo "The template folder at $template_path already contains files. Skipping template copy."
fi
else
echo "Error: The default template folder at $DEFAULT_TEMPLATE_DIR was not found. Please ensure it exists in the current directory."
exit 1
fi
# Debugging statements to ensure variables are set correctly
echo ""
echo "Debug: OBSIDIAN_NOTES_PATH='$obsidian_notes_path'"
echo "Debug: TEMPLATE_PATH='$template_path'"
echo "Debug: EXAM_PATH='$exam_path'"
echo "Debug: TRAINING_PATH='$training_path'"
echo "Debug: WORKING_DIR='$working_dir'"
echo "Debug: HTB_PATH='$htb_path'"
echo "Debug: PG_PATH='$pg_path'"
echo "Debug: OSCP_PATH='$oscp_path'"
echo "Debug: OSCP_AD_PATH='$oscp_ad_path'"
echo ""
# Save paths to the configuration file
cat <<EOL > "$CONFIG_FILE"
# Configuration for the prepnote setup script
# Path to your Obsidian notes vault where your notes are stored.
OBSIDIAN_NOTES_PATH="$obsidian_notes_path"
# Path where you want to store the template folder within your notes vault.
TEMPLATE_PATH="$template_path"
# Path for your OSCP Exam working folder.
EXAM_PATH="$exam_path"
# Path for your OSCP Training working folder.
TRAINING_PATH="$training_path"
# General working directory path.
WORKING_DIR="$working_dir"
# Path for your HackTheBox working folder.
HTB_PATH="$htb_path"
# Path for your Proving Grounds working folder.
PG_PATH="$pg_path"
# Path for your OSCP Challenge Labs working folder.
OSCP_PATH="$oscp_path"
# Path for your OSCP AD Challenge Labs working folder.
OSCP_AD_PATH="$oscp_ad_path"
EOL
# Check if the paths were written correctly
if [[ $? -eq 0 ]]; then
echo ""
echo "Setup completed. Configuration saved to $CONFIG_FILE."
else
echo "Error: Failed to write to $CONFIG_FILE. Please check permissions and try again."
exit 1
fi
echo ""
echo ""
echo "You can run this script again to modify paths or manually edit $CONFIG_FILE if needed."
# Prompt the user to create a symlink to /usr/local/bin
read -p "Would you like to create a symlink for 'prepnote.sh' and 'config.txt' in /usr/local/bin for easier access? (y/n) [N]: " symlink_choice
symlink_choice=${symlink_choice:-N}
if [[ "$symlink_choice" =~ ^[Yy]$ ]]; then
sudo ln -s "$SCRIPT_DIR/prepnote.sh" /usr/local/bin/prepnote
sudo cp "$(dirname "$0")/config.txt" /usr/local/bin/config.txt
if [[ $? -eq 0 ]]; then
echo "Symlinks created successfully. You can now run 'prepnote' from anywhere."
else
echo "Error: Failed to create the symlink. Please check permissions or try again."
fi
fi