Skip to content

Commit 450cced

Browse files
committed
Converted script to plain sh
1 parent 4c054ea commit 450cced

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

data-export/export.sh

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
#!/usr/bin/env bash
2-
set -o errexit -o errtrace -o noclobber -o nounset -o pipefail
3-
IFS=$'\n\t'
1+
#!/usr/bin/env sh
42

5-
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
3+
script_dir=$(cd "$(dirname "$0")" && pwd)
64

7-
function usage() {
5+
usage() {
86
if [ -n "${1:-}" ]; then
97
>&2 cat <<EOF
108
$1
@@ -13,40 +11,36 @@ EOF
1311
fi
1412

1513
>&2 cat <<EOF
16-
Usage: ${BASH_SOURCE[0]} site-uri
14+
Usage: $0 site-uri
1715
1816
EOF
1917
exit 1
2018
}
2119

22-
if (( $# < 1 )); then
23-
usage "Too few arguments"
24-
fi
25-
2620
site_uri="$1"
2721

2822
if [ -z "$site_uri" ]; then
29-
usage "Invalid site-uri"
23+
usage "Missing site-uri"
3024
fi
3125

3226
# cd "$project_dir"
3327

34-
filenames=("$script_dir"/export_*.sql)
28+
filenames="$script_dir/export_*.sql"
3529

36-
for filename in "${filenames[@]}"; do
30+
for filename in $filenames; do
3731
echo "Running $filename"
3832

3933
# JSON
4034

4135
# https://tldp.org/LDP/abs/html/string-manipulation.html
42-
output_filename=${filename/%.sql/.json}
36+
output_filename="$filename.json"
4337
# https://github.com/drush-ops/drush/issues/3071#issuecomment-347929777
4438
vendor/bin/drush --uri="$site_uri" php:eval "return \Drupal::database()->query(file_get_contents('$filename'))->fetchAll()" --format=json >| "$output_filename" || true
4539
ls -lh "$output_filename"
4640

4741
# CSV
4842

49-
output_filename=${filename/%.sql/.csv}
43+
output_filename="$filename.csv"
5044
# https://stackoverflow.com/a/22421445/2502647
5145
vendor/bin/drush --uri="$site_uri" sql:cli < "$filename" | awk 'BEGIN { FS="\t"; OFS="," } {
5246
rebuilt=0

0 commit comments

Comments
 (0)