-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-entrypoint.sh
106 lines (89 loc) · 3.02 KB
/
docker-entrypoint.sh
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bash
set -Eeuo pipefail
sourceTarArgs=(
--create
--file -
--directory /usr/src/wordpress
--owner "www-data" --group "www-data"
)
targetTarArgs=(
--extract
--file -
--directory /var/www/html
)
#Remove akismet plugin
folder="/usr/src/wordpress/wp-content/plugins/akismet"
if [ -d "$folder" ]; then
# Delete the folder and its contents
rm -rf "$folder"
echo "Folder deleted: $folder"
else
echo "Folder does not exist: $folder"
fi
#Remove hello dolly plugin
file_path="/usr/src/wordpress/wp-content/plugins/hello.php"
if [ -f "$file_path" ]; then
echo "Deleting $file_path..."
rm "$file_path"
echo "File deleted successfully."
else
echo "File $file_path does not exist."
fi
#copy nginx config
file_path="/etc/nginx/nginx.conf"
dst_path="/var/www/html/nginx.conf"
if [ -f "$dst_path" ]; then
echo "$dst_path already exist."
else
echo "Creating $dst_path..."
cp "$file_path" "/var/www/html/"
echo "Nginx file copied successfully."
fi
# loop over "pluggable" content in the source, and if it already exists in the destination, skip it
# https://github.com/docker-library/wordpress/issues/506 ("wp-content" persisted, "akismet" updated, WordPress container restarted/recreated, "akismet" downgraded)
for contentPath in \
/usr/src/wordpress/.htaccess \
/usr/src/wordpress/wp-content/*/*/ \
; do
contentPath="${contentPath%/}"
[ -e "$contentPath" ] || continue
contentPath="${contentPath#/usr/src/wordpress/}" # "wp-content/plugins/akismet", etc.
if [ -e "$PWD/$contentPath" ]; then
echo >&2 "WARNING: '$PWD/$contentPath' exists! (not copying the WordPress version)"
sourceTarArgs+=( --exclude "./$contentPath" )
fi
done
if [ -d "/var/www/html/wp-admin" ] && [ -f "/var/www/html/wp-config.php" ] && [ -f "/var/www/html/index.php" ]; then
echo "Wordpress already there skipping..."
else
tar "${sourceTarArgs[@]}" . | tar "${targetTarArgs[@]}"
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
fi
# Add a new user for SFTP access with key-based authentication
USERNAME="sftpuser"
if id "$USERNAME" &>/dev/null; then
echo "User $USERNAME already exists."
else
useradd -m -d /home/sftpuser -s /sbin/nologin sftpuser
mkdir /home/sftpuser/.ssh
fi
chmod 700 /home/sftpuser/.ssh
# Add the public key to the authorized keys file
if [ -v PUBLIC_KEY ]; then
echo "ssh-rsa $PUBLIC_KEY" > /home/sftpuser/.ssh/authorized_keys
chown -R sftpuser:sftpuser /home/sftpuser/.ssh
chmod 600 /home/sftpuser/.ssh/authorized_keys
echo "ssh-rsa $PUBLIC_KEY" > /home/sshuser/.ssh/authorized_keys
chown sshuser:sshgroup /home/sshuser/.ssh/authorized_keys
chmod 600 /home/sshuser/.ssh/authorized_keys
echo "Public key is: $PUBLIC_KEY"
usermod -aG www-data sftpuser
usermod -aG www-data sshuser
chmod -R g+rwx /var/www/html/
chown -R www-data:www-data /var/www/html/
else
echo "PUBLIC_KEY is not defined."
fi
exec "$@"
## echo "127.0.0.1 $(hostname) localhost localhost.localdomain" >> /etc/hosts;
## service sendmail restart