This repository has been archived by the owner on Dec 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsrdb-oneify.sh
executable file
·62 lines (51 loc) · 2.05 KB
/
srdb-oneify.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
#!/bin/bash
#
# Oneify Search Replace DB.
#
# https://github.com/interconnectit/Search-Replace-DB/archive/master.zip
echo "Oneify favicon ..."
sed -i -e "/<meta charset/ {a <link rel=\"icon\" \"data:image/x-icon;base64,$(base64 -w 0 favicon.ico)\">" -e "}" \
templates/html.php
echo "Oneify images ..."
sed -i -e "/^\(.*\)url(..\/img\/branding\.png)\(.*\)$/ {H;s//\1/p;i url('data:image/png;base64,$(base64 -w 0 assets/img/branding.png)')" \
-e "g;s//\2/}" \
assets/css/style.css
sed -i -e "/^\(.*\)url(..\/img\/rotate\.png)\(.*\)$/ {H;s//\1/p;i url('data:image/png;base64,$(base64 -w 0 assets/img/rotate.png)')" \
-e "g;s//\2/}" \
assets/css/style.css
echo "Oneify CSS ..."
sed -i -e "/<link\s*href=\"assets\/css\/style\.css\"/ {a <style type=\"text/css\">" \
-e "r assets/css/style.css" -e "a </style>" -e "d}" \
templates/html.php
echo "Oneify JS ..."
sed -i -e "/<script\s*src=\"assets\/js\/scripts\.js\"/ {a <script>" \
-e "r assets/js/scripts.js" -e "a </script>" -e "d}" \
templates/html.php
# Oneify PHP includes
PHP_SCRIPTS="src/ui.php
index.php"
while read -r PHP; do
# Get list of included files
INCLUDES="$(sed -n -e "s/\b\(include\|require\)\(_once\)\?\s*(\?\s*['\"]\(\S\+\)['\"]\s*)\?\s*;/@@\3@@/p" "$PHP")" #"
if [ -z "$INCLUDES" ]; then
continue
fi
# Add special markers
sed -i -e "s/\b\(include\|require\)\(_once\)\?\s*(\?\s*['\"]\(\S\+\)['\"]\s*)\?\s*;/@@\3@@/" "$PHP"
while read -r INC; do
if ! [ -f "${INC//@@/}" ]; then
continue
fi
echo "Including ${INC//@@/} in ${PHP} ..."
# Test whether PHP needs reopening
PHP_REOPEN=""
if { cat "${INC//@@/}"; echo "<?php"; } | php --syntax-check &> /dev/null; then
PHP_REOPEN="a <?php"
fi
# Replace included filename with its content
sed -i -e "/${INC//\//\\/}/ {a // ${INC//@@/}" -e "a ?>" \
-e "r ${INC//@@/}" -e "$PHP_REOPEN" -e "d}" "$PHP"
done <<< "$INCLUDES"
done <<< "$PHP_SCRIPTS"
# Double check result
php --syntax-check index.php