Samba shares, host file updates
This commit is contained in:
1
dev-panel.vincentdevelopment.ca/htdocs/info.php
Normal file
1
dev-panel.vincentdevelopment.ca/htdocs/info.php
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<?php phpinfo(); ?>
|
||||||
8
helpers/dev-sites.path
Normal file
8
helpers/dev-sites.path
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Watch for new dev sites
|
||||||
|
|
||||||
|
[Path]
|
||||||
|
PathModified=/var/www
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
6
helpers/dev-sites.service
Normal file
6
helpers/dev-sites.service
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Update hosts entries for dev sites
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/usr/local/bin/update-dev-hosts.sh
|
||||||
56
helpers/gen-wpcontent-shares
Executable file
56
helpers/gen-wpcontent-shares
Executable file
@@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
wwwRoot="/var/www"
|
||||||
|
outFile="/etc/samba/wordops-wpcontent-shares.conf"
|
||||||
|
tmpFile="$(mktemp)"
|
||||||
|
|
||||||
|
# Change these to match your world:
|
||||||
|
sambaGroup="dev" # group allowed to access shares
|
||||||
|
forceGroup="dev" # group to force on created files (optional)
|
||||||
|
|
||||||
|
{
|
||||||
|
echo "; AUTO-GENERATED FILE - DO NOT EDIT"
|
||||||
|
echo "; Generated: $(date -Is)"
|
||||||
|
echo
|
||||||
|
|
||||||
|
shopt -s nullglob
|
||||||
|
for siteDir in "${wwwRoot}"/*; do
|
||||||
|
site="$(basename "${siteDir}")"
|
||||||
|
wpContent="${wwwRoot}/${site}/htdocs/wp-content"
|
||||||
|
|
||||||
|
# Only create shares for sites that look like WP installs
|
||||||
|
if [[ -d "${wpContent}" ]]; then
|
||||||
|
cat <<SHARE
|
||||||
|
|
||||||
|
[${site}]
|
||||||
|
comment = WordPress wp-content for ${site}
|
||||||
|
path = ${wpContent}
|
||||||
|
browseable = yes
|
||||||
|
writable = yes
|
||||||
|
read only = no
|
||||||
|
guest ok = no
|
||||||
|
|
||||||
|
; Lock access down to a group
|
||||||
|
valid users = @${sambaGroup}
|
||||||
|
|
||||||
|
; Keep permissions sane for webserver + devs
|
||||||
|
force group = ${forceGroup}
|
||||||
|
create mask = 0664
|
||||||
|
directory mask = 2775
|
||||||
|
|
||||||
|
; Optional: reduce Finder/Windows junk
|
||||||
|
veto files = /Thumbs.db/.DS_Store/._.DS_Store/
|
||||||
|
SHARE
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
} > "${tmpFile}"
|
||||||
|
|
||||||
|
# Basic sanity check: refuse to install a broken file
|
||||||
|
testparm -s "${tmpFile}" >/dev/null
|
||||||
|
|
||||||
|
sudo mv "${tmpFile}" "${outFile}"
|
||||||
|
sudo chmod 0644 "${outFile}"
|
||||||
|
|
||||||
|
# Reload Samba to pick up new shares (no disconnect like restart)
|
||||||
|
sudo systemctl reload smbd || sudo systemctl reload samba
|
||||||
9
helpers/gen-wpcontent-shares.path
Normal file
9
helpers/gen-wpcontent-shares.path
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Watch /var/www and regenerate Samba shares on change
|
||||||
|
|
||||||
|
[Path]
|
||||||
|
PathChanged=/var/www
|
||||||
|
PathModified=/var/www
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
6
helpers/gen-wpcontent-shares.service
Normal file
6
helpers/gen-wpcontent-shares.service
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Generate Samba shares for WordPress wp-content folders
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/usr/local/sbin/gen-wpcontent-shares
|
||||||
31
helpers/update-dev-hosts.sh
Normal file
31
helpers/update-dev-hosts.sh
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
HOSTS_FILE="/etc/hosts"
|
||||||
|
SITES_DIR="/var/www"
|
||||||
|
DEV_DOMAIN="vincentdevelopment.ca"
|
||||||
|
|
||||||
|
TMP=$(mktemp)
|
||||||
|
|
||||||
|
echo "# BEGIN DEV-SITES" >> "$TMP"
|
||||||
|
|
||||||
|
for dir in "$SITES_DIR"/*; do
|
||||||
|
site=$(basename "$dir")
|
||||||
|
|
||||||
|
# Skip system dirs
|
||||||
|
[[ "$site" == "html" ]] && continue
|
||||||
|
|
||||||
|
echo "127.0.0.1 $site" >> "$TMP"
|
||||||
|
|
||||||
|
# Uncomment when system goes live
|
||||||
|
# echo "127.0.0.1 $site $site.$DEV_DOMAIN"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "# END DEV-SITES" >> "$TMP"
|
||||||
|
|
||||||
|
# Remove existing block
|
||||||
|
sed -i '/# BEGIN DEV-SITES/,/# END DEV-SITES/d' "$HOSTS_FILE"
|
||||||
|
|
||||||
|
# Append fresh block
|
||||||
|
cat "$TMP" >> "$HOSTS_FILE"
|
||||||
|
|
||||||
|
rm "$TMP"
|
||||||
Reference in New Issue
Block a user