Created
March 5, 2024 21:21
-
-
Save newtonkiragu/f2f8882d2384c0648efd45c5e47cb9be to your computer and use it in GitHub Desktop.
Script that runs every time a new wsl session starts. It should be added to .bashrc or .zshrc. It is used to only run the services you would like to run instead of activating systemctl
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
#!/bin/bash | |
# Function to run activation commands | |
activate_commands() { | |
# Prompt user for sudo password | |
echo "Please enter your sudo password:" | |
sudo -v || { echo "Incorrect sudo password. Exiting."; exit 1; } | |
# Activation commands for Postgres | |
sudo service postgresql start | |
# Activation commands for MySQL | |
sudo service mysql start | |
# Activation Command for Redis | |
#sudo service redis start | |
} | |
# Check if the user requested to manually run activation commands | |
if [[ "$1" == "-m" ]]; then | |
echo "Running activation commands for Postgres, MySQL... manually" | |
activate_commands | |
else | |
# Check if WSL is a cold start or continuation | |
if pgrep -x "init" >/dev/null || pgrep -x "systemd" >/dev/null; then | |
echo "WSL session was initialized. Skipping activation commands." | |
echo "You can manually run activation commands using: $0 -m" | |
else | |
# Ask user if they want to run activation commands | |
read -p "Do you want to run activation commands for Postgres, MySQL...? (y/n): " answer | |
if [[ "$answer" =~ ^[Yy]$ ]]; then | |
activate_commands | |
else | |
echo "Activation commands skipped." | |
fi | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment