summaryrefslogtreecommitdiffstats
path: root/relocate.php
diff options
context:
space:
mode:
authorRemi Collet <fedora@famillecollet.com>2012-06-10 07:17:36 +0200
committerRemi Collet <fedora@famillecollet.com>2012-06-10 07:17:36 +0200
commit0bf18fff7dff14f81c4ba0b16cab92b42b3861f7 (patch)
tree2bacbfde4baf2d3d0c98a1a9cad5137dab352db7 /relocate.php
repo reorg
Diffstat (limited to 'relocate.php')
-rw-r--r--relocate.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/relocate.php b/relocate.php
new file mode 100644
index 0000000..8475b33
--- /dev/null
+++ b/relocate.php
@@ -0,0 +1,61 @@
+<?php
+
+#
+# relocate.php /path/to/file prefix
+#
+# Takes a file as input and a string prefix; reads
+# the file as a serialized data blob and strips PREFIX
+# from the beginning of each string value within the blob.
+# Serializes again and writes output to stdout.
+#
+
+$file = $_SERVER['argv'][1];
+$destdir = $_SERVER['argv'][2];
+
+$destdir_len = strlen($destdir);
+
+function relocate_string($value) {
+ global $destdir, $destdir_len;
+
+ if (strncmp($value, $destdir, $destdir_len) == 0) {
+ $value = substr($value, $destdir_len);
+ }
+ return $value;
+}
+
+function relocate_value($value) {
+ if (is_string($value)) {
+ $value = relocate_string($value);
+ } else if (is_array($value)) {
+ $value = relocate_array($value);
+ }
+
+ return $value;
+}
+
+function relocate_array($array) {
+ $result = array();
+
+ foreach ($array as $key => $value) {
+ if (is_string($key)) {
+ $key = relocate_string($key);
+ }
+ $result[$key] = relocate_value($value);
+ }
+
+ return $result;
+}
+
+$input = file_get_contents($file);
+
+# Special case for /etc/pear.conf.
+if (strncmp($input, "#PEAR_Config 0.9\n", 17) == 0) {
+ echo substr($input, 0, 17);
+ $s = substr($input, 17);
+} else {
+ $s = $input;
+}
+
+echo serialize(relocate_value(unserialize($s)));
+
+?> \ No newline at end of file