-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0281ffb
commit 7a52594
Showing
3 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
set -u | ||
set -o pipefail | ||
|
||
source "$(dirname "$0")/utils.sh" | ||
|
||
LOG_DIR="$(pwd)/logs/installation" | ||
|
||
setup_logging "$LOG_DIR" | ||
|
||
install_package() { | ||
local package="$1" | ||
local manager="$2" | ||
|
||
if [[ "$manager" == "apt" ]]; then | ||
echo -e "$(process_colorize $COLOR_LIGHT_GREEN_BACKGROUND " - Installing $package...")" | ||
if ! sudo apt-get install -y "$package"; then | ||
echo -e "$(colorize $COLOR_RED "Failed to install $package")" | ||
exit 1 | ||
fi | ||
elif [[ "$manager" == "snap" ]]; then | ||
echo -e "$(process_colorize $COLOR_LIGHT_GREEN_BACKGROUND " - Installing $package...")" | ||
if ! sudo snap install "$package"; then | ||
echo -e "$(colorize $COLOR_RED "Failed to install $package")" | ||
exit 1 | ||
fi | ||
fi | ||
echo -e "$(result_colorize $COLOR_GREEN_BACKGROUND "$package installed")" | ||
echo | ||
} | ||
|
||
git_config() { | ||
local package="$1" | ||
if [[ "$package" == "git" ]]; then | ||
if [ -t 0 ]; then | ||
echo -e "$(colorize $COLOR_YELLOW "Do you want to (re)configure Git? (y/n)")" | ||
read -r configure_git </dev/tty | ||
else | ||
echo "Not running in an interactive shell. Skipping Git configuration." | ||
return | ||
fi | ||
|
||
if [[ "$configure_git" == "y" ]]; then | ||
echo -e "$(colorize $COLOR_YELLOW "Enter your Git user name:")" | ||
read -r git_user_name </dev/tty | ||
echo -e "$(colorize $COLOR_YELLOW "Enter your Git user email:")" | ||
read -r git_user_email </dev/tty | ||
|
||
git config --global user.name "$git_user_name" | ||
git config --global user.email "$git_user_email" | ||
|
||
echo -e "$(colorize $COLOR_GREEN "Git has been configured with:")" | ||
echo -e "$(colorize $COLOR_GREEN "User Name: $git_user_name")" | ||
echo -e "$(colorize $COLOR_GREEN "User Email: $git_user_email")" | ||
else | ||
echo -e "$(result_colorize $COLOR_YELLOW_HIGH_INTENCITY_BACKGROUND "Git configuration skipped.")" | ||
echo | ||
fi | ||
fi | ||
} | ||
|
||
echo -e "$(process_colorize $COLOR_BLUE_BACKGROUND 'Updating system...')" | ||
# sudo apt-get update && sudo apt-get upgrade -y | ||
echo -e "$(result_colorize $COLOR_GREEN_BACKGROUND 'System updated')" | ||
echo | ||
|
||
for package_manager in "apt" "snap"; do | ||
case $package_manager in | ||
apt) | ||
packages=("${APT[@]}") | ||
color=$COLOR_PURPLE_BACKGROUND | ||
;; | ||
snap) | ||
packages=("${SNAP[@]}") | ||
color=$COLOR_PURPLE_BACKGROUND | ||
;; | ||
esac | ||
|
||
echo -e "$(result_colorize $COLOR_BLUE_BACKGROUND "Installing $package_manager packages:")" | ||
echo | ||
for package in "${packages[@]}"; do | ||
echo -e "$(process_colorize $color "Installing $package")" | ||
install_package "$package" "$package_manager" | ||
|
||
# Only run git_config for apt packages (assuming git is installed via apt) | ||
if [[ "$package_manager" == "apt" && "$package" == "git" ]]; then | ||
git_config "$package" | ||
fi | ||
done | ||
done | ||
|
||
echo -e "$(result_colorize $COLOR_BLUE_BACKGROUND "Installing shells:")" | ||
echo | ||
|
||
for shell in "${SHELL[@]}"; do | ||
echo -e "$(process_colorize $COLOR_PURPLE_BACKGROUND "Installing $shell")" | ||
install_package "$shell" "apt" | ||
echo -e "$(colorize $COLOR_YELLOW "Set $shell as default shell? (yes/no)")" | ||
read -r set </dev/tty | ||
if [[ "$set" == "yes" ]]; then | ||
sudo chsh -s "$(which $shell)" | ||
echo -e "$(result_colorize $COLOR_GREEN_BACKGROUND "Default shell set to $shell")" | ||
else | ||
echo -e "$(result_colorize $COLOR_YELLOW_HIGH_INTENCITY_BACKGROUND "shell configuration skipped.")" | ||
echo | ||
fi | ||
done | ||
echo -e "$(result_colorize $COLOR_GREEN_BACKGROUND 'Installation completed successfully!')" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
|
||
source "$(dirname "$0")/utils.sh" | ||
|
||
LOG_DIR="$(pwd)/logs/vpn" | ||
|
||
setup_logging "$LOG_DIR" | ||
echo $LOG_DIR | ||
|
||
echo -e "$(process_colorize $COLOR_BLUE_BACKGROUND "Starting VPN latency tests...")" | ||
echo | ||
|
||
if [ -z "$OPENVPN_PATH" ]; then | ||
echo -e "$(result_colorize $COLOR_RED_BACKGROUND "Error: OPENVPN_PATH is not set in the .conf file!")" | ||
exit 1 | ||
|
||
elif [ ! -d "$OPENVPN_PATH" ]; then | ||
echo -e "$(result_colorize $COLOR_RED_BACKGROUND "Error: Directory $OPENVPN_PATH not found!")" | ||
exit 1 | ||
|
||
elif [ -z "$(find "$OPENVPN_PATH" -name '*.ovpn' -print -quit)" ]; then | ||
echo -e "$(result_colorize $COLOR_RED_BACKGROUND "Error: No .ovpn files found in $OPENVPN_PATH!")" | ||
exit 1 | ||
fi | ||
|
||
for CONFIG_FILE in "$OPENVPN_PATH"/*.ovpn; do | ||
FILE_NAME=$(basename "$CONFIG_FILE") | ||
echo -e "$(process_colorize $COLOR_BLUE_BACKGROUND "Processing $FILE_NAME...")" | ||
|
||
# Extract the remote server address from the OpenVPN configuration file | ||
REMOTE_SERVER=$(grep -E '^remote\s+' "$CONFIG_FILE" | awk '{print $2}') | ||
|
||
# Check if the remote server address was found | ||
if [ -z "$REMOTE_SERVER" ]; then | ||
echo " Remote server address not found in $FILE_NAME." | ||
continue | ||
fi | ||
|
||
# Ping the remote server | ||
echo -e "$(process_colorize $COLOR_PURPLE_BACKGROUND "- Pinging $FILE_NAME...")" | ||
ping -c 3 "$REMOTE_SERVER" | ||
|
||
# Check the exit status of the ping command | ||
if [ $? -eq 0 ]; then | ||
echo -e "$(result_colorize $COLOR_LIGHT_GREEN_BACKGROUND "Ping to $FILE_NAME was successful.")" | ||
else | ||
echo -e "$(result_colorize $COLOR_RED_BACKGROUND "Ping to $FILE_NAME failed.")" | ||
fi | ||
|
||
echo | ||
done | ||
|
||
echo -e "$(result_colorize $COLOR_GREEN_BACKGROUND "VPN latency tests completed!")" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/bin/bash | ||
|
||
# Color definitions | ||
UNDERLINE='\e[4m' | ||
COLOR_BLACK_BOLD='\e[1;30m' | ||
COLOR_RED='\033[0;31m' | ||
COLOR_RED_BACKGROUND='\e[41m' | ||
COLOR_GREEN='\033[0;32m' | ||
COLOR_GREEN_BOLD='\033[4;32m' | ||
COLOR_GREEN_BACKGROUND='\e[42m' | ||
COLOR_YELLOW='\033[0;33m' | ||
COLOR_YELLOW_HIGH_INTENCITY_BACKGROUND='\e[0;103m' | ||
COLOR_BLUE='\033[1;34m' | ||
COLOR_BLUE_BACKGROUND='\e[44m' | ||
COLOR_PURPLE='\033[0;35m' | ||
COLOR_PURPLE_BACKGROUND='\e[45m' | ||
COLOR_LIGHT_GREEN='\033[0;36m' | ||
COLOR_LIGHT_GREEN_BACKGROUND='\e[46m' | ||
COLOR_WHITE_BOLD='\033[1;37m' | ||
COLOR_RESET='\033[0m' | ||
|
||
CONF_DIR="$(pwd)/src/configurations/utc.conf" | ||
|
||
|
||
# Function to colorize text | ||
colorize() { | ||
local color="$1" | ||
local text="$2" | ||
echo -e "${color}${text}${COLOR_RESET}" | ||
} | ||
|
||
result_colorize(){ | ||
local background_color="$1" | ||
local text="$2" | ||
echo -e "${background_color}${COLOR_BLACK_BOLD}${UNDERLINE}${text}${COLOR_RESET}" | ||
} | ||
|
||
process_colorize(){ | ||
local background_color="$1" | ||
local text="$2" | ||
echo -e "${background_color}${COLOR_BLACK_BOLD}${text}${COLOR_RESET}" | ||
} | ||
|
||
# Function to strip colors from text | ||
strip_colors() { | ||
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" | ||
} | ||
|
||
# Function to set up logging | ||
setup_logging() { | ||
local log_dir="$1" | ||
local log_file | ||
|
||
mkdir -p "$log_dir" | ||
|
||
if [ -s "$log_dir/logs.log" ]; then | ||
local timestamp=$(date +"%Y-%m-%d_%H-%M-%S") | ||
log_file="$log_dir/logs_$timestamp.log" | ||
else | ||
log_file="$log_dir/logs.log" | ||
fi | ||
|
||
# exec > >(tee >(strip_colors >>"$log_file")) 2>&1 | ||
|
||
echo -e "$(colorize $COLOR_BLUE "Created at: $(date +"%Y-%m-%d_%H-%M-%S")")" | ||
} | ||
|
||
|
||
if [ -f "$CONF_DIR" ]; then | ||
if ! source "$CONF_DIR"; then | ||
echo -e "$(colorize $COLOR_RED "Error: Failed to source $CONF_DIR. Check the file for syntax errors.")" >&2 | ||
exit 1 | ||
fi | ||
else | ||
echo -e "$(colorize $COLOR_RED "Error: $CONF_DIR file not found!")" >&2 | ||
exit 1 | ||
fi |