From 25ea185fd305a0bcac281f5145c71463948630a2 Mon Sep 17 00:00:00 2001 From: Daniel Kaminski de Souza Date: Thu, 28 Jan 2021 05:12:21 +0000 Subject: [PATCH] :art: Code format. --- .../neo4j-graphql-js/scripts/helpers/regex.pl | 1 + scripts/helpers/cache.sh | 21 ++++--- scripts/helpers/cached_download.sh | 11 ++-- scripts/helpers/delete_duplicates.sh | 4 +- scripts/helpers/download_files.sh | 8 +-- scripts/helpers/execute_start.sh | 27 +++++---- scripts/helpers/execute_stop.sh | 23 ++++---- scripts/helpers/execute_wait.sh | 23 ++++---- scripts/helpers/get_local_host.sh | 4 +- .../get_number_of_logical_processors.sh | 10 ++-- scripts/helpers/get_source_dir.sh | 8 +-- scripts/helpers/load_env_vars.sh | 5 +- scripts/helpers/regex.pl | 9 +-- scripts/helpers/test_get_source_data.sh | 2 +- scripts/install-neo4j.sh | 56 +++++++++---------- scripts/start-neo4j.sh | 4 +- scripts/stop-and-clear-neo4j.sh | 4 +- scripts/wait-for-graphql.sh | 4 +- 18 files changed, 110 insertions(+), 114 deletions(-) create mode 100644 .vscode/perl-lang/home/daniel/Workspaces/Javascript/neo4j-graphql-js/scripts/helpers/regex.pl diff --git a/.vscode/perl-lang/home/daniel/Workspaces/Javascript/neo4j-graphql-js/scripts/helpers/regex.pl b/.vscode/perl-lang/home/daniel/Workspaces/Javascript/neo4j-graphql-js/scripts/helpers/regex.pl new file mode 100644 index 00000000..796122bb --- /dev/null +++ b/.vscode/perl-lang/home/daniel/Workspaces/Javascript/neo4j-graphql-js/scripts/helpers/regex.pl @@ -0,0 +1 @@ +{"vars":[{"line":0,"kind":2,"name":"strict","containerName":""},{"line":1,"name":"$regex","containerName":null,"kind":13,"localvar":"my","defintion":"my"},{"line":4,"name":"@ARGV","containerName":null,"kind":13}],"version":3} \ No newline at end of file diff --git a/scripts/helpers/cache.sh b/scripts/helpers/cache.sh index 37c68325..2cf910b1 100644 --- a/scripts/helpers/cache.sh +++ b/scripts/helpers/cache.sh @@ -1,13 +1,13 @@ #!/bin/bash get_latest_download() { - local cache="$1" # Save first argument in a variable + local cache="$1" # Save first argument in a variable local filename_glob="$2" cd $cache { # try latest_download="$(ls -r $filename_glob | head -1)" #save your output - } 2> /dev/null || { + } 2>/dev/null || { # catch # save log for exception latest_download=() @@ -16,9 +16,9 @@ get_latest_download() { } check_if_there_is_need_to_download() { - local cache="$1" # Save first argument in a variable - local file_URL="$2" # Save first argument in a variable - local filename="$3" # Save first argument in a variable + local cache="$1" # Save first argument in a variable + local file_URL="$2" # Save first argument in a variable + local filename="$3" # Save first argument in a variable get_latest_download $cache $filename* file_to_download=() @@ -26,20 +26,19 @@ check_if_there_is_need_to_download() { file_to_download=($file_URL/$filename) fi } -get_list_of_files_to_download(){ +get_list_of_files_to_download() { # $1 cache folder # $2..n files to check if available in cache - local cache="$1" # Save first argument in a variable - shift # Shift all arguments to the left (original $1 gets lost) + local cache="$1" # Save first argument in a variable + shift # Shift all arguments to the left (original $1 gets lost) local files_info=("$@") # Rebuild the array with rest of arguments local pattern='(.*):+(.*)' files_to_download=() - for file_info in "${files_info[@]}" - do + for file_info in "${files_info[@]}"; do [[ $file_info =~ $pattern ]] check_if_there_is_need_to_download $cache ${BASH_REMATCH[1]} ${BASH_REMATCH[2]} files_to_download+=($file_to_download) done -} \ No newline at end of file +} diff --git a/scripts/helpers/cached_download.sh b/scripts/helpers/cached_download.sh index 0694be8f..e5d0a73b 100644 --- a/scripts/helpers/cached_download.sh +++ b/scripts/helpers/cached_download.sh @@ -2,7 +2,7 @@ source=${BASH_SOURCE[0]} -cached_download(){ +cached_download() { . $(dirname $source)/get_source_dir.sh local this_directory=$(get_source_dir $source) . $this_directory/cache.sh @@ -10,19 +10,18 @@ cached_download(){ . $this_directory/delete_duplicates.sh # $1 download_info # $2 cache_folder - local cache="$1" # Save first argument in a variable - shift # Shift all arguments to the left (original $1 gets lost) + local cache="$1" # Save first argument in a variable + shift # Shift all arguments to the left (original $1 gets lost) local files_info=("$@") # Rebuild the array with rest of arguments get_list_of_files_to_download $cache "${files_info[@]}" download_files $cache "${files_to_download[@]}" delete_duplicates $cache # just in case cached_downloads=() local pattern='(.*):+(.*)' - for file_info in ${files_info[@]} - do + for file_info in ${files_info[@]}; do [[ $file_info =~ $pattern ]] local file_name=${BASH_REMATCH[2]} get_latest_download $cache $file_name cached_downloads+=($cache/$latest_download) done -} \ No newline at end of file +} diff --git a/scripts/helpers/delete_duplicates.sh b/scripts/helpers/delete_duplicates.sh index af26fb33..7c47f68e 100644 --- a/scripts/helpers/delete_duplicates.sh +++ b/scripts/helpers/delete_duplicates.sh @@ -2,7 +2,7 @@ # sudo apt-get install fdupes -delete_duplicates(){ +delete_duplicates() { local folder_to_look_for_duplicates="$1" fdupes -rdN $folder_to_look_for_duplicates -} \ No newline at end of file +} diff --git a/scripts/helpers/download_files.sh b/scripts/helpers/download_files.sh index 16af97df..4b7349e3 100644 --- a/scripts/helpers/download_files.sh +++ b/scripts/helpers/download_files.sh @@ -3,10 +3,10 @@ source=${BASH_SOURCE[0]} . $(dirname $source)/get_source_dir.sh -download_files(){ +download_files() { local this_directory=$(get_source_dir $source) - local cache="$1" # Save first argument in a variable - shift # Shift all arguments to the left (original $1 gets lost) + local cache="$1" # Save first argument in a variable + shift # Shift all arguments to the left (original $1 gets lost) local files_to_download=("$@") # Rebuild the array with rest of arguments local number_of_files_to_download=${#files_to_download[@]} @@ -15,4 +15,4 @@ download_files(){ get_number_of_logical_processors echo ${files_to_download[@]} | xargs -n 1 -P $logical_cpus wget -q -P $cache --show-progress fi -} \ No newline at end of file +} diff --git a/scripts/helpers/execute_start.sh b/scripts/helpers/execute_start.sh index 7165c13e..02ac1795 100644 --- a/scripts/helpers/execute_start.sh +++ b/scripts/helpers/execute_start.sh @@ -10,26 +10,25 @@ if [ ! -d "neo4j/data/databases/graph.db" ]; then echo "Neo4j not installed correctly, run ./scripts/install_neo4j" exit 1 else - echo "dbms.allow_upgrade=true" >> ./neo4j/conf/neo4j.conf - echo "dbms.recovery.fail_on_missing_files=false" >> ./neo4j/conf/neo4j.conf + echo "dbms.allow_upgrade=true" >>./neo4j/conf/neo4j.conf + echo "dbms.recovery.fail_on_missing_files=false" >>./neo4j/conf/neo4j.conf # Set initial and max heap to workaround JVM in docker issues dbms_memory_heap_initial_size="2048m" dbms_memory_heap_max_size="2048m" ./neo4j/bin/neo4j start echo "Waiting up to 2 minutes for neo4j bolt port ($BOLT_PORT)" echo "Endpoint is $localhost:$BOLT_PORT" - for i in {1..120}; - do - nc -z $localhost $BOLT_PORT -w 2 - is_up=$? - if [ $is_up -eq 0 ]; then - echo - echo "Successfully started, neo4j bolt available on $BOLT_PORT" - break - fi - sleep 1 - echo -n "." + for i in {1..120}; do + nc -z $localhost $BOLT_PORT -w 2 + is_up=$? + if [ $is_up -eq 0 ]; then + echo + echo "Successfully started, neo4j bolt available on $BOLT_PORT" + break + fi + sleep 1 + echo -n "." done echo # Wait a further 5 seconds after the port is available sleep 5 -fi \ No newline at end of file +fi diff --git a/scripts/helpers/execute_stop.sh b/scripts/helpers/execute_stop.sh index fbfa3977..c896d4e8 100644 --- a/scripts/helpers/execute_stop.sh +++ b/scripts/helpers/execute_stop.sh @@ -12,18 +12,17 @@ rm -r neo4j/data/databases/graph.db echo "Waiting up to 2 minutes for neo4j bolt port ($BOLT_PORT)" -for i in {1..120}; - do - nc -z $localhost $BOLT_PORT -w 2 - is_up=$? - if [ $is_up -eq 0 ]; then - echo - echo "Successfully started, neo4j bolt available on $BOLT_PORT" - break - fi - sleep 1 - echo -n "." +for i in {1..120}; do + nc -z $localhost $BOLT_PORT -w 2 + is_up=$? + if [ $is_up -eq 0 ]; then + echo + echo "Successfully started, neo4j bolt available on $BOLT_PORT" + break + fi + sleep 1 + echo -n "." done echo # Wait a further 5 seconds after the port is available -sleep 5 \ No newline at end of file +sleep 5 diff --git a/scripts/helpers/execute_wait.sh b/scripts/helpers/execute_wait.sh index 5e687c4c..cf1a8328 100644 --- a/scripts/helpers/execute_wait.sh +++ b/scripts/helpers/execute_wait.sh @@ -9,16 +9,15 @@ load_env_vars echo "Waiting up to 2 minutes for graphql http port ($HTTP_PORT)" . $this_directory/helpers/get_local_host.sh -for i in {1..120}; - do - nc -z $(get_local_host) $HTTP_PORT -w 2 - is_up=$? - if [ $is_up -eq 0 ]; then - echo - echo "Successfully started, graphql http available on $HTTP_PORT" - break - fi - sleep 1 - echo -n "." +for i in {1..120}; do + nc -z $(get_local_host) $HTTP_PORT -w 2 + is_up=$? + if [ $is_up -eq 0 ]; then + echo + echo "Successfully started, graphql http available on $HTTP_PORT" + break + fi + sleep 1 + echo -n "." done -echo \ No newline at end of file +echo diff --git a/scripts/helpers/get_local_host.sh b/scripts/helpers/get_local_host.sh index fdce1add..8e8c1970 100644 --- a/scripts/helpers/get_local_host.sh +++ b/scripts/helpers/get_local_host.sh @@ -2,9 +2,9 @@ source=${BASH_SOURCE[0]} . $(dirname $source)/get_source_dir.sh -get_local_host(){ +get_local_host() { local this_directory=$(get_source_dir $source) local localhost=$(perl $this_directory/regex.pl "$(cat /etc/resolv.conf)") echo $localhost } -# echo "$(get_local_host)" \ No newline at end of file +# echo "$(get_local_host)" diff --git a/scripts/helpers/get_number_of_logical_processors.sh b/scripts/helpers/get_number_of_logical_processors.sh index 3df6a91b..ff161464 100644 --- a/scripts/helpers/get_number_of_logical_processors.sh +++ b/scripts/helpers/get_number_of_logical_processors.sh @@ -1,7 +1,7 @@ #!/bin/bash -get_number_of_logical_processors(){ - logical_cpus=$([ $(uname) = 'Darwin' ] && - sysctl -n hw.logicalcpu_max || - lscpu -p | egrep -v '^#' | wc -l) -} \ No newline at end of file +get_number_of_logical_processors() { + logical_cpus=$([ $(uname) = 'Darwin' ] && + sysctl -n hw.logicalcpu_max || + lscpu -p | egrep -v '^#' | wc -l) +} diff --git a/scripts/helpers/get_source_dir.sh b/scripts/helpers/get_source_dir.sh index d31dcf93..6ccbc8b7 100644 --- a/scripts/helpers/get_source_dir.sh +++ b/scripts/helpers/get_source_dir.sh @@ -2,13 +2,13 @@ # Based on: # https://stackoverflow.com/questions/59895/how-can-i-get-the-source-directory-of-a-bash-script-from-within-the-script-itsel -get_source_dir(){ +get_source_dir() { local this_source=$1 while [ -h "$this_source" ]; do # resolve $this_source until the file is no longer a symlink - local this_dir="$( cd -P "$( dirname "$this_source" )" >/dev/null 2>&1 && pwd )" + local this_dir="$(cd -P "$(dirname "$this_source")" >/dev/null 2>&1 && pwd)" this_source="$(readlink "$this_source")" [[ $this_source != /* ]] && this_source="$this_dir/$this_source" # if $this_source was a relative symlink, we need to resolve it relative to the path where the symlink file was located done - this_dir="$( cd -P "$( dirname "$this_source" )" >/dev/null 2>&1 && pwd )" + this_dir="$(cd -P "$(dirname "$this_source")" >/dev/null 2>&1 && pwd)" echo $this_dir -} \ No newline at end of file +} diff --git a/scripts/helpers/load_env_vars.sh b/scripts/helpers/load_env_vars.sh index 0f907577..86a9b9c5 100644 --- a/scripts/helpers/load_env_vars.sh +++ b/scripts/helpers/load_env_vars.sh @@ -1,8 +1,7 @@ #!/bin/bash -load_env_vars(){ - if [ ! -f ../.env ] - then +load_env_vars() { + if [ ! -f ../.env ]; then export $(cat .env | xargs) fi } diff --git a/scripts/helpers/regex.pl b/scripts/helpers/regex.pl index 6c050359..cfddb192 100644 --- a/scripts/helpers/regex.pl +++ b/scripts/helpers/regex.pl @@ -3,10 +3,11 @@ if ( $ARGV[0] =~ /$regex/ ) { - print "${^MATCH}"; - # print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n"; - # print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n"; - # print "Capture Group 2 is $2 ... and so on\n"; + print "${^MATCH}"; + + # print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n"; + # print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n"; + # print "Capture Group 2 is $2 ... and so on\n"; } # ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p' diff --git a/scripts/helpers/test_get_source_data.sh b/scripts/helpers/test_get_source_data.sh index d49a012e..44545cde 100644 --- a/scripts/helpers/test_get_source_data.sh +++ b/scripts/helpers/test_get_source_data.sh @@ -3,4 +3,4 @@ source=${BASH_SOURCE[0]} . $(dirname $source)/get_source_dir.sh this_directory=$(get_source_dir $source) -echo $this_directory \ No newline at end of file +echo $this_directory diff --git a/scripts/install-neo4j.sh b/scripts/install-neo4j.sh index dfebe359..805b269c 100644 --- a/scripts/install-neo4j.sh +++ b/scripts/install-neo4j.sh @@ -3,7 +3,7 @@ source=${BASH_SOURCE[0]} . $(dirname $source)/helpers/get_source_dir.sh -install-neo4j(){ +install-neo4j() { local this_directory=$(get_source_dir $source) yes | sudo apt-get install fdupes unzip @@ -17,33 +17,33 @@ install-neo4j(){ graph_db_path="neo4j/data/databases/graph.db" if [ ! -d $graph_db_path ]; then - if [ ! -L neo4j ]; then - mkdir -p -- neo4j - mkdir -p -- $cache - fi - neo4j_URL=dist.neo4j.org - apoc_URL=https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/$APOC_VERSION - recommendations_URL=https://datastores.s3.amazonaws.com/recommendations/v$DATASTORE_VERSION - neo4j=neo4j-$NEO4J_DIST-$NEO4J_VERSION-unix.tar.gz - apoc=apoc-$APOC_VERSION-all.jar - recommendations=recommendations.db.zip - - download_info=("$neo4j_URL:$neo4j" "$apoc_URL:$apoc" "$recommendations_URL:$recommendations") - - . $helpers_path/cached_download.sh - cached_download $cache ${download_info[@]} - - tar -xzf ${cached_downloads[0]} -C neo4j --strip-components 1 - cp ${cached_downloads[1]} neo4j/plugins/$apoc - unzip -o ${cached_downloads[2]} - - mv recommendations.db $graph_db_path - rm __MACOSX* -r - - neo4j/bin/neo4j-admin set-default-admin $NEO4J_USER - neo4j/bin/neo4j-admin set-initial-password $NEO4J_PASSWORD + if [ ! -L neo4j ]; then + mkdir -p -- neo4j + mkdir -p -- $cache + fi + neo4j_URL=dist.neo4j.org + apoc_URL=https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/$APOC_VERSION + recommendations_URL=https://datastores.s3.amazonaws.com/recommendations/v$DATASTORE_VERSION + neo4j=neo4j-$NEO4J_DIST-$NEO4J_VERSION-unix.tar.gz + apoc=apoc-$APOC_VERSION-all.jar + recommendations=recommendations.db.zip + + download_info=("$neo4j_URL:$neo4j" "$apoc_URL:$apoc" "$recommendations_URL:$recommendations") + + . $helpers_path/cached_download.sh + cached_download $cache ${download_info[@]} + + tar -xzf ${cached_downloads[0]} -C neo4j --strip-components 1 + cp ${cached_downloads[1]} neo4j/plugins/$apoc + unzip -o ${cached_downloads[2]} + + mv recommendations.db $graph_db_path + rm __MACOSX* -r + + neo4j/bin/neo4j-admin set-default-admin $NEO4J_USER + neo4j/bin/neo4j-admin set-initial-password $NEO4J_PASSWORD else - echo "Database is already installed, skipping" + echo "Database is already installed, skipping" fi } -install-neo4j \ No newline at end of file +install-neo4j diff --git a/scripts/start-neo4j.sh b/scripts/start-neo4j.sh index 516e3ddb..425c978c 100755 --- a/scripts/start-neo4j.sh +++ b/scripts/start-neo4j.sh @@ -3,11 +3,11 @@ source=${BASH_SOURCE[0]} . $(dirname $source)/helpers/get_source_dir.sh -start-neo4j(){ +start-neo4j() { local this_directory=$(get_source_dir $source) . $this_directory/helpers/get_local_host.sh localhost=$(get_local_host) dash $this_directory/helpers/execute_start.sh $this_directory $localhost } -start-neo4j \ No newline at end of file +start-neo4j diff --git a/scripts/stop-and-clear-neo4j.sh b/scripts/stop-and-clear-neo4j.sh index 40c5e01d..7166c622 100755 --- a/scripts/stop-and-clear-neo4j.sh +++ b/scripts/stop-and-clear-neo4j.sh @@ -3,11 +3,11 @@ source=${BASH_SOURCE[0]} . $(dirname $source)/helpers/get_source_dir.sh -stop-and-clear-neo4j(){ +stop-and-clear-neo4j() { local this_directory=$(get_source_dir $source) . $this_directory/helpers/get_local_host.sh localhost=$(get_local_host) dash $this_directory/helpers/execute_stop.sh $this_directory $localhost } -stop-and-clear-neo4j \ No newline at end of file +stop-and-clear-neo4j diff --git a/scripts/wait-for-graphql.sh b/scripts/wait-for-graphql.sh index f7d816d3..6084ac0d 100755 --- a/scripts/wait-for-graphql.sh +++ b/scripts/wait-for-graphql.sh @@ -3,11 +3,11 @@ source=${BASH_SOURCE[0]} . $(dirname $source)/helpers/get_source_dir.sh -wait-for-graphql(){ +wait-for-graphql() { local this_directory=$(get_source_dir $source) . $this_directory/helpers/get_local_host.sh localhost=$(get_local_host) dash $this_directory/helpers/execute_wait.sh $this_directory $localhost } -wait-for-graphql \ No newline at end of file +wait-for-graphql