Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Commit

Permalink
🎨 Code format.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Kaminski de Souza committed Jan 28, 2021
1 parent 3d1b14d commit 25ea185
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -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}
21 changes: 10 additions & 11 deletions scripts/helpers/cache.sh
Original file line number Diff line number Diff line change
@@ -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=()
Expand All @@ -16,30 +16,29 @@ 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=()
if [ ! "$latest_download" ]; then
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
}
}
11 changes: 5 additions & 6 deletions scripts/helpers/cached_download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@

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
. $this_directory/download_files.sh
. $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
}
}
4 changes: 2 additions & 2 deletions scripts/helpers/delete_duplicates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
8 changes: 4 additions & 4 deletions scripts/helpers/download_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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[@]}

Expand All @@ -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
}
}
27 changes: 13 additions & 14 deletions scripts/helpers/execute_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
fi
23 changes: 11 additions & 12 deletions scripts/helpers/execute_stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
sleep 5
23 changes: 11 additions & 12 deletions scripts/helpers/execute_wait.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
echo
4 changes: 2 additions & 2 deletions scripts/helpers/get_local_host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
# echo "$(get_local_host)"
10 changes: 5 additions & 5 deletions scripts/helpers/get_number_of_logical_processors.sh
Original file line number Diff line number Diff line change
@@ -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)
}
get_number_of_logical_processors() {
logical_cpus=$([ $(uname) = 'Darwin' ] &&
sysctl -n hw.logicalcpu_max ||
lscpu -p | egrep -v '^#' | wc -l)
}
8 changes: 4 additions & 4 deletions scripts/helpers/get_source_dir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
5 changes: 2 additions & 3 deletions scripts/helpers/load_env_vars.sh
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 5 additions & 4 deletions scripts/helpers/regex.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion scripts/helpers/test_get_source_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
source=${BASH_SOURCE[0]}
. $(dirname $source)/get_source_dir.sh
this_directory=$(get_source_dir $source)
echo $this_directory
echo $this_directory
56 changes: 28 additions & 28 deletions scripts/install-neo4j.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
install-neo4j
4 changes: 2 additions & 2 deletions scripts/start-neo4j.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
start-neo4j
Loading

0 comments on commit 25ea185

Please sign in to comment.