Created
February 15, 2025 05:43
-
-
Save stefanpejcic/312fff4af8d363df31cec0ce551b5086 to your computer and use it in GitHub Desktop.
Install WP plugins and themes sets
This file contains hidden or 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 | |
BLUEPRINTS_DIR="/var/www/blueprints" | |
# Function to count valid lines (ignores empty lines and comments) | |
count_valid_lines() { | |
[[ -f "$1" ]] && grep -Evc '^\s*$|^\s*#' "$1" || echo "0" | |
} | |
# Function to validate each line (must be a slug, path, or URL) | |
validate_entry() { | |
local entry="$1" | |
# Check if the entry is a valid slug (alphanumeric + hyphens) or a file path or a URL | |
if [[ "$entry" =~ ^[a-z0-9-]+$ || "$entry" =~ ^/.*\.zip$ || "$entry" =~ ^https?://.*\.zip$ ]]; then | |
return 0 # Valid | |
else | |
return 1 # Invalid | |
fi | |
} | |
# Function to install plugins | |
install_plugins() { | |
local plugins_file="$BLUEPRINTS_DIR/plugins.txt" | |
if [[ -f "$plugins_file" ]]; then | |
local plugin_count=$(count_valid_lines "$plugins_file") | |
echo "Found $plugin_count valid plugins in $plugins_file" | |
if [[ $plugin_count -gt 0 ]]; then | |
echo "Installing plugins..." | |
while IFS= read -r plugin; do | |
[[ -z "$plugin" || "$plugin" =~ ^\s*# ]] && continue # Skip empty lines and comments | |
if validate_entry "$plugin"; then | |
echo "Installing: $plugin" | |
wp plugin install "$plugin" --activate | |
else | |
echo "⚠️ Invalid plugin entry: $plugin (Skipping)" | |
fi | |
done < "$plugins_file" | |
else | |
echo "No valid plugins to install." | |
fi | |
else | |
echo "No plugins.txt found. Skipping plugin installation." | |
fi | |
} | |
# Function to install themes | |
install_themes() { | |
local themes_file="$BLUEPRINTS_DIR/themes.txt" | |
if [[ -f "$themes_file" ]]; then | |
local theme_count=$(count_valid_lines "$themes_file") | |
echo "Found $theme_count valid themes in $themes_file" | |
if [[ $theme_count -gt 0 ]]; then | |
echo "Installing themes..." | |
while IFS= read -r theme; do | |
[[ -z "$theme" || "$theme" =~ ^\s*# ]] && continue # Skip empty lines and comments | |
if validate_entry "$theme"; then | |
echo "Installing: $theme" | |
wp theme install "$theme" --activate | |
else | |
echo "⚠️ Invalid theme entry: $theme (Skipping)" | |
fi | |
done < "$themes_file" | |
else | |
echo "No valid themes to install." | |
fi | |
else | |
echo "No themes.txt found. Skipping theme installation." | |
fi | |
} | |
# Run both functions | |
install_plugins | |
install_themes | |
echo "All installations completed!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment