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

Commit 25ea185

Browse files
author
Daniel Kaminski de Souza
committed
🎨 Code format.
1 parent 3d1b14d commit 25ea185

18 files changed

+110
-114
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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}

scripts/helpers/cache.sh

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/bin/bash
22

33
get_latest_download() {
4-
local cache="$1" # Save first argument in a variable
4+
local cache="$1" # Save first argument in a variable
55
local filename_glob="$2"
66
cd $cache
77
{ # try
88
latest_download="$(ls -r $filename_glob | head -1)"
99
#save your output
10-
} 2> /dev/null || {
10+
} 2>/dev/null || {
1111
# catch
1212
# save log for exception
1313
latest_download=()
@@ -16,30 +16,29 @@ get_latest_download() {
1616
}
1717

1818
check_if_there_is_need_to_download() {
19-
local cache="$1" # Save first argument in a variable
20-
local file_URL="$2" # Save first argument in a variable
21-
local filename="$3" # Save first argument in a variable
19+
local cache="$1" # Save first argument in a variable
20+
local file_URL="$2" # Save first argument in a variable
21+
local filename="$3" # Save first argument in a variable
2222
get_latest_download $cache $filename*
2323

2424
file_to_download=()
2525
if [ ! "$latest_download" ]; then
2626
file_to_download=($file_URL/$filename)
2727
fi
2828
}
29-
get_list_of_files_to_download(){
29+
get_list_of_files_to_download() {
3030
# $1 cache folder
3131
# $2..n files to check if available in cache
32-
local cache="$1" # Save first argument in a variable
33-
shift # Shift all arguments to the left (original $1 gets lost)
32+
local cache="$1" # Save first argument in a variable
33+
shift # Shift all arguments to the left (original $1 gets lost)
3434
local files_info=("$@") # Rebuild the array with rest of arguments
3535
local pattern='(.*):+(.*)'
3636

3737
files_to_download=()
3838

39-
for file_info in "${files_info[@]}"
40-
do
39+
for file_info in "${files_info[@]}"; do
4140
[[ $file_info =~ $pattern ]]
4241
check_if_there_is_need_to_download $cache ${BASH_REMATCH[1]} ${BASH_REMATCH[2]}
4342
files_to_download+=($file_to_download)
4443
done
45-
}
44+
}

scripts/helpers/cached_download.sh

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@
22

33
source=${BASH_SOURCE[0]}
44

5-
cached_download(){
5+
cached_download() {
66
. $(dirname $source)/get_source_dir.sh
77
local this_directory=$(get_source_dir $source)
88
. $this_directory/cache.sh
99
. $this_directory/download_files.sh
1010
. $this_directory/delete_duplicates.sh
1111
# $1 download_info
1212
# $2 cache_folder
13-
local cache="$1" # Save first argument in a variable
14-
shift # Shift all arguments to the left (original $1 gets lost)
13+
local cache="$1" # Save first argument in a variable
14+
shift # Shift all arguments to the left (original $1 gets lost)
1515
local files_info=("$@") # Rebuild the array with rest of arguments
1616
get_list_of_files_to_download $cache "${files_info[@]}"
1717
download_files $cache "${files_to_download[@]}"
1818
delete_duplicates $cache # just in case
1919
cached_downloads=()
2020
local pattern='(.*):+(.*)'
21-
for file_info in ${files_info[@]}
22-
do
21+
for file_info in ${files_info[@]}; do
2322
[[ $file_info =~ $pattern ]]
2423
local file_name=${BASH_REMATCH[2]}
2524
get_latest_download $cache $file_name
2625
cached_downloads+=($cache/$latest_download)
2726
done
28-
}
27+
}

scripts/helpers/delete_duplicates.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# sudo apt-get install fdupes
44

5-
delete_duplicates(){
5+
delete_duplicates() {
66
local folder_to_look_for_duplicates="$1"
77
fdupes -rdN $folder_to_look_for_duplicates
8-
}
8+
}

scripts/helpers/download_files.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
source=${BASH_SOURCE[0]}
44
. $(dirname $source)/get_source_dir.sh
55

6-
download_files(){
6+
download_files() {
77
local this_directory=$(get_source_dir $source)
8-
local cache="$1" # Save first argument in a variable
9-
shift # Shift all arguments to the left (original $1 gets lost)
8+
local cache="$1" # Save first argument in a variable
9+
shift # Shift all arguments to the left (original $1 gets lost)
1010
local files_to_download=("$@") # Rebuild the array with rest of arguments
1111
local number_of_files_to_download=${#files_to_download[@]}
1212

@@ -15,4 +15,4 @@ download_files(){
1515
get_number_of_logical_processors
1616
echo ${files_to_download[@]} | xargs -n 1 -P $logical_cpus wget -q -P $cache --show-progress
1717
fi
18-
}
18+
}

scripts/helpers/execute_start.sh

+13-14
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,25 @@ if [ ! -d "neo4j/data/databases/graph.db" ]; then
1010
echo "Neo4j not installed correctly, run ./scripts/install_neo4j"
1111
exit 1
1212
else
13-
echo "dbms.allow_upgrade=true" >> ./neo4j/conf/neo4j.conf
14-
echo "dbms.recovery.fail_on_missing_files=false" >> ./neo4j/conf/neo4j.conf
13+
echo "dbms.allow_upgrade=true" >>./neo4j/conf/neo4j.conf
14+
echo "dbms.recovery.fail_on_missing_files=false" >>./neo4j/conf/neo4j.conf
1515
# Set initial and max heap to workaround JVM in docker issues
1616
dbms_memory_heap_initial_size="2048m" dbms_memory_heap_max_size="2048m" ./neo4j/bin/neo4j start
1717
echo "Waiting up to 2 minutes for neo4j bolt port ($BOLT_PORT)"
1818

1919
echo "Endpoint is $localhost:$BOLT_PORT"
20-
for i in {1..120};
21-
do
22-
nc -z $localhost $BOLT_PORT -w 2
23-
is_up=$?
24-
if [ $is_up -eq 0 ]; then
25-
echo
26-
echo "Successfully started, neo4j bolt available on $BOLT_PORT"
27-
break
28-
fi
29-
sleep 1
30-
echo -n "."
20+
for i in {1..120}; do
21+
nc -z $localhost $BOLT_PORT -w 2
22+
is_up=$?
23+
if [ $is_up -eq 0 ]; then
24+
echo
25+
echo "Successfully started, neo4j bolt available on $BOLT_PORT"
26+
break
27+
fi
28+
sleep 1
29+
echo -n "."
3130
done
3231
echo
3332
# Wait a further 5 seconds after the port is available
3433
sleep 5
35-
fi
34+
fi

scripts/helpers/execute_stop.sh

+11-12
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@ rm -r neo4j/data/databases/graph.db
1212

1313
echo "Waiting up to 2 minutes for neo4j bolt port ($BOLT_PORT)"
1414

15-
for i in {1..120};
16-
do
17-
nc -z $localhost $BOLT_PORT -w 2
18-
is_up=$?
19-
if [ $is_up -eq 0 ]; then
20-
echo
21-
echo "Successfully started, neo4j bolt available on $BOLT_PORT"
22-
break
23-
fi
24-
sleep 1
25-
echo -n "."
15+
for i in {1..120}; do
16+
nc -z $localhost $BOLT_PORT -w 2
17+
is_up=$?
18+
if [ $is_up -eq 0 ]; then
19+
echo
20+
echo "Successfully started, neo4j bolt available on $BOLT_PORT"
21+
break
22+
fi
23+
sleep 1
24+
echo -n "."
2625
done
2726
echo
2827
# Wait a further 5 seconds after the port is available
29-
sleep 5
28+
sleep 5

scripts/helpers/execute_wait.sh

+11-12
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ load_env_vars
99
echo "Waiting up to 2 minutes for graphql http port ($HTTP_PORT)"
1010

1111
. $this_directory/helpers/get_local_host.sh
12-
for i in {1..120};
13-
do
14-
nc -z $(get_local_host) $HTTP_PORT -w 2
15-
is_up=$?
16-
if [ $is_up -eq 0 ]; then
17-
echo
18-
echo "Successfully started, graphql http available on $HTTP_PORT"
19-
break
20-
fi
21-
sleep 1
22-
echo -n "."
12+
for i in {1..120}; do
13+
nc -z $(get_local_host) $HTTP_PORT -w 2
14+
is_up=$?
15+
if [ $is_up -eq 0 ]; then
16+
echo
17+
echo "Successfully started, graphql http available on $HTTP_PORT"
18+
break
19+
fi
20+
sleep 1
21+
echo -n "."
2322
done
24-
echo
23+
echo

scripts/helpers/get_local_host.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
source=${BASH_SOURCE[0]}
33
. $(dirname $source)/get_source_dir.sh
44

5-
get_local_host(){
5+
get_local_host() {
66
local this_directory=$(get_source_dir $source)
77
local localhost=$(perl $this_directory/regex.pl "$(cat /etc/resolv.conf)")
88
echo $localhost
99
}
10-
# echo "$(get_local_host)"
10+
# echo "$(get_local_host)"
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

3-
get_number_of_logical_processors(){
4-
logical_cpus=$([ $(uname) = 'Darwin' ] &&
5-
sysctl -n hw.logicalcpu_max ||
6-
lscpu -p | egrep -v '^#' | wc -l)
7-
}
3+
get_number_of_logical_processors() {
4+
logical_cpus=$([ $(uname) = 'Darwin' ] &&
5+
sysctl -n hw.logicalcpu_max ||
6+
lscpu -p | egrep -v '^#' | wc -l)
7+
}

scripts/helpers/get_source_dir.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
# Based on:
33
# https://stackoverflow.com/questions/59895/how-can-i-get-the-source-directory-of-a-bash-script-from-within-the-script-itsel
44

5-
get_source_dir(){
5+
get_source_dir() {
66
local this_source=$1
77
while [ -h "$this_source" ]; do # resolve $this_source until the file is no longer a symlink
8-
local this_dir="$( cd -P "$( dirname "$this_source" )" >/dev/null 2>&1 && pwd )"
8+
local this_dir="$(cd -P "$(dirname "$this_source")" >/dev/null 2>&1 && pwd)"
99
this_source="$(readlink "$this_source")"
1010
[[ $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
1111
done
12-
this_dir="$( cd -P "$( dirname "$this_source" )" >/dev/null 2>&1 && pwd )"
12+
this_dir="$(cd -P "$(dirname "$this_source")" >/dev/null 2>&1 && pwd)"
1313
echo $this_dir
14-
}
14+
}

scripts/helpers/load_env_vars.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/bin/bash
22

3-
load_env_vars(){
4-
if [ ! -f ../.env ]
5-
then
3+
load_env_vars() {
4+
if [ ! -f ../.env ]; then
65
export $(cat .env | xargs)
76
fi
87
}

scripts/helpers/regex.pl

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44

55
if ( $ARGV[0] =~ /$regex/ ) {
6-
print "${^MATCH}";
7-
# print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
8-
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
9-
# print "Capture Group 2 is $2 ... and so on\n";
6+
print "${^MATCH}";
7+
8+
# print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
9+
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
10+
# print "Capture Group 2 is $2 ... and so on\n";
1011
}
1112

1213
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'

scripts/helpers/test_get_source_data.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
source=${BASH_SOURCE[0]}
44
. $(dirname $source)/get_source_dir.sh
55
this_directory=$(get_source_dir $source)
6-
echo $this_directory
6+
echo $this_directory

scripts/install-neo4j.sh

+28-28
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
source=${BASH_SOURCE[0]}
44
. $(dirname $source)/helpers/get_source_dir.sh
55

6-
install-neo4j(){
6+
install-neo4j() {
77
local this_directory=$(get_source_dir $source)
88

99
yes | sudo apt-get install fdupes unzip
@@ -17,33 +17,33 @@ install-neo4j(){
1717

1818
graph_db_path="neo4j/data/databases/graph.db"
1919
if [ ! -d $graph_db_path ]; then
20-
if [ ! -L neo4j ]; then
21-
mkdir -p -- neo4j
22-
mkdir -p -- $cache
23-
fi
24-
neo4j_URL=dist.neo4j.org
25-
apoc_URL=https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/$APOC_VERSION
26-
recommendations_URL=https://datastores.s3.amazonaws.com/recommendations/v$DATASTORE_VERSION
27-
neo4j=neo4j-$NEO4J_DIST-$NEO4J_VERSION-unix.tar.gz
28-
apoc=apoc-$APOC_VERSION-all.jar
29-
recommendations=recommendations.db.zip
30-
31-
download_info=("$neo4j_URL:$neo4j" "$apoc_URL:$apoc" "$recommendations_URL:$recommendations")
32-
33-
. $helpers_path/cached_download.sh
34-
cached_download $cache ${download_info[@]}
35-
36-
tar -xzf ${cached_downloads[0]} -C neo4j --strip-components 1
37-
cp ${cached_downloads[1]} neo4j/plugins/$apoc
38-
unzip -o ${cached_downloads[2]}
39-
40-
mv recommendations.db $graph_db_path
41-
rm __MACOSX* -r
42-
43-
neo4j/bin/neo4j-admin set-default-admin $NEO4J_USER
44-
neo4j/bin/neo4j-admin set-initial-password $NEO4J_PASSWORD
20+
if [ ! -L neo4j ]; then
21+
mkdir -p -- neo4j
22+
mkdir -p -- $cache
23+
fi
24+
neo4j_URL=dist.neo4j.org
25+
apoc_URL=https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/$APOC_VERSION
26+
recommendations_URL=https://datastores.s3.amazonaws.com/recommendations/v$DATASTORE_VERSION
27+
neo4j=neo4j-$NEO4J_DIST-$NEO4J_VERSION-unix.tar.gz
28+
apoc=apoc-$APOC_VERSION-all.jar
29+
recommendations=recommendations.db.zip
30+
31+
download_info=("$neo4j_URL:$neo4j" "$apoc_URL:$apoc" "$recommendations_URL:$recommendations")
32+
33+
. $helpers_path/cached_download.sh
34+
cached_download $cache ${download_info[@]}
35+
36+
tar -xzf ${cached_downloads[0]} -C neo4j --strip-components 1
37+
cp ${cached_downloads[1]} neo4j/plugins/$apoc
38+
unzip -o ${cached_downloads[2]}
39+
40+
mv recommendations.db $graph_db_path
41+
rm __MACOSX* -r
42+
43+
neo4j/bin/neo4j-admin set-default-admin $NEO4J_USER
44+
neo4j/bin/neo4j-admin set-initial-password $NEO4J_PASSWORD
4545
else
46-
echo "Database is already installed, skipping"
46+
echo "Database is already installed, skipping"
4747
fi
4848
}
49-
install-neo4j
49+
install-neo4j

scripts/start-neo4j.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
source=${BASH_SOURCE[0]}
44
. $(dirname $source)/helpers/get_source_dir.sh
55

6-
start-neo4j(){
6+
start-neo4j() {
77
local this_directory=$(get_source_dir $source)
88

99
. $this_directory/helpers/get_local_host.sh
1010
localhost=$(get_local_host)
1111
dash $this_directory/helpers/execute_start.sh $this_directory $localhost
1212
}
13-
start-neo4j
13+
start-neo4j

0 commit comments

Comments
 (0)