summaryrefslogtreecommitdiff
path: root/wordpress/wordpress-rsync-push-site
blob: 69a32c50b3f0f4b1c3ecd8392e7b51de06fff196 (plain)
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
#!/bin/bash
set -e
set -o pipefail

site=${1#/srv/}
site=${site%/}
case "$site" in
	'' | */* | .*) exit 1 ;;
esac
[ -d /srv/"$site" ]
db_host=$(wordpress-config-info "$site" | jq -r .db_host)
db_name=$(wordpress-config-info "$site" | jq -r .db_name)
[ "$db_name" ]


[ "$REMOTE_HOST" ]
remote_host=$REMOTE_HOST

NO_ACT=y

html_dir=/./srv/$site/public_html 
conf_file=/./etc/apache2/sites-available/$site.conf
[ -d "$html_dir" ]
[ -f "$conf_file" ]




installer()
{
	printf 'arg1=%s\n' "$1"
	printf 'arg2=%s\n' "$2"
}

installer_source_code()
{
	echo '#!/bin/sh'
	declare -f installer
	printf 'installer %q %q\n' "$1" "$2"
}

do_rsync()
{
	rsync ${NO_ACT:+ -n} -u -aR --delete --partial "$conf_file" "$html_dir" "$remote_host":"$target_dir"/
}

remote_mysqldump()
{
	if [ "$DO_NOT_USE_SSH" ]
	then
		mysqldump --host="$db_host" "$db_name"
	else
		ssh -- "$db_host" mysqldump "$db_name"
	fi
}

do_mysqldump()
{
	of=$target_dir/srv/$site/wordpress-database~"$(date -Ins)".sql.gz

	dumpfile=$(mktemp -p "$XDG_RUNTIME_DIR") || dumpfile=$(mktemp)
	remote_mysqldump | gzip -c > "$dumpfile"
	rsync ${NO_ACT:+ -n} --ignore-existing "$dumpfile" "$remote_host":"$of"
	rm "$dumpfile"
}

do_installer()
{
	installer_exe=$(mktemp -p "$XDG_RUNTIME_DIR") || installer_exe=$(mktemp)
	installer_source_code "$target_dir" "$of" > "$installer_exe"
}

target_dir=/var/tmp/wordpress-rsync-push-site~$(date -Ins) NO_ACT=
[ "$target_dir" ] || NO_ACT=y
use_rsync=y
do_rsync
do_mysqldump
do_installer