-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwp-fix-selinux.sh
More file actions
63 lines (51 loc) · 2.75 KB
/
Copy pathwp-fix-selinux.sh
File metadata and controls
63 lines (51 loc) · 2.75 KB
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
#!/bin/bash
# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
BOLD='\033[1m'
NC='\033[0m' # No Color
ok() { echo -e " ${GREEN}✔${NC} $1"; }
fail() { echo -e " ${RED}✘${NC} $1"; }
info() { echo -e " ${BLUE}ℹ${NC} $1"; }
# --- Validate parameter ---
if [[ -z "$1" ]]; then
echo ""
echo -e "${RED}${BOLD}ERROR:${NC} Missing required parameter ${YELLOW}WEB_PATH${NC}"
echo ""
echo -e "${BOLD}Usage:${NC} $0 /path/to/wordpress"
echo -e "${BOLD}Example:${NC} $0 /var/www/virtuals/sm-net.cz/www"
echo ""
exit 1
fi
WEB_PATH="$1"
if [[ ! -d "$WEB_PATH" ]]; then
echo ""
fail "Directory ${YELLOW}$WEB_PATH${NC} does not exist!"
echo ""
exit 1
fi
echo ""
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD} WordPress Permissions Fix${NC}"
echo -e "${BOLD} Path: ${YELLOW}$WEB_PATH${NC}"
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo -e "${BLUE}${BOLD}[1/5]${NC} Creating upgrade directory..."
sudo mkdir -p "$WEB_PATH/wp-content/upgrade" && ok "Created wp-content/upgrade" || fail "Failed to create directory"
echo -e "${BLUE}${BOLD}[2/5]${NC} Setting ownership to apache:apache..."
sudo chown -R apache:apache "$WEB_PATH" && ok "Ownership set" || fail "Failed to set ownership"
echo -e "${BLUE}${BOLD}[3/5]${NC} Setting file permissions..."
sudo find "$WEB_PATH/wp-content" -type d -exec chmod 755 {} \; && ok "Directories set to 755" || fail "Failed to chmod dirs"
sudo find "$WEB_PATH/wp-content" -type f -exec chmod 644 {} \; && ok "Files set to 644" || fail "Failed to chmod files"
echo -e "${BLUE}${BOLD}[4/5]${NC} Configuring SELinux contexts..."
sudo semanage fcontext -a -t httpd_sys_rw_content_t "${WEB_PATH//\//\\/}/wp-content(/.*)?" 2>/dev/null && ok "wp-content context" || info "wp-content context already set"
sudo semanage fcontext -a -t httpd_sys_rw_content_t "${WEB_PATH//\//\\/}/wp-includes(/.*)?" 2>/dev/null && ok "wp-includes context" || info "wp-includes context already set"
sudo semanage fcontext -a -t httpd_sys_rw_content_t "${WEB_PATH//\//\\/}/wp-admin(/.*)?" 2>/dev/null && ok "wp-admin context" || info "wp-admin context already set"
sudo semanage fcontext -a -t httpd_sys_rw_content_t "${WEB_PATH//\//\\/}(/.*)?" 2>/dev/null && ok "Root path context" || info "Root context already set"
echo -e "${BLUE}${BOLD}[5/5]${NC} Restoring SELinux contexts..."
sudo restorecon -Rv "$WEB_PATH" > /dev/null 2>&1 && ok "Contexts restored" || fail "Failed to restore contexts"
echo ""
echo -e "${GREEN}${BOLD} ✔ All done!${NC}"
echo ""