├── .gitignore ├── LICENSE ├── README.md ├── ROADMAP.md ├── assert.sh ├── ineo └── test.sh /.gitignore: -------------------------------------------------------------------------------- 1 | bad_tar_for_test 2 | fake_ineo_host 3 | fake_neo4j_host 4 | ineo_for_test 5 | .DS_Store 6 | .idea 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-2020 Carlos Forero 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ineo 2 | 3 | [![Join the chat at https://gitter.im/cohesivestack/ineo](https://badges.gitter.im/cohesivestack/ineo.svg)](https://gitter.im/cohesivestack/ineo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | [![License](https://img.shields.io/github/license/cohesivestack/ineo.svg?style=flat)](https://img.shields.io/github/license/cohesivestack/ineo.svg?style=flat) 5 | [![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/cohesivestack/ineo.svg?style=flat)]((https://img.shields.io/github/languages/code-size/cohesivestack/ineo.svg?style=flat)) 6 | 7 | A simple but useful Neo4j instance manager. 8 | 9 | Neo4j is a great graph database, however its architecture was designed to work with just one database for each Neo4j server instance. This issue could be a problem when we are developing an application with an environment for testing and developing, or just when we are creating or serving two or more applications. 10 | 11 | Ineo figure out this issue allowing to manage different Neo4j instances on different ports. 12 | 13 | ## Requirements 14 | 15 | * **Bash**. Installed by default on OS X and Ubuntu 16 | * **Curl**. Installed by default on OS X and Ubuntu 17 | * **Java**. In order to start the Neo4j server 18 | 19 | ## Installation 20 | 21 | Please check [releases](https://github.com/cohesivestack/ineo/releases) for the [latest version](https://github.com/cohesivestack/ineo/releases/latest) available. 22 | 23 | 1. Execute the line below on your terminal: 24 | 25 | ``` 26 | curl -sSL https://raw.githubusercontent.com/cohesivestack/ineo/v2.1.0/ineo | bash -s install 27 | ``` 28 | 29 | 2. Restart your terminal or execute the line below to set proper environment: 30 | 31 | ``` 32 | source ~/.bashrc 33 | ``` 34 | 35 | ## How to use 36 | 37 | ### Create an instance 38 | 39 | Imagine that you need a database for an application called *my_db*: 40 | 41 | ``` 42 | $ ineo create my_db 43 | 44 | The instance my_db was created successfully 45 | ``` 46 | 47 | ### Show instance information 48 | 49 | Show the information about the recently instance created: 50 | 51 | ``` 52 | $ ineo instances 53 | 54 | > instance 'my_db' 55 | VERSION: 3.5.16 56 | EDITION: community 57 | PATH: /home_path/.ineo/instances/my_db 58 | PORT: 7474 59 | HTTPS: 7475 60 | BOLT: 7476 61 | ``` 62 | 63 | Ineo downloaded the last available version of Neo4j and created an instance database ready to use on port 7474 and 7475 for SSL or bolt port 7476. 64 | 65 | ### Start instance 66 | 67 | Start the database instance for using 68 | 69 | ``` 70 | $ ineo start my_db 71 | 72 | start 'my_db' 73 | Active database: graph.db 74 | Directories in use: 75 | home: /home_path/.ineo/instances/my_db 76 | config: /home_path/.ineo/instances/my_db/conf 77 | logs: /home_path/.ineo/instances/my_db/logs 78 | plugins: /home_path/.ineo/instances/my_db/plugins 79 | import: /home_path/.ineo/instances/my_db/import 80 | data: /home_path/.ineo/instances/my_db/data 81 | certificates: /home_path/.ineo/instances/my_db/certificates 82 | run: /home_path/.ineo/instances/my_db/run 83 | Starting Neo4j. 84 | Started neo4j (pid 12345). It is available at http://0.0.0.0:7474/ 85 | There may be a short delay until the server is ready. 86 | See /home_path/.ineo/instances/my_db/logs/neo4j.log for current status. 87 | ``` 88 | 89 | ### Show instance status 90 | 91 | Show the status of the database instance 92 | 93 | ``` 94 | $ ineo status my_db 95 | 96 | status 'my_db' 97 | Neo4j is running at pid 12345 98 | ``` 99 | 100 | ### Stop instance 101 | 102 | Stop the database instance 103 | 104 | ``` 105 | $ ineo stop my_db 106 | 107 | stop 'my_db' 108 | Stopping Neo4j.. stopped 109 | ``` 110 | 111 | ### Restart instance 112 | 113 | It's also possible to restart a database instance 114 | 115 | ``` 116 | $ ineo restart my_db 117 | ``` 118 | 119 | ## Using with multiple instances 120 | 121 | The main objetive of Ineo is managing different Neo4j instances. 122 | 123 | ### Create an instance with a specific port 124 | 125 | Imagine that you want to create an instance for testing. This should be created with another http port, so both instances can be running simultaneously. 126 | 127 | ``` 128 | $ ineo create -p8486 my_db_test 129 | 130 | The instance my_db_test was successfully created. 131 | ``` 132 | 133 | Now, when you show the information about instances, you see: 134 | 135 | ``` 136 | $ ineo instances 137 | 138 | > instance 'my_db' 139 | VERSION: 3.5.16 140 | EDITION: community 141 | PATH: /home_path/.ineo/instances/my_db 142 | PORT: 7474 143 | HTTPS: 7475 144 | BOLT: 7476 145 | 146 | > instance 'my_db_test' 147 | VERSION: 3.5.16 148 | EDITION: community 149 | PATH: /home_path/.ineo/instances/my_db_test 150 | PORT: 8486 151 | HTTPS: 8487 152 | BOLT: 8488 153 | 154 | ``` 155 | 156 | ### Start multiple instances 157 | 158 | All instances can be started using the command `start` without an instance name. 159 | 160 | ``` 161 | $ ineo start 162 | 163 | Warning -> A Neo4j instance name is not specified. 164 | 165 | Are you sure you want to start all instances? (y/n) y 166 | 167 | 168 | start 'my_db' 169 | Active database: graph.db 170 | Directories in use: 171 | home: /home_path.ineo/instances/my_db 172 | config: /home_path.ineo/instances/my_db/conf 173 | logs: /home_path.ineo/instances/my_db/logs 174 | plugins: /home_path.ineo/instances/my_db/plugins 175 | import: /home_path.ineo/instances/my_db/import 176 | data: /home_path.ineo/instances/my_db/data 177 | certificates: /home_path.ineo/instances/my_db/certificates 178 | run: /home_path.ineo/instances/my_db/run 179 | Starting Neo4j. 180 | Started neo4j (pid 12345). It is available at http://0.0.0.0:7474/ 181 | There may be a short delay until the server is ready. 182 | See /home_path.ineo/instances/my_db/logs/neo4j.log for current status. 183 | 184 | start 'my_db_test' 185 | Active database: graph.db 186 | Directories in use: 187 | home: /home_path.ineo/instances/my_db_test 188 | config: /home_path.ineo/instances/my_db_test/conf 189 | logs: /home_path.ineo/instances/my_db_test/logs 190 | plugins: /home_path.ineo/instances/my_db_test/plugins 191 | import: /home_path.ineo/instances/my_db_test/import 192 | data: /home_path.ineo/instances/my_db_test/data 193 | certificates: /home_path.ineo/instances/my_db_test/certificates 194 | run: /home_path.ineo/instances/my_db_test/run 195 | Starting Neo4j. 196 | Started neo4j (pid 23456). It is available at http://0.0.0.0:8486/ 197 | There may be a short delay until the server is ready. 198 | See /home_path.ineo/instances/my_db_test/logs/neo4j.log for current status. 199 | ``` 200 | 201 | ### Show status for multiple instances 202 | 203 | It's possible to show the status of all instances using the command `stop` without instance name. 204 | 205 | ``` 206 | $ ineo status 207 | 208 | status 'my_db' 209 | Neo4j is running at pid 12345 210 | 211 | status 'my_db_test' 212 | Neo4j is running at pid 23456 213 | ``` 214 | 215 | ### Stop multiple instances 216 | 217 | All instances can be stopped using the command `stop` without instance name. 218 | 219 | ``` 220 | $ ineo stop 221 | 222 | Warning -> A Neo4j instance name is not specified. 223 | 224 | Are you sure you want to stop all instances? (y/n) y 225 | 226 | 227 | stop 'my_db' 228 | Stopping Neo4j.. stopped 229 | 230 | stop 'my_db_test' 231 | Stopping Neo4j.. stopped 232 | ``` 233 | 234 | ### Restart multiple instance 235 | 236 | It's also possible to restart multiple instances using the command `restart` without instance name. 237 | 238 | ``` 239 | $ ineo restart 240 | ``` 241 | 242 | ### Changing the port 243 | 244 | You can change the port to a specific instance. 245 | 246 | ``` 247 | $ ineo set-port my_db 9494 248 | ``` 249 | 250 | The SSL port as well. 251 | 252 | ``` 253 | $ ineo set-port -s my_db 9495 254 | ``` 255 | 256 | Or the bolt port if you like. 257 | 258 | ``` 259 | $ ineo set-port -b my_db 9496 260 | ``` 261 | 262 | ## Installing a specific version 263 | 264 | The command `create` always uses the latest Neo4j version your current Ineo version was tested with. However, it is possible to specify another version using the option `-v` 265 | 266 | ``` 267 | ineo create -v 3.2.0 my_db 268 | ``` 269 | 270 | ### The command versions 271 | 272 | The command `versions` shows all Neo4j versions available for installing. 273 | 274 | ``` 275 | $ ineo versions 276 | ``` 277 | 278 | ## The command install 279 | 280 | There is a command to install Ineo. Use this command only if you don't have already installed Ineo. 281 | 282 | ``` 283 | $ ineo install 284 | ``` 285 | 286 | If you happen to use an OS with systemd support, you can also add Ineo as a systemd service to automatically start up you instances on boot. 287 | 288 | ``` 289 | $ ineo install -S 290 | ``` 291 | 292 | ### Installing in a specific directory 293 | 294 | Ineo is installed in `$HOME/.ineo` by default, however, it is possible to specify another directory using the option `-d`. 295 | 296 | ``` 297 | $ ineo install -d ~/.ineo-custom-path 298 | ``` 299 | 300 | If you are installing from curl: 301 | 302 | ``` 303 | $ curl -sSL https://raw.githubusercontent.com/cohesivestack/ineo/v2.1.0/ineo | bash -s install -d ~/.ineo-custom-path 304 | ``` 305 | 306 | ## Help and other commands 307 | 308 | Just typing `ineo` shows you a brief description of every Ineo command. 309 | 310 | ``` 311 | $ ineo help 312 | 313 | USAGE: 314 | ineo [options] [] 315 | 316 | COMMANDS: 317 | 318 | create Create a new instance with a specific 319 | set-port Change the port of a specific instance 320 | versions Show the Neo4j versions available for installation 321 | list List information about installed instances 322 | 323 | start Start Neo4j instances 324 | stop Stop Neo4j instances 325 | restart Restart Neo4j instances 326 | status Show instances status 327 | shell Start the shell for a Neo4j instance 328 | console Start a Neo4j instance in mode console 329 | 330 | backup Backup a specific database 331 | restore Restore a specific database 332 | 333 | set-config Change settings in configuration file 334 | get-config Read settings from configuration file 335 | 336 | delete-db Delete all data of a specific instance 337 | destroy Remove a specific instance 338 | 339 | install Install ineo 340 | update Update ineo 341 | uninstall Uninstall ineo 342 | 343 | help Show this help or help for specific [command] 344 | ``` 345 | 346 | ### Help for a specific command 347 | 348 | Using `ineo help [command]` you can get the help for a specific command: 349 | 350 | ``` 351 | $ ineo help start 352 | 353 | USAGE: 354 | start [options] [instance_names ...] 355 | 356 | DESCRIPTION: 357 | Start one or more Neo4j instances 358 | 359 | ARGUMENTS: 360 | [instance_names ...] Name of one or more instances to start (optional) 361 | 362 | If this argument is not specified then ineo tries 363 | to start all created instances 364 | 365 | OPTIONS: 366 | -q Start the instances without confirmation 367 | ``` 368 | 369 | ## Tested on 370 | 371 | * macOS X (10.14) 372 | * Ubuntu (18.04) 373 | 374 | ## Roadmap 375 | 376 | Feel free to make suggestions. Use issues for that. 377 | 378 | [https://github.com/cohesivestack/ineo/blob/master/ROADMAP.md](https://github.com/cohesivestack/ineo/blob/master/ROADMAP.md) 379 | 380 | ## Contributing 381 | 382 | Any issue on [https://github.com/cohesivestack/ineo/issues](https://github.com/cohesivestack/ineo/issues) 383 | 384 | Code contributions are welcome. The rules are: 385 | 386 | * Fork the repository 387 | * Always add or modify the test on `test.sh` 388 | * Use correctly indentation (2 spaces) and name conventions 389 | * Pull request 390 | 391 | ## License 392 | 393 | Copyright © 2015-2020 Carlos Forero 394 | 395 | Ineo is released under the [MIT License](LICENSE). 396 | -------------------------------------------------------------------------------- /ROADMAP.md: -------------------------------------------------------------------------------- 1 | # Roadmap 2 | 3 | ## Version 1.3 4 | 5 | * Option to create new instance from existing instance 6 | * Command to execute a simple cypher statement against an instance 7 | 8 | ## Version 1.2 - In development 9 | 10 | * Option to change configuration file 11 | * Command to backup and restore data 12 | * Option for automatic Ineo upgrades 13 | 14 | ## Version 1.1 - Released on Jan 2018 15 | 16 | * Output colors 17 | * Add webserver address during installation 18 | * Make configuration compatible with Neo4j V3 19 | * V3 Add additional bolt port config 20 | * Add choice for Neo4j community or Neo4j enterprise edition 21 | -------------------------------------------------------------------------------- /assert.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # assert.sh 1.1 - bash unit testing framework 3 | # Copyright (C) 2009-2015 Robert Lehmann 4 | # 5 | # http://github.com/lehmannro/assert.sh 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU Lesser General Public License as published 9 | # by the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU Lesser General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General Public License 18 | # along with this program. If not, see . 19 | 20 | export DISCOVERONLY=${DISCOVERONLY:-} 21 | export DEBUG=${DEBUG:-} 22 | export STOP=${STOP:-} 23 | export INVARIANT=${INVARIANT:-} 24 | export CONTINUE=${CONTINUE:-} 25 | 26 | args="$(getopt -n "$0" -l \ 27 | verbose,help,stop,discover,invariant,continue vhxdic $*)" \ 28 | || exit -1 29 | for arg in $args; do 30 | case "$arg" in 31 | -h) 32 | echo "$0 [-vxidc]" \ 33 | "[--verbose] [--stop] [--invariant] [--discover] [--continue]" 34 | echo "`sed 's/./ /g' <<< "$0"` [-h] [--help]" 35 | exit 0;; 36 | --help) 37 | cat < [stdin] 103 | (( tests_ran++ )) || : 104 | [[ -z "$DISCOVERONLY" ]] || return 105 | expected=$(echo -ne "${2:-}") 106 | result="$(eval 2>/dev/null $1 <<< ${3:-})" || true 107 | if [[ "$result" == "$expected" ]]; then 108 | [[ -z "$DEBUG" ]] || echo -n . 109 | return 110 | fi 111 | result="$(sed -e :a -e '$!N;s/\n/\\n/;ta' <<< "$result")" 112 | [[ -z "$result" ]] && result="nothing" || result="\"$result\"" 113 | [[ -z "$2" ]] && expected="nothing" || expected="\"$2\"" 114 | 115 | set +e 116 | diff=$(diff -y <(echo -e "${expected}") <(echo -e "${result}")) 117 | set -e 118 | _assert_fail "expected ${expected}${_indent}got ${result}${_indent}diff \n${diff}" "$1" "$3" 119 | } 120 | 121 | assert_contains() { 122 | # assert_contains [stdin] 123 | (( tests_ran++ )) || : 124 | [[ -z "${DISCOVERONLY}" ]] || return 125 | expected=$(echo -ne "${2:-}") 126 | result="$(eval 2>/dev/null $1 <<< ${3:-})" || true 127 | if [[ "${result}" =~ ${expected} ]]; then 128 | [[ -z "${DEBUG}" ]] || echo -n . 129 | return 130 | fi 131 | result="$(sed -e :a -e '$!N;s/\n/\\n/;ta' <<< "$result")" 132 | [[ -z "${result}" ]] && result="nothing" || result="\"${result}\"" 133 | [[ -z "$2" ]] && expected="nothing" || expected="\"$2\"" 134 | 135 | set +e 136 | diff=$(diff -y <(echo -e "${expected}") <(echo -e "${result}")) 137 | set -e 138 | _assert_fail "expected ${expected}${_indent}got ${result}${_indent}diff \n${diff}" "$1" "$3" 139 | } 140 | 141 | assert_try_raises() { 142 | # assert_raises [stdin] 143 | local tries=$1 144 | (( tests_ran++ )) || : 145 | [[ -z "$DISCOVERONLY" ]] || return 146 | while [[ 0 -lt "$tries" ]]; 147 | do 148 | if [[ "${tries}" -gt 1 ]]; then 149 | sleep 1 150 | fi 151 | status=0 152 | (eval $2 <<< ${4:-}) > /dev/null 2>&1 || status=$? 153 | expected=${3:-0} 154 | if [[ "$status" -eq "$expected" ]]; then 155 | [[ -z "$DEBUG" ]] || echo -n . 156 | return 157 | fi 158 | (( tries-- )) 159 | done 160 | _assert_fail "program terminated with code $status instead of $expected" "$2" "$4" 161 | } 162 | 163 | assert_raises() { 164 | # assert_raises [stdin] 165 | assert_try_raises 1 "$1" "$2" "$3" 166 | } 167 | 168 | _assert_fail() { 169 | # _assert_fail 170 | [[ -n "$DEBUG" ]] && echo -n X 171 | report="test #$tests_ran \"$2${3:+ <<< $3}\" failed:${_indent}$1" 172 | if [[ -n "$STOP" ]]; then 173 | [[ -n "$DEBUG" ]] && echo 174 | echo -e "$report" 175 | exit 1 176 | fi 177 | tests_errors[$tests_failed]="$report" 178 | (( tests_failed++ )) || : 179 | } 180 | 181 | skip_if() { 182 | # skip_if 183 | (eval $@) > /dev/null 2>&1 && status=0 || status=$? 184 | [[ "$status" -eq 0 ]] || return 185 | skip 186 | } 187 | 188 | skip() { 189 | # skip (no arguments) 190 | shopt -q extdebug && tests_extdebug=0 || tests_extdebug=1 191 | shopt -q -o errexit && tests_errexit=0 || tests_errexit=1 192 | # enable extdebug so returning 1 in a DEBUG trap handler skips next command 193 | shopt -s extdebug 194 | # disable errexit (set -e) so we can safely return 1 without causing exit 195 | set +o errexit 196 | tests_trapped=0 197 | trap _skip DEBUG 198 | } 199 | _skip() { 200 | if [[ $tests_trapped -eq 0 ]]; then 201 | # DEBUG trap for command we want to skip. Do not remove the handler 202 | # yet because *after* the command we need to reset extdebug/errexit (in 203 | # another DEBUG trap.) 204 | tests_trapped=1 205 | [[ -z "$DEBUG" ]] || echo -n s 206 | return 1 207 | else 208 | trap - DEBUG 209 | [[ $tests_extdebug -eq 0 ]] || shopt -u extdebug 210 | [[ $tests_errexit -eq 1 ]] || set -o errexit 211 | return 0 212 | fi 213 | } 214 | 215 | 216 | _assert_reset 217 | : ${tests_suite_status:=0} # remember if any of the tests failed so far 218 | _assert_cleanup() { 219 | local status=$? 220 | # modify exit code if it's not already non-zero 221 | [[ $status -eq 0 && -z $CONTINUE ]] && exit $tests_suite_status 222 | } 223 | trap _assert_cleanup EXIT 224 | -------------------------------------------------------------------------------- /ineo: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ineo 2.0.0 - Neo4j Instances Manager 3 | # Copyright (C) 2015-2020 Carlos Forero 4 | # 5 | # http://github.com/carlosforero/ineo 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | # 25 | # Requirements: 26 | # - curl 27 | # - openjdk 28 | 29 | 30 | VERSION=2.0.0 31 | 32 | DEFAULT_HOME="${HOME}/.ineo" 33 | 34 | DEFAULT_VERSION='3.5.16' 35 | 36 | DEFAULT_PORT='7474' 37 | 38 | DEFAULT_EDITION='community' 39 | 40 | DEFAULT_AUTO_DELAY=3 41 | 42 | # NEO4J_HOSTNAME can be assigned from the environment, so can be changed 43 | # with testing to use tars in tars_for_test folder 44 | NEO4J_HOSTNAME="${NEO4J_HOSTNAME:-http://dist.neo4j.org}" 45 | 46 | # INEO_HOSTNAME can be assigned from the environment, so it can be changed 47 | # with testing to use a mock 48 | INEO_HOSTNAME="${INEO_HOSTNAME:-http://ineo.cohesivestack.com}" 49 | 50 | LOCK_DIR='/tmp/ineo.neo4j.instances.lock' 51 | 52 | TEMP_DIR="/tmp/$$.ineo" 53 | INSTANCE_TEMP_DIR="${INEO_HOME}/instances/.tmp" 54 | 55 | SED_CMD="sed -i " 56 | OWNER_CMD="stat -c %u" 57 | 58 | # define color variable to be used in echo, cat, ... 59 | if [[ -n "${TERM:-}" && ${TERM} != "dumb" ]] ; then 60 | readonly BLACK="$(tput setaf 0)" # Black 61 | readonly RED="$(tput setaf 1)" # Red 62 | readonly GREEN="$(tput setaf 2)" # Green 63 | readonly YELLOW="$(tput setaf 3)" # Yellow 64 | readonly BLUE="$(tput setaf 4)" # Blue 65 | readonly PURPLE="$(tput setaf 5)" # Purple 66 | readonly CYAN="$(tput setaf 6)" # Cyan 67 | readonly WHITE="$(tput setaf 7)" # White 68 | readonly UNDERLINE="$(tput smul)" # Underline 69 | readonly ITALIC="$(tput sitm)" # Italic 70 | readonly BOLD="$(tput bold)" # Bold 71 | readonly NF="$(tput sgr0)$(tput rmul)" # No Format 72 | else 73 | # NO TERM NO COLOR 74 | readonly BLACK="" # Black 75 | readonly RED="" # Red 76 | readonly GREEN="" # Green 77 | readonly YELLOW="" # Yellow 78 | readonly BLUE="" # Blue 79 | readonly PURPLE="" # Purple 80 | readonly CYAN="" # Cyan 81 | readonly WHITE="" # White 82 | readonly UNDERLINE="" # Underline 83 | readonly ITALIC="" # Italic 84 | readonly BOLD="" # Bold 85 | readonly NF="" # No Format 86 | fi 87 | 88 | # ============================================================================== 89 | # BASH AUTO COMPLETION 90 | # ============================================================================== 91 | 92 | function ineo_autocompletion { 93 | if [ "${#COMP_WORDS[@]}" -eq "2" ]; then 94 | COMPREPLY=($(compgen -W "create set-port versions instances start stop restart status shell console delete-db 95 | destroy install update uninstall help" "${COMP_WORDS[1]}")) 96 | else 97 | COMPREPLY=$(compgen -W "$(ineo instances|egrep '> instance'|sed "s/> instance '\(.*\)'/ \1/g"|sed "s/\s*//g")" 98 | "${COMP_WORDS[-1]}") 99 | fi 100 | } 101 | 102 | # ============================================================================== 103 | # SET INSTANCES FUNCTION 104 | # ============================================================================== 105 | 106 | function set_instances { 107 | if [[ -d "${INEO_HOME}/instances" ]]; then 108 | local instance_name 109 | for instance_name in $(ls ${INEO_HOME}/instances); do 110 | if [[ -d "${INEO_HOME}/instances/${instance_name}" ]]; then 111 | INSTANCES+=(${instance_name}) 112 | fi 113 | done; 114 | fi 115 | } 116 | 117 | # ============================================================================== 118 | # INVALID COMMAND FUNCTION 119 | # ============================================================================== 120 | 121 | function invalid_command_param { 122 | local param=$1 123 | local command=$2 124 | printf "\n ${PURPLE}Error -> Invalid argument or option ${BOLD}${param}\n" 125 | printf "\n ${NF}View help about the command ${UNDERLINE}${command}${NF} typing:" 126 | printf "\n ${CYAN}ineo help ${command}${NF}\n\n" 127 | } 128 | 129 | # ============================================================================== 130 | # IS INSTANCE RUNNING 131 | # ============================================================================== 132 | 133 | function is_instance_running { 134 | local instance_name=$1 135 | 136 | if [[ $(get_major_version "${instance_name}") -lt 3 ]]; then 137 | if [[ -f "${INEO_HOME}/instances/${instance_name}/data/neo4j-service.pid" ]]; then 138 | exit 0 139 | fi 140 | elif [[ -f "${INEO_HOME}/instances/${instance_name}/run/neo4j.pid" ]]; then 141 | exit 0 142 | fi 143 | exit 1 144 | } 145 | 146 | # ============================================================================== 147 | # GET CONFIGURATION PATH 148 | # ============================================================================== 149 | 150 | function get_configuration_path { 151 | local instance_name=$1 152 | 153 | if [[ $(get_major_version "${instance_name}") -lt 3 ]]; then 154 | echo "${INEO_HOME}/instances/${instance_name}/conf/neo4j-server.properties" 155 | else 156 | echo "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf" 157 | fi 158 | } 159 | 160 | # ============================================================================== 161 | # GET DATABASE PATH 162 | # ============================================================================== 163 | 164 | function get_database_path { 165 | local instance_name=$1 166 | 167 | if [[ $(get_major_version "${instance_name}") -lt 3 ]]; then 168 | echo "${INEO_HOME}/instances/${instance_name}/data/graph.db" 169 | else 170 | echo "${INEO_HOME}/instances/${instance_name}/data/databases/graph.db" 171 | fi 172 | } 173 | 174 | # ============================================================================== 175 | # CONFIGURATION EXISTS 176 | # ============================================================================== 177 | 178 | function configuration_exists { 179 | local instance_name=$1 180 | 181 | if [[ -f $(get_configuration_path "${instance_name}") ]]; then 182 | return 0 183 | fi 184 | return 1 185 | } 186 | 187 | # ============================================================================== 188 | # CONFIGURATION GET 189 | # ============================================================================== 190 | 191 | function configuration_get { 192 | local instance_name=${1} 193 | local param=${2//\./\\.} 194 | local path=$(get_configuration_path "${instance_name}") 195 | 196 | # allow to use glob like asterix 197 | param=${param//\*/.*} 198 | 199 | local result+=$(sed -n "/^\(${param}\)=\(.*\)$/s//\1=\2/p" "${path}") 200 | 201 | echo -e "${result}" 202 | } 203 | 204 | # ============================================================================== 205 | # CONFIGURATION SET 206 | # ============================================================================== 207 | 208 | function configuration_set { 209 | local instance_name=${1} 210 | local param=${2} 211 | local value=${3} 212 | local path=$(get_configuration_path "${instance_name}") 213 | 214 | # first check, if value already exists in config 215 | if [[ -n $(sed -nE "/^#?(${param})=.*$/s//\1/p" "${path}") ]]; then 216 | ${SED_CMD} -E "/^#?(${param})=.*$/s//\1=${value//\//\\/}/" "${path}" 217 | else 218 | # append new parameter to end of config 219 | echo "${param}=${value}" >> "${path}" 220 | fi 221 | 222 | } 223 | 224 | # ============================================================================== 225 | # CONFIGURATION COMMENT 226 | # ============================================================================== 227 | 228 | function configuration_comment { 229 | local instance_name=${1} 230 | local param=${2//\./\\.} 231 | local disable=${3} 232 | local path=$(get_configuration_path "${instance_name}") 233 | local comment="#" 234 | 235 | if [[ "${disable}" == "false" ]]; then 236 | comment="" 237 | fi 238 | 239 | # first check, if value already exists in config 240 | ${SED_CMD} -E "/^#?(${param}=.*)$/s//${comment}\1/" "${path}" 241 | 242 | } 243 | 244 | # ============================================================================== 245 | # GET_INEO 246 | # ============================================================================== 247 | 248 | # access ineo metadata information of an instance 249 | function get_ineo { 250 | local instance_name=$1 251 | local config_name=$2 252 | 253 | # prevent include to override global vars 254 | local neo4j_version 255 | local neo4j_edition 256 | local ineo_start_auto 257 | local ineo_start_order 258 | local ineo_start_delay 259 | 260 | if [[ -f "${INEO_HOME}/instances/${instance_name}/.ineo" ]]; then 261 | source "${INEO_HOME}/instances/${instance_name}/.ineo" 262 | echo ${!config_name} 263 | else 264 | echo 'unknown' 265 | fi 266 | } 267 | 268 | # ============================================================================== 269 | # GET_VERSION 270 | # ============================================================================== 271 | 272 | function get_major_version { 273 | local instance_name=$1 274 | local version=$(get_ineo "${instance_name}" neo4j_version) 275 | echo "${version%%.*}" 276 | } 277 | 278 | function get_minor_version { 279 | local instance_name=$1 280 | local version=$(get_ineo "${instance_name}" neo4j_version) 281 | echo "${version%.*}" 282 | } 283 | 284 | # ============================================================================== 285 | # INSTALL 286 | # ============================================================================== 287 | 288 | function install { 289 | local as_service=false 290 | 291 | shift 292 | while getopts ":d:S" optname 293 | do 294 | case "${optname}" in 295 | d) 296 | INEO_HOME=${OPTARG} 297 | ;; 298 | S) 299 | as_service=true 300 | ;; 301 | *) 302 | invalid_command_param "${OPTARG}" "install" 303 | exit 1 304 | ;; 305 | esac 306 | done 307 | 308 | local arg1=${@:$OPTIND:1} 309 | if [[ -n "${arg1}" ]]; then 310 | invalid_command_param "${arg1}" "install" 311 | exit 1 312 | fi 313 | 314 | # If installation as service requested we need to be root and be on a systemd OS 315 | if [[ "${as_service}" == true ]]; then 316 | # Check if we are root 317 | if [[ "$(whoami)" != "root" ]]; then 318 | printf "\n ${PURPLE}Error -> Installation as a service can only be done by root user${NF}\n\n" 319 | exit 1 320 | fi 321 | 322 | if [[ $(ps -o comm 1 | tail -n 1 ) != "systemd" ]]; then 323 | printf "\n ${PURPLE}Error -> Installation as a service can only be done on a systemd enabled OS${NF}\n\n" 324 | exit 1 325 | fi 326 | 327 | DEFAULT_HOME=/var/lib/ineo 328 | fi 329 | 330 | # Set INEO_HOME variable 331 | if [[ -z "${INEO_HOME}" ]]; then 332 | INEO_HOME=${DEFAULT_HOME} 333 | fi 334 | 335 | # Check if directory is an absolute directory 336 | if [[ ! ${INEO_HOME} =~ ^/ ]]; then 337 | printf "\n ${PURPLE}Error -> The directory ${BOLD}${INEO_HOME}${PURPLE} is not an absolute path\n" 338 | printf "\n ${NF}Use directories like:" 339 | printf "\n ${CYAN}/opt/ineo" 340 | printf "\n ~/.ineo${NF}\n\n" 341 | exit 1 342 | fi 343 | 344 | # Check if directory exists 345 | if [[ -d "${INEO_HOME}" ]]; then 346 | printf "\n ${PURPLE}Error -> The directory ${BOLD}${INEO_HOME}${PURPLE} already exists\n" 347 | printf "\n ${NF}If you want reinstall ineo then uninstall it with:" 348 | printf "\n ${CYAN}ineo uninstall -d \"${INEO_HOME}\"\n" 349 | printf "\n ${NF}or ensure the directory doesn't contain anything important then remove it with:" 350 | printf "\n ${CYAN}rm -r \"${INEO_HOME}\"${NF}\n\n" 351 | exit 1 352 | fi 353 | 354 | # Create folders 355 | local folders=(bin neo4j instances cache) 356 | local folder 357 | for folder in "${folders[@]}"; do 358 | mkdir "${TEMP_DIR}/${folder}" 359 | done 360 | 361 | # self copy to folder bin of ineo 362 | if [[ $(basename "$0") == "ineo" ]]; then 363 | cp "${0}" "${TEMP_DIR}/bin" 364 | else 365 | curl -sSL "${INEO_HOSTNAME}/ineo" > "${TEMP_DIR}/bin/ineo" 366 | fi 367 | 368 | chmod 755 "${TEMP_DIR}/bin/ineo" 369 | 370 | # Create variable 371 | local line_for_bashrc="export INEO_HOME=${INEO_HOME}; export PATH=\$INEO_HOME/bin:\$PATH" 372 | 373 | # If not exists a line with the current Ineo home directory then proceeds to 374 | # create it 375 | if ! grep -Fq "${line_for_bashrc}" ~/.bashrc; then 376 | # Remove any old set variable 377 | sed -i.bak '/export INEO_HOME=/d' ~/.bashrc 378 | 379 | # Add the line in .bashrc to export the variable 380 | echo "${line_for_bashrc}" >> ~/.bashrc 381 | fi 382 | 383 | # Move the TEMP_DIR to the target directory for ineo 384 | mv "${TEMP_DIR}" "${INEO_HOME}" 385 | 386 | # Check if ineo service can be installed 387 | if [[ "${as_service}" == true ]]; then 388 | cat >/lib/systemd/system/ineo.service <"${completion}/ineo" < The variable ${BOLD}\$INEO_HOME${PURPLE} is not set\n" 516 | printf "\n ${NF}Are you sure that Ineo is installed?\n\n" 517 | exit 1 518 | fi 519 | 520 | # Check if the directory is an absolute directory 521 | if [[ ! "${INEO_HOME}" =~ ^/ ]]; then 522 | printf "\n ${PURPLE}Error -> The directory ${BOLD}${INEO_HOME}${PURPLE} is not an absolute path\n" 523 | printf "\n ${NF}Use directories like:" 524 | printf "\n ${CYAN}/opt/ineo" 525 | printf "\n ~/.ineo${NF}\n\n" 526 | exit 1 527 | fi 528 | 529 | if ! ${forced}; then 530 | # Check if the directory exists 531 | if [[ ! -d "${INEO_HOME}" ]]; then 532 | printf "\n ${PURPLE}Error -> The directory ${BOLD}${INEO_HOME}${PURPLE} doesn't exists\n" 533 | printf "\n ${NF}Are you sure that Ineo is installed?\n\n" 534 | exit 1 535 | fi 536 | 537 | # Check if the directory looks like an Ineo directory 538 | if [[ ! -d "${INEO_HOME}/bin" ]] || [[ ! -d "${INEO_HOME}/neo4j" ]] || [[ ! -d "${INEO_HOME}/instances" ]]; then 539 | printf "\n ${YELLOW}Warning -> The directory ${RED}${INEO_HOME}${YELLOW} doesn't look like an Ineo directory.${NF}\n\n" 540 | read -p " Are you sure this directory is an Ineo directory? (y/n) " -r 541 | if [[ ! "${REPLY}" =~ ^[Yy]$ ]]; then 542 | exit 1 543 | fi 544 | fi 545 | 546 | printf "\n ${YELLOW}Warning -> This action will remove everything in ${RED}${INEO_HOME}${NF}\n\n" 547 | read -p " Are you sure you want to do this action? (y/n) " -r 548 | if [[ ! "${REPLY}" =~ ^[Yy]$ ]]; then 549 | exit 1 550 | fi 551 | fi 552 | 553 | # Check if ineo service has been installed 554 | if [[ $(whoami) == "root" ]]; then 555 | if [[ $(ps -o comm 1 | tail -n 1 ) == "systemd" ]]; then 556 | rm /lib/systemd/system/ineo.service 557 | fi 558 | fi 559 | 560 | # Check if ineo bash autocomplete has been installed 561 | local completion 562 | if [[ -O "/etc/bash_completion.d/ineo" ]]; then 563 | rm "/etc/bash_completion.d/ineo" 564 | elif [[ -O "/usr/local/etc/bash_completion.d/ineo" ]]; then 565 | rm "/usr/local/etc/bash_completion.d/ineo" 566 | fi 567 | 568 | # Remove directory 569 | rm -r "${INEO_HOME}" 570 | 571 | # Replace the directories separator (/) by (\/), so it can be used with sed 572 | INEO_HOME=${INEO_HOME//\//\\\/} 573 | # Remove variable in .bashrc 574 | sed -i.bak "/export INEO_HOME=${INEO_HOME}; export PATH=\$INEO_HOME\/bin:\$PATH/d" ~/.bashrc 575 | 576 | printf "\n ${GREEN}Ineo was successfully uninstalled.${NF}\n\n" 577 | exit 0 578 | } 579 | 580 | # ============================================================================== 581 | # VERSION 582 | # ============================================================================== 583 | 584 | function version { 585 | if [[ -n "${2}" ]]; then 586 | invalid_command_param "${2}" "version" 587 | exit 1 588 | fi 589 | 590 | printf "\n The installed version of ineo is ${BOLD}${VERSION}${NF}\n\n" 591 | } 592 | 593 | # ============================================================================== 594 | # UPDATE 595 | # ============================================================================== 596 | 597 | function update { 598 | if [[ -n "${2}" ]]; then 599 | invalid_command_param "${2}" "update" 600 | exit 1 601 | fi 602 | 603 | local local_file=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)/`basename "${BASH_SOURCE[0]}"` 604 | 605 | local remote_file=${TEMP_DIR}/remote_ineo 606 | 607 | curl -s -o "${remote_file}" "${INEO_HOSTNAME}/ineo" 608 | 609 | if cmp --silent "${local_file}" "${remote_file}"; then 610 | printf "\n The last ineo version already is installed!\nso nothing was updated\n\n" 611 | version 612 | else 613 | chmod 700 "${remote_file}" 614 | "${remote_file}" UPDATE_SCRIPT_BATCH "${INEO_HOME}" "${TEMP_DIR}" "${VERSION}" 615 | fi 616 | exit 0 617 | } 618 | 619 | # ============================================================================== 620 | # UPDATE_SCRIPT_BATCH 621 | # ============================================================================== 622 | 623 | function update_script_batch { 624 | 625 | local ineo_home=$2 626 | local temp_dir=$3 627 | local old_version=$4 628 | 629 | local local_file=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)/`basename "${BASH_SOURCE[0]}"` 630 | 631 | cp "${local_file}" "${ineo_home}/bin/ineo" 632 | 633 | printf "\n ${GREEN}Ineo was successfully upgraded from ${BOLD}${old_version}${GREEN} to ${BOLD}${VERSION}${NF}\n\n" 634 | 635 | } 636 | 637 | 638 | # ============================================================================== 639 | # CREATE 640 | # ============================================================================== 641 | 642 | function create { 643 | local port=${DEFAULT_PORT} 644 | local version=${DEFAULT_VERSION} 645 | local edition=${DEFAULT_EDITION} 646 | local force_download=false 647 | local force_install=false 648 | local allow_external_connections=false 649 | 650 | shift 651 | while getopts ":p:s:b:v:e:adf" optname 652 | do 653 | case "${optname}" in 654 | p) 655 | port=${OPTARG} 656 | ;; 657 | s) 658 | https_port=${OPTARG} 659 | ;; 660 | b) 661 | bolt_port=${OPTARG} 662 | ;; 663 | v) 664 | version=${OPTARG} 665 | ;; 666 | e) 667 | edition=${OPTARG} 668 | ;; 669 | a) 670 | allow_external_connections=true 671 | ;; 672 | d) 673 | force_download=true 674 | ;; 675 | f) 676 | force_install=true 677 | ;; 678 | *) 679 | invalid_command_param "${OPTARG}" "create" 680 | exit 1 681 | ;; 682 | esac 683 | done 684 | local instance_name=${@:$OPTIND:1} 685 | 686 | shift 687 | local arg2=${@:$OPTIND:1} 688 | if [[ -n "${arg2}" ]]; then 689 | invalid_command_param "${arg2}" "create" 690 | exit 1 691 | fi 692 | 693 | # The action create always requires an instance name 694 | if [[ -z "${instance_name}" ]]; then 695 | printf "\n ${PURPLE}Error -> create requires an instance name\n" 696 | printf "\n ${NF}View help about the command ${UNDERLINE}create${NF} typing:" 697 | printf "\n ${CYAN}ineo help create${NF}\n\n" 698 | exit 1 699 | fi 700 | 701 | # If directory for the instance exists then a message suggesting run or 702 | # install with the option -f is showed 703 | if [[ -d "${INEO_HOME}/instances/${instance_name}" ]] && ! ${force_install} ; then 704 | printf "\n ${PURPLE}Error -> A directory for the instance ${BOLD}${instance_name}${PURPLE} already exists\n" 705 | printf "\n ${NF}Maybe the instance already was created or try run the command ${UNDERLINE}install${NF} with the -f option to force the installation\n\n" 706 | exit 1 707 | fi 708 | 709 | # Bolt port only works with Neo4j version 3.0 or higher 710 | if [[ "${version%%.*}" -lt 3 && "${bolt_port}" ]]; then 711 | printf "\n ${PURPLE}Error -> Bolt port only works on Neo4j 3.0 or higher\n" 712 | printf "\n ${NF}View help about the command ${UNDERLINE}create${NF} typing:" 713 | printf "\n ${CYAN}ineo help create${NF}\n\n" 714 | exit 1 715 | fi 716 | 717 | # Edition must be either "community" or "enterprise" 718 | if [[ ! "${edition}" =~ ^(community|enterprise)$ ]]; then 719 | printf "\n ${PURPLE}Error -> Edition (-e) must be: 'community' or 'enterprise'\n" 720 | printf "\n ${NF}View help about the command ${UNDERLINE}create${NF} typing:" 721 | printf "\n ${CYAN}ineo help create${NF}\n\n" 722 | exit 1 723 | fi 724 | 725 | local tar_name="neo4j-${edition}-${version}-unix.tar.gz" 726 | 727 | # Download and create tar if doesn't exists 728 | if [[ ! -f "${INEO_HOME}/neo4j/${tar_name}" || "${force_download}" == "true" ]]; then 729 | curl -o "${TEMP_DIR}/${tar_name}" "${NEO4J_HOSTNAME}/${tar_name}" 730 | 731 | mv "${TEMP_DIR}/${tar_name}" "${INEO_HOME}/neo4j/${tar_name}" 732 | fi 733 | 734 | # Create tmp dir to extract to 735 | mkdir -p "${INEO_HOME}/instances/.${instance_name}" 736 | # if not extracted then the tar might have been damaged, so a message suggesting 737 | # to use -d option is shown. Option no-same-owner is needed for autostart purposes using sudo. 738 | if ! tar --no-same-owner --strip 1 -xzf "${INEO_HOME}/neo4j/${tar_name}" \ 739 | -C "${INEO_HOME}/instances/.${instance_name}" &> /dev/null; then 740 | printf "\n ${PURPLE}Error -> The tar file ${BOLD}${tar_name}${PURPLE} can't be extracted\n" 741 | printf "\n ${NF}Try run the command ${UNDERLINE}create${NF} with the -d option to download the tar file again\n\n" 742 | exit 1 743 | fi 744 | 745 | if ${force_install} ; then 746 | rm -rf "${INEO_HOME}/instances/${instance_name}" 747 | fi 748 | 749 | # Create a hidden file with meta information to this installation (e.g. version, edition, ...) 750 | cat >"${INEO_HOME}/instances/.${instance_name}/.ineo" < ${port} ? ${https_port} : ${port}) + 1))} 767 | 768 | # Set the port on the configuration file 769 | set_port "${instance_name}" "${port}" 770 | set_https_port "${instance_name}" "${https_port}" 771 | 772 | if [[ "${version%%.*}" -gt 2 ]]; then 773 | set_bolt_port "${instance_name}" "${bolt_port}" 774 | fi 775 | 776 | # If version is less than 3 and is enterprise then disable the online backup 777 | # by default 778 | if [[ "${version%%.*}" -lt 3 && "${edition}" == "enterprise" ]]; then 779 | ${SED_CMD} "/^\(online_backup_enabled=\).*/s//\1false/" \ 780 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.properties" 781 | fi 782 | 783 | # Set the webserver address in the configuration file 784 | allow_external_connections "${instance_name}" 785 | 786 | printf "\n ${GREEN}The instance ${BOLD}${instance_name}${GREEN} was successfully created.${NF}\n\n" 787 | } 788 | 789 | function allow_external_connections { 790 | local instance_name=$1 791 | if [[ $(get_major_version ${instance_name}) < 3 ]]; then 792 | if [[ "${allow_external_connections}" == true ]]; then 793 | ${SED_CMD} -E "/org.neo4j.server.webserver.address=/ s/^#//g" \ 794 | ${INEO_HOME}/instances/${instance_name}/conf/neo4j-server.properties 795 | fi 796 | else 797 | if [[ $(get_minor_version "${instance_name}") < "3.1" ]]; then 798 | address=localhost 799 | if [[ "${allow_external_connections}" == true ]]; then 800 | address=0.0.0.0 801 | fi 802 | ${SED_CMD} -E "/dbms.connector.http.address=/ s/=.*:([0-9]*)/=${address}:\1/g" \ 803 | ${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf 804 | ${SED_CMD} -E "/dbms.connector.https.address=/ s/=.*:([0-9]*)/=${address}:\1/g" \ 805 | ${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf 806 | ${SED_CMD} -E "/dbms.connector.bolt.address=/ s/=.*:([0-9]*)/=${address}:\1/g" \ 807 | ${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf 808 | else 809 | if [[ "${allow_external_connections}" == false ]]; then 810 | ${SED_CMD} -E "/dbms.connectors.default_listen_address=/ s/^#//g" \ 811 | ${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf 812 | fi 813 | fi 814 | fi 815 | } 816 | 817 | # ============================================================================== 818 | # ACTIONS 819 | # ============================================================================== 820 | 821 | function action { 822 | local action_name=${@:$OPTIND:1} 823 | local quiet=false 824 | 825 | shift 826 | while getopts ":q" optname 827 | do 828 | case "${optname}" in 829 | q) 830 | quiet=true 831 | ;; 832 | *) 833 | invalid_command_param "${OPTARG}" "${action_name}" 834 | exit 1 835 | ;; 836 | esac 837 | done 838 | 839 | local instance_name=${@:$OPTIND:1} 840 | 841 | shift 842 | local arg2=${@:$OPTIND:1} 843 | if [[ -n "${arg2}" ]]; then 844 | invalid_command_param "${arg2}" "${action_name}" 845 | exit 1 846 | fi 847 | 848 | local instances=() 849 | 850 | # If is not specified the instance name, then apply on all instances 851 | if [[ -z "${instance_name}" ]]; then 852 | 853 | # Console requires an instance name 854 | if [[ "${action_name}" == "console" ]]; then 855 | printf "\n ${PURPLE}Error -> console requires an instance name\n" 856 | printf "\n ${NF}View help about the command ${UNDERLINE}console${NF} typing:" 857 | printf "\n ${CYAN}ineo help console${NF}\n\n" 858 | exit 1 859 | fi 860 | 861 | # If no instances then an error messages 862 | if [[ -z "${INSTANCES}" ]]; then 863 | printf "\n ${PURPLE}Error -> No instances created yet\n" 864 | printf "\n ${NF}Try create an instance with the command:" 865 | printf "\n ${CYAN}ineo create [your_instance_name]${NF}\n\n" 866 | fi 867 | 868 | # Confirmation for critical actions 869 | if [[ "${action_name}" =~ ^(start|stop|restart)$ && "${quiet}" == "false" ]]; then 870 | printf "\n ${YELLOW}Warning -> A Neo4j instance name is not specified.${NF}\n\n" 871 | read -p " Are you sure you want to ${action_name} all instances? (y/n) " -r 872 | echo # (optional) move to a new line 873 | if [[ ! "${REPLY}" =~ ^[Yy]$ ]]; then 874 | exit 1 875 | fi 876 | fi 877 | instances=("${INSTANCES[@]}") 878 | else 879 | if [[ ! -d "${INEO_HOME}/instances/${instance_name}" ]]; then 880 | printf "\n ${PURPLE}Error -> There is not an instance with the name ${BOLD}${instance_name}\n" 881 | printf "\n ${NF}You can create an instance with the command:" 882 | printf "\n ${CYAN}ineo create ${instance_name}${NF}\n\n" 883 | exit 1 884 | fi 885 | instances[0]=${instance_name} 886 | fi 887 | 888 | local instance_name 889 | for instance_name in "${instances[@]}"; do 890 | if [[ ! -f "${INEO_HOME}/instances/${instance_name}/bin/neo4j" ]]; then 891 | printf "\n ${PURPLE}Error -> The instance ${BOLD}${instance_name}${PURPLE} seems that is not properly installed\n" 892 | printf "\n ${NF}You can recreate the instance with the command:" 893 | printf "\n ${CYAN}ineo create -f ${instance_name}${NF}\n\n" 894 | exit 1 895 | fi 896 | 897 | printf "\n ${action_name} '${instance_name}'\n " 898 | 899 | "${INEO_HOME}/instances/${instance_name}/bin/neo4j" "${action_name}" 900 | 901 | done 902 | printf "\n" 903 | } 904 | 905 | # ============================================================================== 906 | # AUTOSTART 907 | # ============================================================================== 908 | 909 | function autostart { 910 | # If no instances then an error messages 911 | if [[ -z "${INSTANCES}" ]]; then 912 | printf "\n ${PURPLE}Error -> No instances created yet\n" 913 | printf "\n ${NF}Try create an instance with the command:" 914 | printf "\n ${CYAN}ineo create [your_instance_name]${NF}\n\n" 915 | exit 1 916 | fi 917 | 918 | # Pick all instances with ineo_start_auto = 1 919 | local instance_name 920 | local instance_list 921 | local start_auto 922 | local start_priority 923 | for instance_name in "${INSTANCES[@]}"; do 924 | start_auto=$(get_ineo "${instance_name}" "ineo_start_auto") 925 | if [[ "${start_auto}" == 1 ]]; then 926 | start_priority=$(get_ineo "${instance_name}" "ineo_start_priority") 927 | if [[ -z "${start_priority}" ]]; then 928 | start_priority=0 929 | fi 930 | instance_list+="${start_priority} ${instance_name}\n" 931 | fi 932 | done 933 | 934 | # Order instances by priority 935 | local instances=() 936 | for instance_name in "$(echo -e $instance_list | sort -rn)"; do 937 | instances+=($(echo "${instance_name}" | cut -f2 -d' ')) 938 | done 939 | 940 | local start_delay 941 | local last=${instances[@]: -1:1} 942 | for instance_name in "${instances[@]}"; do 943 | if [[ ! -f "${INEO_HOME}/instances/${instance_name}/bin/neo4j" ]]; then 944 | printf "\n ${PURPLE}Error -> The instance ${BOLD}${instance_name}${PURPLE} seems that is not properly installed\n" 945 | printf "\n ${NF}You can recreate the instance with the command:" 946 | printf "\n ${CYAN}ineo create -f ${instance_name}${NF}\n\n" 947 | exit 1 948 | fi 949 | 950 | # find out whose instance we are going to start 951 | local ownerId=$(${OWNER_CMD} "${INEO_HOME}/instances/${instance_name}/bin/neo4j") 952 | # check if user ID still exists 953 | id -u "${ownerId}" >/dev/null 2>&1 954 | if [[ "$?" -ne 0 ]]; then 955 | printf "\n failed to start '${instance_name} [unknown owner #${ownerId}]'\n " 956 | continue 957 | fi 958 | 959 | printf "\n start '${instance_name}'\n " 960 | 961 | # because we are in autostart, we want to start the instances as if their owner would have started them, 962 | # so they are able to stop and administrate them themselves 963 | sudo -n -u "#${ownerId}" -- "${INEO_HOME}/instances/${instance_name}/bin/neo4j" "start" 964 | 965 | # don't delay if this instance is the last to be autostarted 966 | if [[ "${instance_name}" != "${last}" ]]; then 967 | # delay start of next instance depending on delay setting 968 | # this can prevents server load peaks 969 | start_delay=$(get_ineo "${instance_name}" "ineo_start_delay") 970 | if [[ -z "${start_delay}" ]]; then 971 | start_delay=${DEFAULT_AUTO_DELAY} 972 | fi 973 | printf " delay next start by '${start_delay}' secs\n " 974 | sleep "${start_delay}" 975 | fi 976 | done 977 | } 978 | 979 | # ============================================================================== 980 | # SHELL 981 | # ============================================================================== 982 | 983 | function shell { 984 | shift 985 | while getopts "::" optname 986 | do 987 | case "${optname}" in 988 | *) 989 | invalid_command_param "${OPTARG}" "shell" 990 | exit 1 991 | ;; 992 | esac 993 | done 994 | 995 | local instance_name=${@:$OPTIND:1} 996 | 997 | shift 998 | local arg2=${@:$OPTIND:1} 999 | if [[ -n "${arg2}" ]]; then 1000 | invalid_command_param "${arg2}" "shell" 1001 | exit 1 1002 | fi 1003 | 1004 | # Shell requires an instance name 1005 | if [[ -z "${instance_name}" ]]; then 1006 | printf "\n ${PURPLE}Error -> shell requires an instance name\n" 1007 | printf "\n ${NF}View help about the command ${UNDERLINE}shell${NF} typing:" 1008 | printf "\n ${CYAN}ineo help shell${NF}\n\n" 1009 | exit 1 1010 | fi 1011 | 1012 | # Check if the directory exists 1013 | if [[ ! -d "${INEO_HOME}/instances/${instance_name}" ]]; then 1014 | printf "\n ${PURPLE}Error -> There is not an instance with the name ${BOLD}${instance_name}\n" 1015 | printf "\n ${NF}List installed instances typing:" 1016 | printf "\n ${CYAN}ineo list${NF}\n\n" 1017 | exit 1 1018 | fi 1019 | 1020 | # Check if the instance is running 1021 | if ( ! (is_instance_running "${instance_name}") ); then 1022 | 1023 | printf "\n ${PURPLE}Error -> The instance ${BOLD}${instance_name}${PURPLE} is not running\n" 1024 | printf "\n ${NF}Try start the instance typing:" 1025 | printf "\n ${CYAN}ineo start '${instance_name}'${NF}\n\n" 1026 | exit 1 1027 | fi 1028 | 1029 | "${INEO_HOME}/instances/${instance_name}/bin/neo4j-shell" 1030 | 1031 | exit 0 1032 | 1033 | } 1034 | 1035 | 1036 | # ============================================================================== 1037 | # DESTROY 1038 | # ============================================================================== 1039 | 1040 | function destroy { 1041 | local force=false 1042 | 1043 | shift 1044 | while getopts ":f" optname 1045 | do 1046 | case "${optname}" in 1047 | f) 1048 | force=true 1049 | ;; 1050 | *) 1051 | invalid_command_param "${OPTARG}" "destroy" 1052 | exit 1 1053 | ;; 1054 | esac 1055 | done 1056 | 1057 | local instance_name=${@:$OPTIND:1} 1058 | 1059 | shift 1060 | local arg2=${@:$OPTIND:1} 1061 | if [[ -n "${arg2}" ]]; then 1062 | invalid_command_param "${arg2}" "destroy" 1063 | exit 1 1064 | fi 1065 | 1066 | # Destroy requires an instance name 1067 | if [[ -z "${instance_name}" ]]; then 1068 | printf "\n ${PURPLE}Error -> destroy requires an instance name\n" 1069 | printf "\n ${NF}View help about the command ${UNDERLINE}destroy${NF} typing:" 1070 | printf "\n ${CYAN}ineo help destroy${NF}\n\n" 1071 | exit 1 1072 | fi 1073 | 1074 | # Check if the directory exists 1075 | if [[ ! -d "${INEO_HOME}/instances/${instance_name}" ]]; then 1076 | printf "\n ${PURPLE}Error -> There is not an instance with the name ${BOLD}${instance_name}\n" 1077 | printf "\n ${NF}List installed instances typing:" 1078 | printf "\n ${CYAN}ineo list${NF}" 1079 | exit 1 1080 | fi 1081 | 1082 | # Confirm destroy 1083 | if [[ "${force}" == false ]]; then 1084 | printf "\n ${YELLOW}Warning -> Destroying the instance ${RED}${instance_name}${YELLOW} will remove all data for this instance${NF}\n\n" 1085 | read -p " Are you sure you want to destroy the '${instance_name}'? (y/n) " -r 1086 | echo # (optional) move to a new line 1087 | if [[ ! "${REPLY}" =~ ^[Yy]$ ]]; then 1088 | exit 1 1089 | fi 1090 | fi 1091 | 1092 | # Check if the instance is running 1093 | if ( (is_instance_running "${instance_name}") ); then 1094 | 1095 | if [[ "${force}" == false ]]; then 1096 | printf "\n ${YELLOW}Warning -> The instance ${RED}${instance_name}${YELLOW} is running.${NF}\n\n" 1097 | read -p " Are you sure you want to stop '${instance_name}' and destroy? (y/n) " -r 1098 | echo # (optional) move to a new line 1099 | if [[ ! "${REPLY}" =~ ^[Yy]$ ]]; then 1100 | exit 1 1101 | fi 1102 | fi 1103 | 1104 | # Stop the instance 1105 | "${INEO_HOME}/instances/${instance_name}/bin/neo4j" stop 1106 | fi 1107 | 1108 | rm -fr "${INEO_HOME}/instances/${instance_name}" 1109 | 1110 | printf "\n ${GREEN}The instance ${BOLD}${instance_name}${GREEN} was successfully destroyed.${NF}\n\n" 1111 | exit 0 1112 | 1113 | } 1114 | 1115 | # ============================================================================== 1116 | # LIST 1117 | # ============================================================================== 1118 | 1119 | function list { 1120 | if [[ -n "${2}" ]]; then 1121 | invalid_command_param "${2}" 'list' 1122 | exit 1 1123 | fi 1124 | 1125 | if [[ "${#INSTANCES[@]}" -eq 0 ]]; then 1126 | printf "\n There are not any created instance yet\n" 1127 | printf "\n Create the first one using the command ${UNDERLINE}create${NF}\n" 1128 | printf "\n View help about the command ${UNDERLINE}create${NF} typing:\n" 1129 | printf " ${CYAN}ineo help create${NF}\n" 1130 | else 1131 | local instance_name 1132 | for instance_name in "${INSTANCES[@]}"; do 1133 | 1134 | if [[ $(get_major_version "${instance_name}") -lt 3 ]]; then 1135 | local port=$(sed -n '/^org\.neo4j\.server\.webserver\.port=\(.*\)$/ s//\1/p' \ 1136 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j-server.properties") 1137 | local ssl=$(sed -n '/^org\.neo4j\.server\.webserver\.https\.port=\(.*\)$/ s//\1/p' \ 1138 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j-server.properties") 1139 | else 1140 | if [[ $(get_minor_version "${instance_name}") < "3.1" ]]; then 1141 | local port=$(sed -n '/^dbms\.connector\.http\.address=.*\:\(.*\)$/ s//\1/p' \ 1142 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf") 1143 | local ssl=$(sed -n '/^dbms\.connector\.https\.address=.*\:\(.*\)$/ s//\1/p' \ 1144 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf") 1145 | local bolt=$(sed -n '/^dbms\.connector\.bolt\.address=.*\:\(.*\)$/ s//\1/p' \ 1146 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf") 1147 | else 1148 | local port=$(sed -n '/^dbms\.connector\.http\.listen\_address=.*\:\(.*\)$/ s//\1/p' \ 1149 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf") 1150 | local ssl=$(sed -n '/^dbms\.connector\.https\.listen\_address=.*\:\(.*\)$/ s//\1/p' \ 1151 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf") 1152 | local bolt=$(sed -n '/^dbms\.connector\.bolt\.listen\_address=.*\:\(.*\)$/ s//\1/p' \ 1153 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf") 1154 | fi 1155 | 1156 | if [[ -z "${bolt}" ]]; then 1157 | bolt="(default)" 1158 | fi 1159 | fi 1160 | 1161 | if [[ -z "${port}" ]]; then 1162 | port="(default)" 1163 | fi 1164 | 1165 | if [[ -z "${ssl}" ]]; then 1166 | ssl="(default)" 1167 | fi 1168 | 1169 | local version=$(get_ineo "${instance_name}" neo4j_version) 1170 | local edition=$(get_ineo "${instance_name}" neo4j_edition) 1171 | 1172 | printf "\n > instance '${instance_name}'" 1173 | printf "\n VERSION: ${version}" 1174 | printf "\n EDITION: ${edition}" 1175 | printf "\n PATH: ${INEO_HOME}/instances/${instance_name}" 1176 | printf "\n PORT: ${port}" 1177 | printf "\n HTTPS: ${ssl}\n" 1178 | if [[ $(get_major_version "${instance_name}") -gt 2 ]]; then 1179 | printf " BOLT: ${bolt}\n" 1180 | fi 1181 | done 1182 | printf "\n" 1183 | fi 1184 | } 1185 | 1186 | # ============================================================================== 1187 | # SET-PORT 1188 | # ============================================================================== 1189 | 1190 | function set_port { 1191 | local instance_name=$1 1192 | local port=$2 1193 | 1194 | if [[ $(get_major_version "${instance_name}") -lt 3 ]]; then 1195 | ${SED_CMD} -E "/^(org.neo4j.server.webserver.port=).*/ s//\1${port}/" \ 1196 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j-server.properties" 1197 | else 1198 | if [[ $(get_minor_version "${instance_name}") < "3.1" ]]; then 1199 | ${SED_CMD} -E "/dbms.connector.http.address=/ s/^# *//" \ 1200 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf" 1201 | 1202 | ${SED_CMD} -E "/dbms.connector.http.address=.*/ s/:[0-9]*/:${port}/" \ 1203 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf" 1204 | else 1205 | ${SED_CMD} -E "/dbms.connector.http.listen_address=/ s/^# *//" \ 1206 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf" 1207 | 1208 | ${SED_CMD} -E "/dbms.connector.http.listen_address=.*/ s/:[0-9]*/:${port}/" \ 1209 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf" 1210 | fi 1211 | fi 1212 | } 1213 | 1214 | function set_https_port { 1215 | local instance_name=$1 1216 | local port=$2 1217 | 1218 | if [[ $(get_major_version "${instance_name}") -lt 3 ]]; then 1219 | ${SED_CMD} -E "/^(org.neo4j.server.webserver.https.port=).*/ s//\1${port}/" \ 1220 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j-server.properties" 1221 | else 1222 | if [[ $(get_minor_version "${instance_name}") < "3.1" ]]; then 1223 | ${SED_CMD} -E "/dbms.connector.https.address=/ s/^# *//" \ 1224 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf" 1225 | 1226 | ${SED_CMD} -E "/dbms.connector.https.address=/ s/:[0-9]*/:${port}/" \ 1227 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf" 1228 | else 1229 | ${SED_CMD} -E "/dbms.connector.https.listen_address=/ s/^# *//" \ 1230 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf" 1231 | 1232 | ${SED_CMD} -E "/dbms.connector.https.listen_address=/ s/:[0-9]*/:${port}/" \ 1233 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf" 1234 | fi 1235 | fi 1236 | } 1237 | 1238 | function set_bolt_port { 1239 | local instance_name=$1 1240 | local port=$2 1241 | 1242 | if [[ $(get_major_version "${instance_name}") < 3 ]]; then 1243 | ${SED_CMD} -E "/dbms.connector.bolt.address=/ s/^# *//" \ 1244 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j-server.properties" 1245 | 1246 | ${SED_CMD} -E "/dbms.connector.bolt.address=/ s/:[0-9]*/:${port}/" \ 1247 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j-server.properties" 1248 | else 1249 | if [[ $(get_minor_version "${instance_name}") < "3.1" ]]; then 1250 | ${SED_CMD} -E "/dbms.connector.bolt.address=/ s/^# *//" \ 1251 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf" 1252 | 1253 | ${SED_CMD} -E "/dbms.connector.bolt.address=/ s/:[0-9]*/:${port}/" \ 1254 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf" 1255 | else 1256 | ${SED_CMD} -E "/dbms.connector.bolt.listen_address=/ s/^# *//" \ 1257 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf" 1258 | 1259 | ${SED_CMD} -E "/dbms.connector.bolt.listen_address=/ s/:[0-9]*/:${port}/" \ 1260 | "${INEO_HOME}/instances/${instance_name}/conf/neo4j.conf" 1261 | fi 1262 | fi 1263 | } 1264 | 1265 | # Command 1266 | function set-port { 1267 | local https=false 1268 | local bolt=false 1269 | 1270 | shift 1271 | while getopts ":sb" optname 1272 | do 1273 | case "${optname}" in 1274 | s) 1275 | https=true 1276 | ;; 1277 | b) 1278 | bolt=true 1279 | ;; 1280 | *) 1281 | invalid_command_param "${OPTARG}" "set-port" 1282 | exit 1 1283 | ;; 1284 | esac 1285 | done 1286 | 1287 | local instance_name=${@:$OPTIND:1} 1288 | 1289 | if [[ $(get_major_version ${instance_name}) -lt 3 && "${bolt}" == true ]]; then 1290 | printf "\n ${PURPLE}Error -> Bolt port only works with Neo4j 3.0 or higher\n" 1291 | printf "\n ${NF}View help about the command ${UNDERLINE}set-port${NF} typing:" 1292 | printf "\n ${CYAN}ineo help set-port${NF}\n\n" 1293 | exit 1 1294 | fi 1295 | 1296 | if [[ "${https}" == true && "${bolt}" == true ]]; then 1297 | printf "\n ${PURPLE}Error -> ${BOLD}set-port${PURPLE} can't set bolt and ssl port at the same time\n" 1298 | printf "\n ${NF}View help about the command ${UNDERLINE}set-port${NF} typing:" 1299 | printf "\n ${CYAN}ineo help set-port${NF}\n\n" 1300 | exit 1 1301 | fi 1302 | 1303 | shift 1304 | local port=${@:$OPTIND:1} 1305 | 1306 | shift 1307 | local arg=${@:$OPTIND:1} 1308 | if [[ -n "${arg}" ]]; then 1309 | invalid_command_param "${arg}" "set-port" 1310 | exit 1 1311 | fi 1312 | 1313 | if [[ -z "${instance_name}" || -z "${port}" ]]; then 1314 | printf "\n ${PURPLE}Error -> ${BOLD}set-port${PURPLE} requires an instance name and a port number\n" 1315 | printf "\n ${NF}View help about the command ${UNDERLINE}set-port${NF} typing:" 1316 | printf "\n ${CYAN}ineo help set-port${NF}\n\n" 1317 | exit 1 1318 | fi 1319 | 1320 | if [[ ! "${port}" =~ ^[0-9]+$ ]]; then 1321 | printf "\n ${PURPLE}Error -> The port must be a positive integer number\n" 1322 | printf "\n ${NF}View help about the command ${UNDERLINE}set-port${NF} typing:" 1323 | printf "\n ${CYAN}ineo help set-port${NF}\n\n" 1324 | exit 1 1325 | fi 1326 | 1327 | if (( port < 1 || port > 65535 )); then 1328 | printf "\n ${PURPLE}Error -> The port must be a number between ${BOLD}1${PURPLE} and ${BOLD}65535\n" 1329 | printf "\n ${NF}View help about the command ${UNDERLINE}set-port${NF} typing:" 1330 | printf "\n ${CYAN}ineo help set-port${NF}\n\n" 1331 | exit 1 1332 | fi 1333 | 1334 | # Check if the configuration file doesn't exists 1335 | if ! (configuration_exists ${instance_name}); then 1336 | printf "\n ${PURPLE}Error -> There is not an instance with the name ${BOLD}${instance_name}${PURPLE} or is not properly installed\n" 1337 | printf "\n ${NF}List installed instances typing:" 1338 | printf "\n ${CYAN}ineo list${NF}\n\n" 1339 | exit 1 1340 | fi 1341 | 1342 | if [[ "${https}" == true ]]; then 1343 | set_port "${instance_name}" "${port}" 1344 | 1345 | printf "\n ${GREEN}The https port was successfully changed to ${BOLD}${port}${GREEN}.${NF}\n\n" 1346 | 1347 | elif [[ "${bolt}" == true ]]; then 1348 | set_bolt_port "${instance_name}" "${port}" 1349 | 1350 | printf "\n ${GREEN}The bolt port was successfully changed to ${BOLD}${port}${GREEN}.${NF}\n\n" 1351 | else 1352 | set_https_port "${instance_name}" "${port}" 1353 | 1354 | printf "\n ${GREEN}The http port was successfully changed to ${BOLD}${port}${GREEN}.${NF}\n\n" 1355 | fi 1356 | 1357 | } 1358 | 1359 | # ============================================================================== 1360 | # GET-CONFIG 1361 | # ============================================================================== 1362 | 1363 | # Command 1364 | function get-config { 1365 | local all=false 1366 | local config= 1367 | local output=line 1368 | local param= 1369 | local quiet=false 1370 | local wildcard=false 1371 | 1372 | shift 1373 | while getopts ":o:aq" optname 1374 | do 1375 | case "${optname}" in 1376 | a) 1377 | all=true 1378 | ;; 1379 | o) 1380 | output=${OPTARG} 1381 | ;; 1382 | q) 1383 | quiet=true 1384 | ;; 1385 | *) 1386 | invalid_command_param "${OPTARG}" "get-config" 1387 | exit 1 1388 | ;; 1389 | esac 1390 | done 1391 | shift $((OPTIND-1)) 1392 | 1393 | if [[ ("${all}" == true && "${#}" -ne 1) || ("${all}" == false && "${#}" -lt 2) ]]; then 1394 | printf "\n ${PURPLE}Error -> ${BOLD}get-config${PURPLE} requires an instance name and parameter\n" 1395 | printf "\n ${NF}View help about the command ${UNDERLINE}get-config${NF} typing:" 1396 | printf "\n ${CYAN}ineo help get-config${NF}\n\n" 1397 | exit 1 1398 | fi 1399 | 1400 | if [[ ! "${output}" =~ ^(list|ini|line|value)$ ]]; then 1401 | printf "\n ${PURPLE}Error -> ${BOLD}get-config${PURPLE} has no output ${BOLD}${output}\n" 1402 | printf "\n ${NF}View help about the command ${UNDERLINE}get-config${NF} typing:" 1403 | printf "\n ${CYAN}ineo help get-config${NF}\n\n" 1404 | exit 1 1405 | fi 1406 | 1407 | # take off last argument 1408 | param=${!#} 1409 | # set options without last argument 1410 | set -- "${@:1:$#-1}" 1411 | 1412 | local instances=( ${@} ) 1413 | 1414 | # If is not specified the instance name, then apply on all instances 1415 | if [[ "${all}" == true ]]; then 1416 | 1417 | # If no instances then an error messages 1418 | if [[ -z "${INSTANCES}" ]]; then 1419 | printf "\n ${PURPLE}Error -> No instances created\n" 1420 | printf "\n ${NF}Try create an instance with the command:" 1421 | printf "\n ${CYAN}ineo create [your_instance_name]${NF}\n\n" 1422 | fi 1423 | 1424 | instances=("${INSTANCES[@]}") 1425 | fi 1426 | 1427 | if [[ "${param}" =~ "*" ]]; then 1428 | wildcard=true 1429 | 1430 | # some outputs don't make sense with wildcard search 1431 | if [[ "${param}" =~ "*" && "${output}" == "value" ]]; then 1432 | output="line" 1433 | fi 1434 | fi 1435 | # some outputs don't make sense with multiple instances 1436 | if [[ ${#instances[@]} -gt 1 && ! "${output}" =~ ^(list|ini)$ ]]; then 1437 | output="list" 1438 | fi 1439 | 1440 | local instance_name 1441 | for instance_name in "${instances[@]}"; do 1442 | if ! $(configuration_exists ${instance_name}); then 1443 | printf "\n ${PURPLE}Error -> There is not an instance with the name ${BOLD}${instance_name}\n" 1444 | printf "\n ${NF}You can create an instance with the command:" 1445 | printf "\n ${CYAN}ineo create ${instance_name}${NF}\n\n" 1446 | exit 1 1447 | fi 1448 | 1449 | config=$(configuration_get "${instance_name}" "${param}" | sort) 1450 | 1451 | # give a warning, if querying for a specific value, which doesn't exist in the configuration 1452 | if [[ "${wildcard}" == false && "${#config}" -eq 0 && "${quiet}" == false ]]; then 1453 | config="WARNING: \"${param}\" doesn't exist in the \"${instance_name}\" configuration" 1454 | fi 1455 | 1456 | IFS=$'\n' 1457 | case "${output}" in 1458 | line) 1459 | # this doesn't make sense for multiple instances, but is very nice for coding 1460 | echo -e "${config}" 1461 | ;; 1462 | value) 1463 | # this doesn't make sense for multiple instances, but is very nice for coding 1464 | for value in ${config} 1465 | do 1466 | echo "${value#*=}" 1467 | done 1468 | ;; 1469 | ini) 1470 | # ini like output, where instance name is the section name 1471 | printf "[${instance_name}]" 1472 | if [[ "${#config}" -gt 0 ]]; then 1473 | printf "\n${config}\n" 1474 | fi 1475 | printf "\n" 1476 | ;; 1477 | *) 1478 | printf "\n > instance '${instance_name}'" 1479 | for value in ${config} 1480 | do 1481 | printf "\n ${value}" 1482 | done 1483 | printf "\n\n" 1484 | esac 1485 | 1486 | done 1487 | 1488 | } 1489 | 1490 | # ============================================================================== 1491 | # SET-CONFIG 1492 | # ============================================================================== 1493 | 1494 | # Command 1495 | function set-config { 1496 | local disable=false 1497 | local quiet=false 1498 | local param= 1499 | local value= 1500 | 1501 | shift 1502 | while getopts ":dq" optname 1503 | do 1504 | case "${optname}" in 1505 | d) 1506 | disable=true 1507 | ;; 1508 | q) 1509 | quiet=true 1510 | ;; 1511 | *) 1512 | invalid_command_param "${OPTARG}" "set-config" 1513 | exit 1 1514 | ;; 1515 | esac 1516 | done 1517 | shift $((OPTIND-1)) 1518 | 1519 | if [[ ("${disable}" == true && "${#}" -ne 2) || ("${disable}" == false && "${#}" -ne 3) ]]; then 1520 | printf "\n ${PURPLE}Error -> ${BOLD}set-config${PURPLE} requires an instance name, parameter and value\n" 1521 | printf "\n ${NF}View help about the command ${UNDERLINE}set-config${NF} typing:" 1522 | printf "\n ${CYAN}ineo help set-config${NF}\n\n" 1523 | exit 1 1524 | fi 1525 | 1526 | if [[ "${disable}" == "false" ]]; then 1527 | # take off last argument 1528 | value=${!#} 1529 | # set options without last argument 1530 | set -- "${@:1:$#-1}" 1531 | fi 1532 | 1533 | # take off last argument 1534 | param=${!#} 1535 | # set options without last argument 1536 | set -- "${@:1:$#-1}" 1537 | 1538 | local instances=( ${@} ) 1539 | 1540 | local instance_name 1541 | for instance_name in "${instances[@]}"; do 1542 | if ! $(configuration_exists ${instance_name}); then 1543 | printf "\n ${PURPLE}Error -> There is not an instance with the name ${BOLD}${instance_name}\n" 1544 | printf "\n ${NF}You can create an instance with the command:" 1545 | printf "\n ${CYAN}ineo create ${instance_name}${NF}\n\n" 1546 | exit 1 1547 | fi 1548 | 1549 | ${quiet} || printf "\n > instance '${instance_name}'" 1550 | if [[ "${disable}" == false ]]; then 1551 | $(configuration_set "${instance_name}" "${param}" "${value}") 1552 | ${quiet} || printf "\n ${GREEN}Parameter ${param} set to ${BOLD}${value}${GREEN}.${NF}\n\n" 1553 | else 1554 | $(configuration_comment "${instance_name}" "${param}" "${disable}") 1555 | ${quiet} || printf "\n ${GREEN}Parameter ${param} has been ${BOLD}disabled${GREEN}.${NF}\n\n" 1556 | fi 1557 | 1558 | done 1559 | ${quiet} || printf "\n" 1560 | 1561 | } 1562 | 1563 | # ============================================================================== 1564 | # BACKUP 1565 | # ============================================================================== 1566 | 1567 | # Command 1568 | function backup { 1569 | local path="." 1570 | 1571 | shift 1572 | while getopts ":p:" optname 1573 | do 1574 | case "${optname}" in 1575 | p) 1576 | # remove trailing / 1577 | path=${OPTARG%/} 1578 | ;; 1579 | *) 1580 | invalid_command_param "${OPTARG}" "backup" 1581 | exit 1 1582 | ;; 1583 | esac 1584 | done 1585 | 1586 | local instance_name=${@:$OPTIND:1} 1587 | 1588 | shift 1589 | local arg=${@:$OPTIND:1} 1590 | if [[ -n "${arg}" ]]; then 1591 | invalid_command_param "${arg}" "backup" 1592 | exit 1 1593 | fi 1594 | 1595 | # backup requires an instance name 1596 | if [[ -z "${instance_name}" ]]; then 1597 | printf "\n ${PURPLE}Error -> ${BOLD}backup${PURPLE} requires an instance name\n" 1598 | printf "\n ${NF}View help about the command ${UNDERLINE}backup${NF} typing:" 1599 | printf "\n ${CYAN}ineo help backup${NF}\n\n" 1600 | exit 1 1601 | fi 1602 | 1603 | # backup requires Neo4j >=3.1 1604 | if [[ $(get_minor_version "${instance_name}") < "3.1" ]]; then 1605 | printf "\n ${PURPLE}Error -> ${BOLD}backup${PURPLE} requires instance to run Neo4j version 3.1 or higher\n" 1606 | printf "\n ${NF}View help about the command ${UNDERLINE}backup${NF} typing:" 1607 | printf "\n ${CYAN}ineo help backup${NF}\n\n" 1608 | exit 1 1609 | fi 1610 | 1611 | # Check if the directory exists 1612 | if [[ ! -d "${INEO_HOME}/instances/${instance_name}" ]]; then 1613 | printf "\n ${PURPLE}Error -> There is not an instance with the name ${BOLD}${instance_name}${PURPLE} or is not properly installed\n" 1614 | printf "\n ${NF}List installed instances typing:" 1615 | printf "\n ${CYAN}ineo instances${NF}\n\n" 1616 | exit 1 1617 | fi 1618 | 1619 | # Check if save path exists 1620 | if [[ -d "${path}" ]]; then 1621 | # add filename to path 1622 | path="${path}/ineo_${instance_name}_$(date +"%Y-%m-%d_%H-%M-%S").dump" 1623 | else 1624 | # given path might include filename already, check if dirname is a valid path 1625 | if [[ ! -d "$(dirname "${path}")" ]]; then 1626 | printf "\n ${PURPLE}Error -> The given path ${BOLD}${path}${PURPLE} doesn't exists or is not writable${NF}\n\n" 1627 | exit 1 1628 | fi 1629 | fi 1630 | 1631 | (is_instance_running ${instance_name}) 1632 | local is_running=$? 1633 | # Check if the instance is running 1634 | if [[ "${is_running}" -eq 0 ]]; then 1635 | 1636 | # Stop the instance 1637 | ${INEO_HOME}/instances/${instance_name}/bin/neo4j stop 1638 | fi 1639 | 1640 | "${INEO_HOME}/instances/${instance_name}/bin/neo4j-admin" dump --database="graph.db" --to="${path}" 1641 | 1642 | local success=$? 1643 | if [[ "${success}" -ne 0 ]]; then 1644 | printf "\n ${PURPLE}Error -> The backup failed with return code ${BOLD}${success}${PURPLE}${NF}\n\n" 1645 | exit 1 1646 | fi 1647 | 1648 | if [[ "${is_running}" -eq 0 ]]; then 1649 | 1650 | # Restart the instance 1651 | ${INEO_HOME}/instances/${instance_name}/bin/neo4j start 1652 | fi 1653 | 1654 | printf "\n ${GREEN}The data of the instance ${BOLD}${instance_name}${GREEN} was successfully" 1655 | printf "\n backuped to ${BOLD}${path}${GREEN}${NF}\n\n" 1656 | exit 0 1657 | 1658 | } 1659 | 1660 | # ============================================================================== 1661 | # RESTORE 1662 | # ============================================================================== 1663 | 1664 | # Command 1665 | function restore { 1666 | local force=false 1667 | 1668 | shift 1669 | while getopts ":f" optname 1670 | do 1671 | case "${optname}" in 1672 | f) 1673 | force=true 1674 | ;; 1675 | *) 1676 | invalid_command_param "${OPTARG}" "restore" 1677 | exit 1 1678 | ;; 1679 | esac 1680 | done 1681 | 1682 | local file=${@:$OPTIND:1} 1683 | # Check if the dump file exists 1684 | if [[ ! -f "${file}" ]]; then 1685 | printf "\n ${PURPLE}Error -> No dump file ${BOLD}${file}${PURPLE} found${NF}\n\n" 1686 | exit 1 1687 | fi 1688 | 1689 | shift 1690 | local instance_name=${@:$OPTIND:1} 1691 | # restore requires an instance name 1692 | if [[ -z "${instance_name}" ]]; then 1693 | printf "\n ${PURPLE}Error -> ${BOLD}restore${PURPLE} requires an instance name\n" 1694 | printf "\n ${NF}View help about the command ${UNDERLINE}restore${NF} typing:" 1695 | printf "\n ${CYAN}ineo help restore${NF}\n\n" 1696 | exit 1 1697 | fi 1698 | 1699 | # Check if the directory exists 1700 | if [[ ! -d "${INEO_HOME}/instances/${instance_name}" ]]; then 1701 | printf "\n ${PURPLE}Error -> There is not an instance with the name ${BOLD}${instance_name}${PURPLE} or is not properly installed\n" 1702 | printf "\n ${NF}List installed instances typing:" 1703 | printf "\n ${CYAN}ineo instances${NF}\n\n" 1704 | exit 1 1705 | fi 1706 | 1707 | # restore requires Neo4j >=3.1 1708 | if [[ $(get_minor_version "${instance_name}") < "3.1" ]]; then 1709 | printf "\n ${PURPLE}Error -> ${BOLD}restore${PURPLE} requires instance to run Neo4j version 3.1 or higher\n" 1710 | printf "\n ${NF}View help about the command ${UNDERLINE}restore${NF} typing:" 1711 | printf "\n ${CYAN}ineo help restore${NF}\n\n" 1712 | exit 1 1713 | fi 1714 | 1715 | shift 1716 | local arg=${@:$OPTIND:1} 1717 | if [[ -n "${arg}" ]]; then 1718 | invalid_command_param "${arg}" "restore" 1719 | exit 1 1720 | fi 1721 | 1722 | # Confirm restore 1723 | if [[ "${force}" == false ]]; then 1724 | printf "\n ${YELLOW}Warning -> ${RED}restore${YELLOW} on the instance ${BOLD}${instance_name}${YELLOW} will overwrite all existing data for this instance${NF}\n\n" 1725 | read -p " Are you sure you want to continue overwritting the data for '${instance_name}'? (y/n) " -r 1726 | if [[ ! "${REPLY}" =~ ^[Yy]$ ]]; then 1727 | exit 1 1728 | fi 1729 | fi 1730 | 1731 | (is_instance_running ${instance_name}) 1732 | local is_running=$? 1733 | # Check if the instance is running 1734 | if [[ "${is_running}" -eq 0 ]]; then 1735 | 1736 | # Stop the instance 1737 | ${INEO_HOME}/instances/${instance_name}/bin/neo4j stop 1738 | fi 1739 | 1740 | "${INEO_HOME}/instances/${instance_name}/bin/neo4j-admin" load --from="${file}" --database="graph.db" --force 1741 | 1742 | local success=$? 1743 | if [[ "${success}" -ne 0 ]]; then 1744 | printf "\n ${PURPLE}Error -> The restore failed with return code ${BOLD}${success}${PURPLE}${NF}\n\n" 1745 | exit 1 1746 | fi 1747 | 1748 | if [[ "${is_running}" -eq 0 ]]; then 1749 | 1750 | # Restart the instance 1751 | ${INEO_HOME}/instances/${instance_name}/bin/neo4j start 1752 | fi 1753 | 1754 | printf "\n ${GREEN}The data of the instance ${BOLD}${instance_name}${GREEN} was successfully" 1755 | printf "\n restored from ${BOLD}${file}${GREEN}${NF}\n\n" 1756 | exit 0 1757 | 1758 | } 1759 | 1760 | # ============================================================================== 1761 | # DELETE-DB 1762 | # ============================================================================== 1763 | 1764 | # Command 1765 | function delete-db { 1766 | local force=false 1767 | 1768 | shift 1769 | while getopts ":f" optname 1770 | do 1771 | case "${optname}" in 1772 | f) 1773 | force=true 1774 | ;; 1775 | *) 1776 | invalid_command_param "${OPTARG}" "delete-db" 1777 | exit 1 1778 | ;; 1779 | esac 1780 | done 1781 | 1782 | local instance_name=${@:$OPTIND:1} 1783 | 1784 | shift 1785 | local arg=${@:$OPTIND:1} 1786 | if [[ -n "${arg}" ]]; then 1787 | invalid_command_param "${arg}" "delete-db" 1788 | exit 1 1789 | fi 1790 | 1791 | # delete-db requires an instance name 1792 | if [[ -z "${instance_name}" ]]; then 1793 | printf "\n ${PURPLE}Error -> ${BOLD}delete-db${PURPLE} requires an instance name\n" 1794 | printf "\n ${NF}View help about the command ${UNDERLINE}delete-db${NF} typing:" 1795 | printf "\n ${CYAN}ineo help delete-db${NF}\n\n" 1796 | exit 1 1797 | fi 1798 | 1799 | # Check if the directory exists 1800 | if [[ ! -d "${INEO_HOME}/instances/${instance_name}" ]]; then 1801 | printf "\n ${PURPLE}Error -> There is not an instance with the name ${BOLD}${instance_name}${PURPLE} or is not properly installed\n" 1802 | printf "\n ${NF}List installed instances typing:" 1803 | printf "\n ${CYAN}ineo list${NF}\n\n" 1804 | exit 1 1805 | fi 1806 | 1807 | # Confirm delete-db 1808 | if [[ "${force}" == false ]]; then 1809 | printf "\n ${YELLOW}Warning -> ${RED}delete-db${YELLOW} on the instance ${BOLD}${instance_name}${YELLOW} will remove all data for this instance${NF}\n\n" 1810 | read -p " Are you sure you want to continue clearing the data for '${instance_name}'? (y/n) " -r 1811 | if [[ ! "${REPLY}" =~ ^[Yy]$ ]]; then 1812 | exit 1 1813 | fi 1814 | fi 1815 | 1816 | # Check if the instance is running 1817 | if ( (is_instance_running ${instance_name}) ); then 1818 | 1819 | if [[ "${force}" == false ]]; then 1820 | printf "\n ${YELLOW}Warning -> The instance ${RED}${instance_name}${YELLOW} is running.${NF}\n\n" 1821 | read -p " Are you sure you want to stop '${instance_name}' and clear the data? (y/n) " -r 1822 | 1823 | if [[ ! "${REPLY}" =~ ^[Yy]$ ]]; then 1824 | exit 1 1825 | fi 1826 | fi 1827 | 1828 | # Stop the instance 1829 | ${INEO_HOME}/instances/${instance_name}/bin/neo4j stop 1830 | fi 1831 | 1832 | local dbPath=$(get_database_path "${instance_name}") 1833 | 1834 | if [[ ! -d "${dbPath}" ]]; then 1835 | printf "\n There is not a database on the instance ${UNDERLINE}${instance_name}${NF}, so nothing was removed\n\n" 1836 | exit 0 1837 | fi 1838 | 1839 | rm -rf "${dbPath}" 1840 | 1841 | printf "\n ${GREEN}The data for the instance ${BOLD}${instance_name}${GREEN} was successfully removed${NF}\n\n" 1842 | exit 0 1843 | 1844 | } 1845 | 1846 | # ============================================================================== 1847 | # VERSIONS 1848 | # ============================================================================== 1849 | 1850 | function versions { 1851 | local update=false 1852 | 1853 | shift 1854 | while getopts ":u" optname 1855 | do 1856 | case "${optname}" in 1857 | u) 1858 | update=true 1859 | ;; 1860 | *) 1861 | invalid_command_param "${OPTARG}" "versions" 1862 | exit 1 1863 | ;; 1864 | esac 1865 | done 1866 | 1867 | local arg2=${@:$OPTIND:1} 1868 | if [[ -n "${arg2}" ]]; then 1869 | invalid_command_param "${arg2}" "versions" 1870 | exit 1 1871 | fi 1872 | 1873 | local fetch='' 1874 | local page=1 1875 | local cache_file=${INEO_HOME}/cache/versions 1876 | local releases='' 1877 | local error='' 1878 | 1879 | if [[ ! -f "${cache_file}" || ! -s "${cache_file}" || "${update}" == "true" ]]; then 1880 | while [ "${page}" -eq 1 ] || [ ! -z "${fetch}" ]; do 1881 | fetch="$(curl -s https://api.github.com/repos/neo4j/neo4j/tags?page=${page})" 1882 | fetch="$(echo "${fetch}" | grep -o -E '"[0-9]+\.[0-9]+\.[0-9]+"' | sed 's/"/ /g')" 1883 | releases+="${fetch}\n" 1884 | ((page++)) 1885 | done 1886 | releases="$(echo -e "${releases}" | sort )" 1887 | 1888 | if [[ -z "${releases}" ]]; then 1889 | error="\n ${PURPLE}Error -> Is not possible to connect to the Neo4j Github site.${NF}\n Please check your internet connection or retry in some minutes\n\n" 1890 | else 1891 | echo -e "${releases}" > "${cache_file}" 1892 | fi 1893 | fi 1894 | 1895 | if [[ -f "${cache_file}" && -s "${cache_file}" ]]; then 1896 | local updated_at="$(ls -l ${cache_file} | awk '{print $6, $7, $8 }')" 1897 | cat "${cache_file}" | sed "s/${DEFAULT_VERSION}/${DEFAULT_VERSION} <- recommended and default for this Ineo's installation/" 1898 | printf "\n These are the Neo4j versions available until ${updated_at}\n" 1899 | printf "\n If you want to update this list type:" 1900 | printf "\n ${CYAN}ineo versions -u${NF}\n\n" 1901 | fi 1902 | 1903 | if [[ -n "${error}" ]]; then 1904 | printf "${error}" 1905 | fi 1906 | } 1907 | 1908 | # ============================================================================== 1909 | # HELP 1910 | # ============================================================================== 1911 | 1912 | function help { 1913 | if [[ -z "${1}" ]]; then 1914 | printf "${HELP}" 1915 | else 1916 | command=$(echo "help_$1" | tr '[:lower:]' '[:upper:]' | tr '-' '_') 1917 | printf "${!command}" 1918 | fi 1919 | } 1920 | 1921 | # ============================================================================== 1922 | # HELPS 1923 | # ============================================================================== 1924 | 1925 | HELP=" 1926 | USAGE: 1927 | ineo [options] [] 1928 | 1929 | COMMANDS: 1930 | 1931 | create Create a new instance with a specific 1932 | set-port Change the port of a specific instance 1933 | versions Show the Neo4j versions available for installation 1934 | list List information about installed instances 1935 | 1936 | start Start Neo4j instances 1937 | stop Stop Neo4j instances 1938 | restart Restart Neo4j instances 1939 | status Show instances status 1940 | shell Start the shell for a Neo4j instance 1941 | console Start a Neo4j instance in mode console 1942 | 1943 | backup Backup a specific database 1944 | restore Restore a specific database 1945 | 1946 | set-config Change settings in configuration file 1947 | get-config Read settings from configuration file 1948 | 1949 | delete-db Delete all data of a specific instance 1950 | destroy Remove a specific instance 1951 | 1952 | install Install ineo 1953 | update Update ineo 1954 | uninstall Uninstall ineo 1955 | 1956 | help Show this help or help for specific [command] 1957 | 1958 | " 1959 | 1960 | HELP_CREATE=" 1961 | USAGE: 1962 | create [options] 1963 | 1964 | DESCRIPTION: 1965 | Create a new instance 1966 | 1967 | ARGUMENTS: 1968 | Instance name to create 1969 | 1970 | OPTIONS: 1971 | -p Http server port for the Neo4j instance. 1972 | 1973 | Default: 7474 1974 | 1975 | -s Https server port (SSL port) for the Neo4j instance 1976 | 1977 | Default: +1 (7475 when port is 7474) 1978 | 1979 | -b Bolt port for the Neo4j instance 1980 | 1981 | Default: +1 1982 | Note: Only works on Neo4j version 3.0 or higher 1983 | 1984 | -a Allow external connections (http/https/bolt) 1985 | 1986 | -v The Neo4j version for the instance 1987 | 1988 | Default: ${DEFAULT_VERSION} 1989 | 1990 | -e The Neo4j edition for the instance (community/enterprise) 1991 | 1992 | Default: ${DEFAULT_EDITION} 1993 | Note: Enterprise version requires to have a valid license 1994 | 1995 | -d Force download of Neo4j version 1996 | 1997 | -f Force install even if instance already exists 1998 | 1999 | " 2000 | 2001 | HELP_SET_PORT=" 2002 | USAGE: 2003 | set-port [options] 2004 | 2005 | DESCRIPTION: 2006 | Change the port of a specific instance 2007 | 2008 | ARGUMENTS: 2009 | Instance name to change 2010 | New port number 2011 | 2012 | OPTIONS: 2013 | -s Use this option to change the SSL port 2014 | 2015 | -b Use this option to change the Bolt port 2016 | 2017 | Note: Bolt port only works on Neo4j version 3.0 or higher 2018 | 2019 | " 2020 | 2021 | HELP_GET_CONFIG=" 2022 | USAGE: 2023 | get-config [options] 2024 | 2025 | DESCRIPTION: 2026 | Read settings from configuration file 2027 | 2028 | ARGUMENTS: 2029 | [instance_names ...] Name of one or more instances to read 2030 | 2031 | Name of the Neo4j configuration parameter 2032 | 2033 | An '*' can be used as a wildcard to extract 2034 | multiple settings 2035 | 2036 | OPTIONS: 2037 | -a Read all instances 2038 | 2039 | If this option is used then don't use instance argument 2040 | 2041 | -o Define output format (list/ini/line/value) 2042 | 2043 | Line and value can't be used on multiple instances. 2044 | Value can't be used with a wildcard parameter 2045 | 2046 | -q Suppress warnings, if paramater doesn't exist 2047 | 2048 | " 2049 | 2050 | HELP_SET_CONFIG=" 2051 | USAGE: 2052 | set-config [options] 2053 | 2054 | DESCRIPTION: 2055 | Set a configuration value. If parameter doesn't exist in config file yet, 2056 | it will be appended. 2057 | 2058 | ARGUMENTS: 2059 | Name of instance to configure 2060 | Name of the Neo4j configuration parameter 2061 | Value of the Neo4j configuration parameter 2062 | 2063 | OPTIONS: 2064 | -d Disable (comment out) the parameter. 2065 | 2066 | If this option is used the last value is not required 2067 | 2068 | -q Write setting without confirmation 2069 | 2070 | " 2071 | 2072 | HELP_VERSIONS=" 2073 | USAGE: 2074 | versions 2075 | 2076 | DESCRIPTION: 2077 | Show the Neo4j versions available for installation 2078 | 2079 | OPTIONS: 2080 | -u Update the list of versions available 2081 | 2082 | " 2083 | 2084 | HELP_LIST=" 2085 | USAGE: 2086 | list 2087 | 2088 | DESCRIPTION: 2089 | List information about installed instances 2090 | 2091 | ALIASES: 2092 | ls, instances 2093 | 2094 | " 2095 | HELP_LS=${HELP_LIST} 2096 | HELP_INSTANCES=${HELP_LIST} 2097 | 2098 | HELP_START=" 2099 | USAGE: 2100 | start [options] [instance_names ...] 2101 | 2102 | DESCRIPTION: 2103 | Start one or more Neo4j instances 2104 | 2105 | ARGUMENTS: 2106 | [instance_names ...] Name of one or more instances to start (optional) 2107 | 2108 | If this argument is not specified then ineo tries 2109 | to start all created instances 2110 | 2111 | OPTIONS: 2112 | -q Start the instances without confirmation 2113 | 2114 | " 2115 | 2116 | HELP_STOP=" 2117 | USAGE: 2118 | stop [options] [instance_names ...] 2119 | 2120 | DESCRIPTION: 2121 | Stop one or more Neo4j instances 2122 | 2123 | ARGUMENTS: 2124 | [instance_names ...] Name of one or more instances to stop (optional) 2125 | 2126 | If this argument is not specified then ineo tries 2127 | to stop all created instances 2128 | 2129 | OPTIONS: 2130 | -q Stop the instances without confirmation 2131 | 2132 | " 2133 | 2134 | HELP_RESTART=" 2135 | USAGE: 2136 | restart [options] [instance_names ...] 2137 | 2138 | DESCRIPTION: 2139 | Restart one or more Neo4j instances 2140 | 2141 | ARGUMENTS: 2142 | [instance_names ...] Name of one or more instances to restart (optional) 2143 | 2144 | If this argument is not specified then ineo tries 2145 | to restart all created instances 2146 | 2147 | OPTIONS: 2148 | -q Restart the instances without confirmation 2149 | 2150 | " 2151 | 2152 | HELP_STATUS=" 2153 | USAGE: 2154 | status [instance_names ...] 2155 | 2156 | DESCRIPTION: 2157 | Show the status of one or more Neo4j instances 2158 | 2159 | ARGUMENTS: 2160 | [instance_names ...] Name of one or more instances to show status (optional) 2161 | 2162 | If this argument is not specified then ineo tries 2163 | to show the status of all created instances 2164 | 2165 | " 2166 | 2167 | HELP_SHELL=" 2168 | USAGE: 2169 | shell 2170 | 2171 | DESCRIPTION: 2172 | Start the shell for a Neo4j instance 2173 | 2174 | ARGUMENTS: 2175 | Instance name to work with the shell 2176 | 2177 | " 2178 | 2179 | HELP_CONSOLE=" 2180 | USAGE: 2181 | console 2182 | 2183 | DESCRIPTION: 2184 | Start a Neo4j instance in mode console 2185 | 2186 | ARGUMENTS: 2187 | Instance name to start 2188 | 2189 | " 2190 | 2191 | HELP_BACKUP=" 2192 | USAGE: 2193 | backup 2194 | 2195 | DESCRIPTION: 2196 | Create an offline backup of a specific database (requires Neo4j >=3.1) 2197 | 2198 | The backup will not include ineo nor neo4j config settings. The backup will 2199 | stop the instance in order to make the backup. If the instance was running 2200 | before the backup, it will be restarted afterwards. 2201 | 2202 | ARGUMENTS: 2203 | Instance name of the data to backup 2204 | 2205 | OPTIONS: 2206 | -p Destination path of the backup 2207 | 2208 | Default: ./ 2209 | 2210 | " 2211 | 2212 | HELP_RESTORE=" 2213 | USAGE: 2214 | restore [options] 2215 | 2216 | DESCRIPTION: 2217 | Restore a specific instance using a Neo4j dump file (requires Neo4j >=3.1) 2218 | 2219 | Any existing data will be overwritten by this command. 2220 | 2221 | ARGUMENTS: 2222 | Path to Neo4j dump file 2223 | Instance name of the data to restore 2224 | 2225 | OPTIONS: 2226 | -f Overwrite the data without confirmation 2227 | 2228 | " 2229 | 2230 | HELP_DELETE_DB=" 2231 | USAGE: 2232 | delete-db [options] 2233 | 2234 | DESCRIPTION: 2235 | Delete the data files for a specific instance. 2236 | 2237 | This command delete the data files, so using it could be slow on test-driven. 2238 | 2239 | If you need delete the data to restart it on test-driven, use cypher instead: 2240 | 'MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r;' 2241 | 2242 | ARGUMENTS: 2243 | Instance name of the data to delete 2244 | 2245 | OPTIONS: 2246 | -f Delete the data without confirmation 2247 | 2248 | " 2249 | 2250 | HELP_DESTROY=" 2251 | USAGE: 2252 | destroy [options] 2253 | 2254 | DESCRIPTION: 2255 | Destroy a specific instance 2256 | 2257 | ARGUMENTS: 2258 | Instance name to destroy 2259 | 2260 | OPTIONS: 2261 | -f Destroy the instance without confirmation 2262 | 2263 | " 2264 | 2265 | HELP_INSTALL=" 2266 | USAGE: 2267 | install [options] 2268 | 2269 | DESCRIPTION: 2270 | Install ineo 2271 | 2272 | Don't use this command if you already have ineo installed and working 2273 | correctly. If root user installs ineo on a systemd OS, a systemd 2274 | service will also be install to support autostart on instances. 2275 | 2276 | OPTIONS: 2277 | -d Directory name (absolute path) where ineo will be 2278 | installed 2279 | 2280 | Default: ~/.ineo or /var/lib/ineo if using -S 2281 | 2282 | -S Install ineo as a service (only on systemd OSes) 2283 | 2284 | " 2285 | 2286 | HELP_UPDATE=" 2287 | USAGE: 2288 | update 2289 | 2290 | DESCRIPTION: 2291 | Update the current installed ineo to the last version available 2292 | 2293 | " 2294 | 2295 | HELP_UNINSTALL=" 2296 | USAGE: 2297 | uninstall [options] 2298 | 2299 | DESCRIPTION: 2300 | Uninstall ineo 2301 | 2302 | OPTIONS: 2303 | -d Directory name where ineo is installed 2304 | 2305 | The default value is the value of the variable 2306 | \$INEO_HOME if it is configured 2307 | 2308 | -f Try to uninstall without confirmations 2309 | 2310 | " 2311 | 2312 | HELP_HELP=" 2313 | USAGE: 2314 | help [command_name] 2315 | 2316 | DESCRIPTION: 2317 | Show the help for ineo 2318 | 2319 | ARGUMENTS: 2320 | [command_name] Optional name to display the help for a specific command 2321 | 2322 | " 2323 | 2324 | # ============================================================================== 2325 | # SET COMMAND VARIABLE 2326 | # ============================================================================== 2327 | 2328 | COMMAND=$1 2329 | 2330 | # ============================================================================== 2331 | # MAIN 2332 | # ============================================================================== 2333 | 2334 | # make OS specific changed 2335 | if [[ "$( uname )" == "Darwin" ]]; then 2336 | # sed command is just incompatible with -i option 2337 | SED_CMD="sed -i ''" 2338 | OWNER_CMD="stat -f %Du" 2339 | fi 2340 | 2341 | set_instances 2342 | 2343 | # ============================================================================== 2344 | # LOCK FUNCTION 2345 | # ============================================================================== 2346 | 2347 | if [[ ! "${COMMAND}" == "UPDATE_SCRIPT_BATCH" ]]; then 2348 | if ! mkdir "${LOCK_DIR}"; then 2349 | echo "\n ${RED}FATAL -> Lock failed - exit${NF}\n\n" >&2 2350 | exit 1 2351 | fi 2352 | 2353 | if ! mkdir "${TEMP_DIR}"; then 2354 | echo "\n ${RED}FATAL -> Creating then temp dir ${PURPLE}${TEMP_DIR}${RED} failed - exit${NF}\n\n" >&2 2355 | exit 1 2356 | fi 2357 | 2358 | trap "rmdir \"${LOCK_DIR}\"; rm -rf \"${TEMP_DIR}\"; rm -rf \"${INSTANCE_TEMP_DIR}\"" EXIT 2359 | fi 2360 | 2361 | # ============================================================================== 2362 | # COMMAND SELECTOR 2363 | # ============================================================================== 2364 | case "${COMMAND}" in 2365 | install) 2366 | install $@ 2367 | ;; 2368 | uninstall) 2369 | uninstall $@ 2370 | ;; 2371 | create) 2372 | create $@ 2373 | ;; 2374 | destroy) 2375 | destroy $@ 2376 | ;; 2377 | console|start|stop|restart|status|info) 2378 | action $@ 2379 | ;; 2380 | backup) 2381 | backup $@ 2382 | ;; 2383 | restore) 2384 | restore $@ 2385 | ;; 2386 | get-config) 2387 | get-config $@ 2388 | ;; 2389 | set-config) 2390 | set-config $@ 2391 | ;; 2392 | autostart) 2393 | autostart $@ 2394 | ;; 2395 | delete-db) 2396 | delete-db $@ 2397 | ;; 2398 | set-port) 2399 | set-port $@ 2400 | ;; 2401 | shell) 2402 | shell $@ 2403 | ;; 2404 | update) 2405 | update $@ 2406 | ;; 2407 | versions) 2408 | versions $@ 2409 | ;; 2410 | version) 2411 | version $@ 2412 | ;; 2413 | list|ls|instances) 2414 | list $@ 2415 | ;; 2416 | help) 2417 | help $2 2418 | ;; 2419 | UPDATE_SCRIPT_BATCH) 2420 | update_script_batch $@ 2421 | ;; 2422 | *) 2423 | help 2424 | ;; 2425 | esac 2426 | 2427 | exit 0 2428 | 2429 | # vim: syntax=sh ts=2 sw=2 et sr softtabstop=2 2430 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # REQUIREMENTS 4 | # 5 | # MACOS: 6 | # - gtruncate: 7 | # # brew install coreutils 8 | 9 | 10 | NEO4J_HOSTNAME='http://dist.neo4j.org' 11 | DEFAULT_VERSION='all' 12 | DEFAULT_EDITION='all' 13 | DEFAULT_AUTO_DELAY=3 14 | LAST_VERSION='3.5.16' 15 | SED_CMD="sed -i " 16 | TEST_RETRY=15 17 | 18 | # define color variable to be used in echo, cat, ... 19 | if [[ -n "${TERM:-}" && ${TERM} != "dumb" ]] ; then 20 | readonly BLACK="$(tput setaf 0)" # Black 21 | readonly RED="$(tput setaf 1)" # Red 22 | readonly GREEN="$(tput setaf 2)" # Green 23 | readonly YELLOW="$(tput setaf 3)" # Yellow 24 | readonly BLUE="$(tput setaf 4)" # Blue 25 | readonly PURPLE="$(tput setaf 5)" # Purple 26 | readonly CYAN="$(tput setaf 6)" # Cyan 27 | readonly WHITE="$(tput setaf 7)" # White 28 | readonly UNDERLINE="$(tput smul)" # Underline 29 | readonly ITALIC="$(tput sitm)" # Italic 30 | readonly BOLD="$(tput bold)" # Bold 31 | readonly NF="$(tput sgr0)$(tput rmul)" # No Format 32 | else 33 | # NO TERM NO COLOR 34 | readonly BLACK="" # Black 35 | readonly RED="" # Red 36 | readonly GREEN="" # Green 37 | readonly YELLOW="" # Yellow 38 | readonly BLUE="" # Blue 39 | readonly PURPLE="" # Purple 40 | readonly CYAN="" # Cyan 41 | readonly WHITE="" # White 42 | readonly UNDERLINE="" # Underline 43 | readonly ITALIC="" # Italic 44 | readonly BOLD="" # Bold 45 | readonly NF="" # No Format 46 | fi 47 | 48 | # ============================================================================== 49 | # HELPER FUNCTIONS 50 | # ============================================================================== 51 | 52 | function get_running_message { 53 | local version=$1 54 | local instance=$2 55 | local pid=$3 56 | local major_version_number=${version%%.*} 57 | 58 | if [ $major_version_number -lt 3 ]; then 59 | printf \ 60 | " 61 | status '$instance' 62 | Neo4j Server is running at pid $pid 63 | " 64 | else 65 | printf \ 66 | " 67 | status '$instance' 68 | Neo4j is running at pid $pid 69 | " 70 | fi 71 | } 72 | 73 | function get_not_running_message { 74 | local version=$1 75 | local instance=$2 76 | local major_version_number=${version%%.*} 77 | 78 | if [ $major_version_number -lt 3 ]; then 79 | printf \ 80 | " 81 | status '$instance' 82 | Neo4j Server is not running 83 | " 84 | else 85 | printf \ 86 | " 87 | status '$instance' 88 | Neo4j is not running 89 | " 90 | fi 91 | } 92 | 93 | # compare two version strings 94 | # return values are: 95 | # -1 operator < 96 | # 0 operator = 97 | # 1 operator > 98 | function compare_version () { 99 | if [[ "$1" == "$2" ]]; then 100 | printf 0 101 | return 102 | else 103 | local IFS=. 104 | local i ver1=($1) ver2=($2) 105 | # fill empty fields in ver1 with zeros 106 | for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do 107 | ver1[i]=0 108 | done 109 | for ((i=0; i<${#ver1[@]}; i++)); do 110 | if [[ -z ${ver2[i]} ]]; then 111 | # fill empty fields in ver2 with zeros 112 | ver2[i]=0 113 | fi 114 | if ((10#${ver1[i]} > 10#${ver2[i]})); then 115 | printf 1 116 | return 117 | fi 118 | if ((10#${ver1[i]} < 10#${ver2[i]})); then 119 | printf -- -1 120 | return 121 | fi 122 | done 123 | fi 124 | printf 0 125 | } 126 | 127 | ### 128 | # Extract version of instance 129 | # 130 | # @param string instance 131 | ### 132 | function instance_version () { 133 | local instance=$1 134 | local version 135 | 136 | if [[ -f "${INEO_HOME}/instances/${instance}/.ineo" ]]; then 137 | version=$(grep neo4j_version "${INEO_HOME}/instances/${instance}/.ineo") 138 | printf ${version//[^=]*=/} 139 | fi 140 | } 141 | 142 | ### 143 | # Return database folder depending on instance 144 | # 145 | # The database folder is the one containing the graph.db folder 146 | # 147 | # @param string instance 148 | ### 149 | function database_folder_instance () { 150 | local instance=$1 151 | local version=$(instance_version "${instance}") 152 | 153 | printf $(database_folder_version "${version}") 154 | } 155 | 156 | ### 157 | # Return database folder depending on version 158 | # 159 | # The database folder is the one containing the graph.db folder 160 | # 161 | # @param string version 162 | ### 163 | function database_folder_version () { 164 | local version=$1 165 | local major_version_number=${version%%.*} 166 | 167 | if [ $major_version_number -lt 3 ]; then 168 | printf "/data" 169 | else 170 | printf "/data/databases" 171 | fi 172 | } 173 | 174 | # ============================================================================== 175 | # PROVISION 176 | # ============================================================================== 177 | 178 | # make OS specific changed 179 | if [[ "$( uname )" == "Darwin" ]]; then 180 | # sed command is just incompatible with -i option 181 | SED_CMD="sed -i ''" 182 | fi 183 | 184 | versions=() 185 | editions=() 186 | stoponerror="" 187 | verbose="" 188 | tests=() 189 | while getopts ":v:e:xV" optname 190 | do 191 | case "${optname}" in 192 | v) 193 | versions+=( ${OPTARG} ) 194 | ;; 195 | e) 196 | editions+=( ${OPTARG} ) 197 | ;; 198 | x) 199 | stoponerror="-x" 200 | ;; 201 | V) 202 | verbose+="-v" 203 | ;; 204 | *) 205 | >&2 echo "Invalid parameters" 206 | echo " 207 | USAGE: 208 | test.sh [options] [test name] 209 | 210 | DESCRIPTION: 211 | Start unit tests 212 | 213 | OPTIONS: 214 | -v Test a specific Neo4j version only or use \"all\" 215 | 216 | Default: ${DEFAULT_VERSION} 217 | 218 | -e Test a specific Neo4j edition (community/enterprise) or use \"all\" 219 | 220 | Default: ${DEFAULT_EDITION} 221 | 222 | -x Stop running tests after the first failure 223 | 224 | -V Generate output for every individual test case 225 | " 226 | exit 1 227 | ;; 228 | esac 229 | done 230 | 231 | test_name=${@:$OPTIND:1} 232 | 233 | # If there are not any argument specified then test just with default Neo4j 234 | # version 235 | if [ ${#versions[@]} -eq 0 ]; then 236 | versions=("$DEFAULT_VERSION") 237 | fi 238 | 239 | # If is all then test with all Neo4j versions 240 | if [ ${versions[0]} == 'all' ]; then 241 | # check current java version and select "all" version appropriately 242 | java_version=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2) 243 | if [[ $(compare_version "${java_version%*.*}" "1.8") == -1 ]]; then 244 | versions=(1.9.9 2.3.6 3.0.3 3.3.9 ${LAST_VERSION}) 245 | else 246 | # neo4j 1.9.x is not compatible with java >= 1.8 247 | versions=(2.3.6 3.0.3 3.3.9 ${LAST_VERSION}) 248 | fi 249 | fi 250 | 251 | # If there are not any argument specified then test just with default Neo4j 252 | # edition 253 | if [ ${#editions[@]} -eq 0 ]; then 254 | editions=("$DEFAULT_EDITION") 255 | fi 256 | 257 | # If is all then test with all Neo4j editions 258 | if [ ${editions[0]} == 'all' ]; then 259 | editions=(community enterprise) 260 | fi 261 | 262 | # On fake_neo4j_host is used to save cache tars 263 | mkdir -p fake_neo4j_host 264 | 265 | # If some Neo4J version has not been downloaded then try to download it, so can 266 | # test locally reducing remote http requests. 267 | for version in "${versions[@]}"; do 268 | for edition in "${editions[@]}"; do 269 | tar_name="neo4j-$edition-$version-unix.tar.gz" 270 | if [ ! -f fake_neo4j_host/${tar_name} ]; then 271 | printf "\n\nDownloading ${edition} ${version}\n\n" 272 | if ! curl -f -o /tmp/${$}.${tar_name} ${NEO4J_HOSTNAME}/${tar_name}; then 273 | printf "\n\nError downloading ${edition} ${version}\nThe test has been aborted!!!\n" 274 | exit 0 275 | fi 276 | 277 | mv /tmp/${$}.${tar_name} fake_neo4j_host/${tar_name} 278 | fi 279 | done 280 | done 281 | 282 | # fake_ineo_host is used to make a fake update on tests, this will be the last 283 | # ineo script but with a different version 284 | mkdir -p fake_ineo_host 285 | 286 | cp ./ineo ./fake_ineo_host/ineo 287 | sed -i.bak "/^\(VERSION=\).*/s//\1x.x.x/" ./fake_ineo_host/ineo 288 | 289 | set -e 290 | 291 | # Load assert.sh library (More info: http://github.com/lehmannro/assert.sh) 292 | . assert.sh ${stoponerror} ${verbose} 293 | 294 | # Set the variables to create instances 295 | # ------------------------------------------------------------------------------ 296 | 297 | export NEO4J_HOSTNAME="file://$(pwd)/fake_neo4j_host" 298 | export INEO_HOSTNAME="file://$(pwd)/fake_ineo_host" 299 | export INEO_HOME="$(pwd)/ineo_for_test" 300 | 301 | # Check for orphaned neo4j process still running from a previous test execution 302 | if [[ $(ps -ef -u $(whoami) | grep "[j]ava" | grep "${INEO_HOME}" | wc -l) -ne 0 ]]; then 303 | echo -E "${YELLOW}WARNING${NF}: Some old NEO4J process are still running, this might effect test run" 304 | sleep 1 305 | fi 306 | 307 | # ============================================================================== 308 | # PID FUNCTIONS 309 | # ============================================================================== 310 | 311 | function set_instance_pid { 312 | local instance_name=$1 313 | if [ -f ${INEO_HOME}/instances/${instance_name}/data/neo4j-service.pid ]; then 314 | assert_raises \ 315 | "test -f ${INEO_HOME}/instances/${instance_name}/data/neo4j-service.pid" 0 316 | pid=$(head -n 1 ${INEO_HOME}/instances/${instance_name}/data/neo4j-service.pid) 317 | else 318 | assert_raises \ 319 | "test -f ${INEO_HOME}/instances/${instance_name}/run/neo4j.pid" 0 320 | pid=$(head -n 1 ${INEO_HOME}/instances/${instance_name}/run/neo4j.pid) 321 | fi 322 | } 323 | 324 | function assert_run_pid { 325 | local pid=$1 326 | local instance_name=$2 327 | # we need to wait some seconds, because on fast computers the pid will exists 328 | # even though neo4j terminates due to a configuration error 329 | assert_try_raises "${TEST_RETRY}" "test $(ps -p $pid -o pid=)" 0 330 | 331 | # NEO4J >= 3.x are not generating DB on create 332 | if [[ -d "${INEO_HOME}/instances/${instance_name}/data/databases/" ]]; then 333 | # Check if DB is up and ready, this might need a couple of seconds otherwise NEO4J is not ready 334 | assert_try_raises "${TEST_RETRY}" "test -f ${INEO_HOME}/instances/${instance_name}/data/databases/graph.db/neostore" 0 335 | sleep 2 336 | fi 337 | } 338 | 339 | function assert_not_run_pid { 340 | local pid=$1 341 | # we need to wait some seconds, because on fast computers the pid will exists 342 | # even though neo4j terminates due to a configuration error 343 | assert_try_raises "${TEST_RETRY}" "test $(ps -p $pid -o pid=)" 1 344 | } 345 | 346 | # ============================================================================== 347 | # RESET FUNCTION 348 | # ============================================================================== 349 | 350 | function setup { 351 | if [[ "${verbose}" != "" ]]; then 352 | echo -e "\nStarting test $1" 353 | fi 354 | 355 | # if execution is too fast, lib folder is still locked 356 | sleep 1 357 | rm -fr ineo_for_test 358 | 359 | assert_raises "test -d ineo_for_test" 1 360 | } 361 | 362 | # ============================================================================== 363 | # TEST INSTALL 364 | # ============================================================================== 365 | 366 | InstallWithIncorrectParameters() { 367 | setup "${FUNCNAME[0]}" 368 | 369 | local params=( 370 | "-e $(pwd)/ineo_for_test" 'e' 371 | "-e$(pwd)/ineo_for_test" 'e' 372 | "x -d $(pwd)/ineo_for_test" 'x' 373 | "x -d$(pwd)/ineo_for_test" 'x' 374 | "-d $(pwd)/ineo_for_test y" 'y' 375 | "-d$(pwd)/ineo_for_test y" 'y' 376 | ) 377 | 378 | local i 379 | for ((i=0; i<${#params[*]}; i+=2)); do 380 | assert_raises "./ineo install ${params[i]}" 1 381 | assert "./ineo install ${params[i]}" \ 382 | " 383 | ${PURPLE}Error -> Invalid argument or option ${BOLD}${params[i+1]} 384 | 385 | ${NF}View help about the command ${UNDERLINE}install${NF} typing: 386 | ${CYAN}ineo help install${NF} 387 | " 388 | done 389 | 390 | assert_end InstallWithIncorrectParameters 391 | } 392 | tests+=('InstallWithIncorrectParameters') 393 | 394 | 395 | InstallWithARelativePath() { 396 | setup "${FUNCNAME[0]}" 397 | 398 | local params=( 399 | '-d ineo_for_test' 400 | '-dineo_for_test' 401 | ) 402 | 403 | for param in "${params[@]}"; do 404 | assert_raises "./ineo install $param" 1 405 | assert "./ineo install $param" \ 406 | " 407 | ${PURPLE}Error -> The directory ${BOLD}ineo_for_test${PURPLE} is not an absolute path 408 | 409 | ${NF}Use directories like: 410 | ${CYAN}/opt/ineo 411 | ~/.ineo${NF} 412 | " 413 | done 414 | 415 | assert_end InstallWithARelativePath 416 | } 417 | tests+=('InstallWithARelativePath') 418 | 419 | 420 | InstallOnAnExistingDirectory() { 421 | setup "${FUNCNAME[0]}" 422 | 423 | assert_raises "mkdir $(pwd)/ineo_for_test" 0 424 | 425 | local params=( 426 | "-d $(pwd)/ineo_for_test" 427 | "-d$(pwd)/ineo_for_test" 428 | ) 429 | 430 | local param 431 | for param in "${params[@]}"; do 432 | assert_raises "./ineo install $param" 1 433 | assert "./ineo install $param" \ 434 | " 435 | ${PURPLE}Error -> The directory ${BOLD}$(pwd)/ineo_for_test${PURPLE} already exists 436 | 437 | ${NF}If you want reinstall ineo then uninstall it with: 438 | ${CYAN}ineo uninstall -d \"$(pwd)/ineo_for_test\" 439 | 440 | ${NF}or ensure the directory doesn't contain anything important then remove it with: 441 | ${CYAN}rm -r \"$(pwd)/ineo_for_test\"${NF} 442 | " 443 | done 444 | 445 | assert_end InstallOnAnExistingDirectory 446 | } 447 | tests+=('InstallOnAnExistingDirectory') 448 | 449 | 450 | InstallCorrectly() { 451 | local params=( 452 | "-d $(pwd)/ineo_for_test" 453 | "-d$(pwd)/ineo_for_test" 454 | ) 455 | 456 | for param in "${params[@]}"; do 457 | setup "${FUNCNAME[0]}" 458 | 459 | assert "./ineo install $param" \ 460 | " 461 | ${GREEN}Ineo was successfully installed in ${BOLD}$(pwd)/ineo_for_test 462 | 463 | ${NF}To start using the ${UNDERLINE}ineo${NF} command reopen your terminal or enter: 464 | ${CYAN}source ~/.bashrc${NF} 465 | " 466 | 467 | assert_raises "test -d ineo_for_test" 0 468 | assert_raises "test -d ineo_for_test/bin" 0 469 | assert_raises "test -d ineo_for_test/instances" 0 470 | assert_raises "test -d ineo_for_test/cache" 0 471 | 472 | assert_raises \ 473 | "grep -Fq 'export INEO_HOME=$(pwd)/ineo_for_test; export PATH=\$INEO_HOME/bin:\$PATH' ~/.bashrc" 0 474 | done 475 | 476 | assert_end InstallCorrectly 477 | } 478 | tests+=('InstallCorrectly') 479 | 480 | # ============================================================================== 481 | # TEST UNINSTALL 482 | # ============================================================================== 483 | 484 | UninstallWithIncorrectParameters() { 485 | setup "${FUNCNAME[0]}" 486 | 487 | local params=( 488 | "-e $(pwd)/ineo_for_test" 'e' 489 | "-e$(pwd)/ineo_for_test" 'e' 490 | "x -d $(pwd)/ineo_for_test" 'x' 491 | "x -d$(pwd)/ineo_for_test" 'x' 492 | "-d $(pwd)/ineo_for_test y" 'y' 493 | "-d$(pwd)/ineo_for_test y" 'y' 494 | "-e $(pwd)/ineo_for_test -f" 'e' 495 | "-e$(pwd)/ineo_for_test -f" 'e' 496 | "x -d $(pwd)/ineo_for_test -f" 'x' 497 | "x -d$(pwd)/ineo_for_test -f" 'x' 498 | "-f -d $(pwd)/ineo_for_test y" 'y' 499 | "-f -d$(pwd)/ineo_for_test y" 'y' 500 | ) 501 | 502 | local i 503 | for ((i=0; i<${#params[*]}; i+=2)); do 504 | assert_raises "./ineo uninstall ${params[i]}" 1 505 | assert "./ineo uninstall ${params[i]}" \ 506 | " 507 | ${PURPLE}Error -> Invalid argument or option ${BOLD}${params[i+1]} 508 | 509 | ${NF}View help about the command ${UNDERLINE}uninstall${NF} typing: 510 | ${CYAN}ineo help uninstall${NF} 511 | " 512 | done 513 | 514 | assert_end UninstallWithIncorrectParameters 515 | } 516 | tests+=('UninstallWithIncorrectParameters') 517 | 518 | 519 | UninstallWithARelativeDirectory() { 520 | setup "${FUNCNAME[0]}" 521 | 522 | local params=( 523 | '-d ineo_for_test' 524 | '-dineo_for_test' 525 | ) 526 | 527 | local param 528 | for param in "${params[@]}"; do 529 | assert_raises "./ineo uninstall $param" 1 530 | assert "./ineo uninstall $param" \ 531 | " 532 | ${PURPLE}Error -> The directory ${BOLD}ineo_for_test${PURPLE} is not an absolute path 533 | 534 | ${NF}Use directories like: 535 | ${CYAN}/opt/ineo 536 | ~/.ineo${NF} 537 | " 538 | done 539 | 540 | assert_end UninstallWithARelativeDirectory 541 | } 542 | tests+=('UninstallWithARelativeDirectory') 543 | 544 | 545 | UninstallWithANonExistentDirectory() { 546 | setup "${FUNCNAME[0]}" 547 | 548 | local params=( 549 | "-d $(pwd)/ineo_for_test" 550 | "-d$(pwd)/ineo_for_test" 551 | ) 552 | 553 | # Ensure that directory doesn't exists 554 | assert_raises "test -d $(pwd)/ineo_for_test" 1 555 | 556 | local param 557 | for param in "${params[@]}"; do 558 | assert_raises "./ineo uninstall $param" 1 559 | assert "./ineo uninstall $param" \ 560 | " 561 | ${PURPLE}Error -> The directory ${BOLD}$(pwd)/ineo_for_test${PURPLE} doesn't exists 562 | 563 | ${NF}Are you sure that Ineo is installed? 564 | " 565 | done 566 | 567 | assert_end UninstallWithANonExistentDirectory 568 | } 569 | tests+=('UninstallWithANonExistentDirectory') 570 | 571 | 572 | UninstallWithADirectoryThatDoesntLookLikeAnIneoDirectory() { 573 | setup "${FUNCNAME[0]}" 574 | 575 | local params=( 576 | "-d $(pwd)/ineo_for_test" 577 | "-d$(pwd)/ineo_for_test" 578 | ) 579 | 580 | local param 581 | for param in "${params[@]}"; do 582 | 583 | # Make an installation 584 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 585 | 586 | # Remove a directory from Ineo 587 | assert_raises "rm -fr $(pwd)/ineo_for_test/neo4j" 0 588 | 589 | # Try uninstall saying no to first prompt 590 | assert "echo -ne 'n\n' | ./ineo uninstall $param" \ 591 | " 592 | ${YELLOW}Warning -> The directory ${RED}$(pwd)/ineo_for_test${YELLOW} doesn't look like an Ineo directory.${NF} 593 | " 594 | # Ensure that directory exists yet 595 | assert_raises "test -d $(pwd)/ineo_for_test" 0 596 | 597 | 598 | # Try uninstall saying yes to first prompt and no to second prompt 599 | assert "echo -ne 'y\nn\n' | ./ineo uninstall $param" \ 600 | " 601 | ${YELLOW}Warning -> The directory ${RED}$(pwd)/ineo_for_test${YELLOW} doesn't look like an Ineo directory.${NF} 602 | 603 | 604 | ${YELLOW}Warning -> This action will remove everything in ${RED}$(pwd)/ineo_for_test${NF} 605 | " 606 | # Ensure that directory exists yet 607 | assert_raises "test -d $(pwd)/ineo_for_test" 0 608 | 609 | 610 | # Uninstall saying yes to first prompt and yes to second prompt 611 | assert "echo -ne 'y\ny\n' | ./ineo uninstall $param" \ 612 | " 613 | ${YELLOW}Warning -> The directory ${RED}$(pwd)/ineo_for_test${YELLOW} doesn't look like an Ineo directory.${NF} 614 | 615 | 616 | ${YELLOW}Warning -> This action will remove everything in ${RED}$(pwd)/ineo_for_test${NF} 617 | 618 | 619 | ${GREEN}Ineo was successfully uninstalled.${NF} 620 | " 621 | # Ensure that directory doesn't exists 622 | assert_raises "test -d $(pwd)/ineo_for_test" 1 623 | done 624 | 625 | assert_end UninstallWithADirectoryThatDoesntLookLikeAnIneoDirectory 626 | } 627 | tests+=('UninstallWithADirectoryThatDoesntLookLikeAnIneoDirectory') 628 | 629 | 630 | UninstallWithADirectoryThatDoesntLookLikeAnIneoDirectoryUsingF() { 631 | setup "${FUNCNAME[0]}" 632 | 633 | local params=( 634 | "-d $(pwd)/ineo_for_test -f" 635 | "-d$(pwd)/ineo_for_test -f" 636 | "-f -d $(pwd)/ineo_for_test" 637 | "-f -d$(pwd)/ineo_for_test" 638 | ) 639 | 640 | local param 641 | for param in "${params[@]}"; do 642 | # Make an installation 643 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 644 | 645 | # Remove a directory from Ineo 646 | assert_raises "rm -fr $(pwd)/ineo_for_test/neo4j" 0 647 | 648 | # Ensure that directory exists yet 649 | assert_raises "test $(pwd)/ineo_for_test" 0 650 | 651 | # Uninstall using force 652 | assert "./ineo uninstall $param" \ 653 | " 654 | ${GREEN}Ineo was successfully uninstalled.${NF} 655 | " 656 | 657 | # Ensure that directory doesn't exists 658 | assert_raises "test -d $(pwd)/ineo_for_test" 1 659 | done 660 | 661 | assert_end UninstallWithADirectoryThatDoesntLookLikeAnIneoDirectoryUsingF 662 | } 663 | tests+=('UninstallWithADirectoryThatDoesntLookLikeAnIneoDirectoryUsingF') 664 | 665 | 666 | # ============================================================================== 667 | # TEST CREATE 668 | # ============================================================================== 669 | 670 | CreateAnInstanceWithoutTheRequiredParameter() { 671 | setup "${FUNCNAME[0]}" 672 | 673 | # Make an installation 674 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 675 | 676 | assert_raises "./ineo create" 1 677 | assert "./ineo create" \ 678 | " 679 | ${PURPLE}Error -> create requires an instance name 680 | 681 | ${NF}View help about the command ${UNDERLINE}create${NF} typing: 682 | ${CYAN}ineo help create${NF} 683 | " 684 | assert_end CreateAnInstanceWithoutTheRequiredParameter 685 | } 686 | tests+=('CreateAnInstanceWithoutTheRequiredParameter') 687 | 688 | CreateWithIncorrectParameters() { 689 | setup "${FUNCNAME[0]}" 690 | 691 | local params=( 692 | "-x" 'x' 693 | "-d -x" 'x' 694 | "-f -x" 'x' 695 | "-p7474 -x" 'x' 696 | "-s7878 -x" 'x' 697 | "-v$DEFAULT_VERSION -x" 'x' 698 | "-p7474 -s7878 -v$DEFAULT_VERSION -d -f -x" 'x' 699 | "facebook twitter" 'twitter' 700 | "-x facebook twitter" 'x' 701 | "-p7474 facebook twitter" 'twitter' 702 | "-p7474 -s7878 -v$DEFAULT_VERSION -d -f facebook twitter" 'twitter' 703 | ) 704 | 705 | local i 706 | for ((i=0; i<${#params[*]}; i+=2)); do 707 | assert_raises "./ineo create ${params[i]}" 1 708 | assert "./ineo create ${params[i]}" \ 709 | " 710 | ${PURPLE}Error -> Invalid argument or option ${BOLD}${params[i+1]} 711 | 712 | ${NF}View help about the command ${UNDERLINE}create${NF} typing: 713 | ${CYAN}ineo help create${NF} 714 | " 715 | done 716 | 717 | assert_end CreateWithIncorrectParameters 718 | } 719 | tests+=('CreateWithIncorrectParameters') 720 | 721 | 722 | CreateWithBoltPortOnIncorrectVersion() { 723 | local params=( 724 | "-b8486 -v2.3.6 facebook" 725 | "-p7474 -b8486 -v2.3.6 facebook" 726 | "-p7474 -s7475 -b8486 -v2.3.6 facebook" 727 | ) 728 | 729 | local i 730 | for ((i=0; i<${#params[*]}; i+=1)); do 731 | setup "${FUNCNAME[0]}" 732 | 733 | # Make an installation 734 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 735 | 736 | assert_raises "./ineo create ${params[i]}" 1 737 | assert "./ineo create ${params[i]}" \ 738 | " 739 | ${PURPLE}Error -> Bolt port only works on Neo4j 3.0 or higher 740 | 741 | ${NF}View help about the command ${UNDERLINE}create${NF} typing: 742 | ${CYAN}ineo help create${NF} 743 | " 744 | done 745 | 746 | assert_end CreateWithBoltPortOnIncorrectVersion 747 | } 748 | tests+=('CreateWithBoltPortOnIncorrectVersion') 749 | 750 | 751 | CreateWithIncorrectEdition() { 752 | local params=( 753 | "-e lite facebook" 754 | "-e free facebook" 755 | "-e paid facebook" 756 | "-e 1 facebook" 757 | ) 758 | 759 | local i 760 | for ((i=0; i<${#params[*]}; i+=1)); do 761 | setup "${FUNCNAME[0]} ${params[i]}" 762 | 763 | # Make an installation 764 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 765 | 766 | assert_raises "./ineo create ${params[i]}" 1 767 | assert "./ineo create ${params[i]}" \ 768 | " 769 | ${PURPLE}Error -> Edition (-e) must be: 'community' or 'enterprise' 770 | 771 | ${NF}View help about the command ${UNDERLINE}create${NF} typing: 772 | ${CYAN}ineo help create${NF} 773 | " 774 | done 775 | 776 | assert_end CreateWithIncorrectEdition 777 | } 778 | tests+=('CreateWithIncorrectEdition') 779 | 780 | 781 | CreateAnInstanceCorrectlyWithDifferentVariationsOfParameters() { 782 | # The parameters to check are 'port' 'ssl port' 'bolt port' 'version' 783 | local params=( 784 | 'twitter' '7474' '7475' '7476' "$LAST_VERSION" 'community' 785 | '-p8484 twitter' '8484' '8485' '8486' "$LAST_VERSION" 'community' 786 | '-s9495 twitter' '7474' '9495' '9496' "$LAST_VERSION" 'community' 787 | '-b9496 twitter' '7474' '7475' '9496' "$LAST_VERSION" 'community' 788 | '-p9494 -s8484 twitter' '9494' '8484' '9495' "$LAST_VERSION" 'community' 789 | '-s8484 -b9496 twitter' '7474' '8484' '9496' "$LAST_VERSION" 'community' 790 | '-p8484 -s9495 -b9499 twitter' '8484' '9495' '9499' "$LAST_VERSION" 'community' 791 | "-v$LAST_VERSION twitter" '7474' '7475' '7476' "$LAST_VERSION" 'community' 792 | "-v$LAST_VERSION -e enterprise twitter" '7474' '7475' '7476' "$LAST_VERSION" 'enterprise' 793 | "-v$LAST_VERSION -e community twitter" '7474' '7475' '7476' "$LAST_VERSION" 'community' 794 | "-p8484 -v$LAST_VERSION twitter" '8484' '8485' '8486' "$LAST_VERSION" 'community' 795 | "-s9495 -v$LAST_VERSION twitter" '7474' '9495' '9496' "$LAST_VERSION" 'community' 796 | "-b9496 -v$LAST_VERSION twitter" '7474' '7475' '9496' "$LAST_VERSION" 'community' 797 | "-p9494 -s8484 -v$LAST_VERSION twitter" '9494' '8484' '9495' "$LAST_VERSION" 'community' 798 | "-p8484 -b9496 -v$LAST_VERSION twitter" '8484' '8485' '9496' "$LAST_VERSION" 'community' 799 | "-s8484 -b9496 -v$LAST_VERSION twitter" '7474' '8484' '9496' "$LAST_VERSION" 'community' 800 | "-p8484 -s9494 -b9496 -v$LAST_VERSION twitter" '8484' '9494' '9496' "$LAST_VERSION" 'community' 801 | '-v2.3.6 twitter' '7474' '7475' '' "2.3.6" 'community' 802 | '-v2.3.6 -e enterprise twitter' '7474' '7475' '' "2.3.6" 'enterprise' 803 | '-v2.3.6 -e community twitter' '7474' '7475' '' "2.3.6" 'community' 804 | '-p8484 -v2.3.6 twitter' '8484' '8485' '' "2.3.6" 'community' 805 | '-s9495 -v2.3.6 twitter' '7474' '9495' '' "2.3.6" 'community' 806 | '-p9494 -s8484 -v2.3.6 twitter' '9494' '8484' '' "2.3.6" 'community' 807 | ) 808 | 809 | local i 810 | for ((i=0; i<${#params[*]}; i+=6)); do 811 | setup "${FUNCNAME[0]} ${params[i]} (${params[i+1]}-${params[i+2]}-${params[i+3]}-${params[i+4]}-${params[i+5]})" 812 | 813 | local port=${params[i+1]} 814 | local ssl_port=${params[i+2]} 815 | local bolt_port=${params[i+3]} 816 | local version=${params[i+4]} 817 | local edition=${params[i+5]} 818 | local major_version_number=${version%%.*} 819 | if [ $major_version_number -lt 3 ]; then 820 | local config="$(pwd)/ineo_for_test/instances/twitter/conf/neo4j-server.properties" 821 | else 822 | local config="$(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf" 823 | fi 824 | 825 | # Make an installation 826 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 827 | 828 | # Create the instance 829 | assert "./ineo create ${params[i]}" \ 830 | " 831 | ${GREEN}The instance ${BOLD}twitter${GREEN} was successfully created.${NF} 832 | 833 | " 834 | 835 | # Ensure the correct neo4j version was downloaded 836 | assert_raises \ 837 | "test -f $(pwd)/ineo_for_test/neo4j/neo4j-$edition-$version-unix.tar.gz" 0 838 | 839 | # Ensure neo4j exists 840 | assert_raises "test -f $(pwd)/ineo_for_test/instances/twitter/bin/neo4j" 0 841 | 842 | # Ensure the correct ports were set 843 | if [ $major_version_number -lt 3 ]; then 844 | assert_raises "grep -Fq org\.neo4j\.server\.webserver\.port=$port $config" 0 845 | 846 | assert_raises \ 847 | "grep -Fq org\.neo4j\.server\.webserver\.https\.port=$ssl_port $config" 0 848 | else 849 | assert_raises "grep -Fq dbms\.connector\.http\.listen\_address=:$port $config" 0 850 | 851 | assert_raises \ 852 | "grep -Fq dbms\.connector\.https\.listen\_address=:$ssl_port $config" 0 853 | 854 | assert_raises \ 855 | "grep -Fq dbms\.connector\.bolt\.listen\_address=:$bolt_port $config" 0 856 | fi 857 | done 858 | 859 | assert_end CreateAnInstanceCorrectlyWithDifferentVariationsOfParameters 860 | } 861 | tests+=('CreateAnInstanceCorrectlyWithDifferentVariationsOfParameters') 862 | 863 | 864 | CreateAnInstanceCorrectlyWithEveryVersion() { 865 | 866 | local version 867 | for version in "${versions[@]}"; do 868 | for edition in "${editions[@]}"; do 869 | setup "${FUNCNAME[0]} ${version}-${edition}" 870 | 871 | local major_version_number=${version%%.*} 872 | local minor_version_number=${version%.*} 873 | if [ $major_version_number -lt 3 ]; then 874 | local config="$(pwd)/ineo_for_test/instances/twitter/conf/neo4j-server.properties" 875 | else 876 | local config="$(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf" 877 | fi 878 | 879 | # Make an installation 880 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 881 | 882 | # Create the instance 883 | assert "./ineo create -e $edition -p8484 -s9495 -v $version twitter" \ 884 | " 885 | ${GREEN}The instance ${BOLD}twitter${GREEN} was successfully created.${NF} 886 | " 887 | # Ensure the correct neo4j version was downloaded 888 | assert_raises \ 889 | "test -f $(pwd)/ineo_for_test/neo4j/neo4j-$edition-$version-unix.tar.gz" 0 890 | 891 | # Ensure neo4j exists 892 | assert_raises "test -f $(pwd)/ineo_for_test/instances/twitter/bin/neo4j" 0 893 | 894 | # Ensure the correct ports were set 895 | if [ $major_version_number -lt 3 ]; then 896 | assert_raises "grep -Fq \"org.neo4j.server.webserver.port=$port\" $config" 0 897 | 898 | assert_raises \ 899 | "grep -Fq \"org.neo4j.server.webserver.https.port=$ssl_port\" $config" 0 900 | elif [[ "${minor_version_number}" < "3.1" ]]; then 901 | assert_raises "grep -Fq \"dbms.connector.http.address=localhost:$port\" $config" 0 902 | 903 | assert_raises \ 904 | "grep -Fq \"dbms.connector.https.address=localhost:$ssl_port\" $config" 0 905 | else 906 | assert_raises "grep -Fq \"dbms.connector.http.listen_address=:$port\" $config" 0 907 | 908 | assert_raises \ 909 | "grep -Fq \"dbms.connector.https.listen_address=:$ssl_port\" $config" 0 910 | fi 911 | done 912 | done 913 | 914 | assert_end CreateAnInstanceCorrectlyWithEveryVersion 915 | } 916 | tests+=('CreateAnInstanceCorrectlyWithEveryVersion') 917 | 918 | 919 | CreateAnInstanceWithABadTarAndTryAgainWithDOption() { 920 | setup "${FUNCNAME[0]}" 921 | 922 | # Truncate a bad version, so is possible a bad tar 923 | rm -fr bad_tar_for_test 924 | mkdir bad_tar_for_test 925 | 926 | cp fake_neo4j_host/neo4j-community-${LAST_VERSION}-unix.tar.gz bad_tar_for_test 927 | 928 | local platform=$(uname -s | tr '[:upper:]' '[:lower:]') 929 | 930 | local command_truncate 931 | if [ $platform = 'darwin' ]; then 932 | command_truncate=gtruncate 933 | elif [ $platform = 'linux' ]; then 934 | command_truncate=truncate 935 | fi 936 | 937 | $command_truncate -s20MB bad_tar_for_test/neo4j-community-${LAST_VERSION}-unix.tar.gz 938 | 939 | # Change the NEO4J_HOSTNAME for test to download the bad tar 940 | export NEO4J_HOSTNAME="file://$(pwd)/bad_tar_for_test" 941 | 942 | # Make an installation 943 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 944 | 945 | # Create the instance with a bad tar version 946 | assert "./ineo create -v$LAST_VERSION twitter" \ 947 | " 948 | ${PURPLE}Error -> The tar file ${BOLD}neo4j-community-$LAST_VERSION-unix.tar.gz${PURPLE} can't be extracted 949 | 950 | ${NF}Try run the command ${UNDERLINE}create${NF} with the -d option to download the tar file again 951 | 952 | " 953 | # Ensure the bad tar version of neo4j was downloaded 954 | assert_raises \ 955 | "test -f $(pwd)/ineo_for_test/neo4j/neo4j-community-$LAST_VERSION-unix.tar.gz" 0 956 | 957 | # Ensure the instance doesn't exists 958 | assert_raises "test -d $(pwd)/ineo_for_test/instances/twitter" 1 959 | 960 | # The bad tar now must be good 961 | rm -fr bad_tar_for_test 962 | mkdir bad_tar_for_test 963 | 964 | cp fake_neo4j_host/neo4j-community-${LAST_VERSION}-unix.tar.gz bad_tar_for_test 965 | 966 | # Create the instance with a good tar version 967 | assert "./ineo create -d -v$LAST_VERSION twitter" \ 968 | " 969 | ${GREEN}The instance ${BOLD}twitter${GREEN} was successfully created.${NF} 970 | 971 | " 972 | # Ensure the correct neo4j version was downloaded 973 | assert_raises \ 974 | "test -f $(pwd)/ineo_for_test/neo4j/neo4j-community-$LAST_VERSION-unix.tar.gz" 0 975 | 976 | # Ensure neo4j exists 977 | assert_raises "test -f $(pwd)/ineo_for_test/instances/twitter/bin/neo4j" 0 978 | 979 | # Restore the correct NEO4J_HOSTNAME for test 980 | export NEO4J_HOSTNAME="file://$(pwd)/fake_neo4j_host" 981 | 982 | assert_end CreateAnInstanceWithABadTarAndTryAgainWithDOption 983 | } 984 | tests+=('CreateAnInstanceWithABadTarAndTryAgainWithDOption') 985 | 986 | 987 | CreateAnInstanceOnAExistingDirectoryAndTryAgainWithFOption() { 988 | setup "${FUNCNAME[0]}" 989 | 990 | # Make an installation 991 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 992 | 993 | # Create the intance directory by hand 994 | assert_raises "mkdir $(pwd)/ineo_for_test/instances/twitter" 995 | 996 | # Try create the instance 997 | assert "./ineo create twitter" \ 998 | " 999 | ${PURPLE}Error -> A directory for the instance ${BOLD}twitter${PURPLE} already exists 1000 | 1001 | ${NF}Maybe the instance already was created or try run the command ${UNDERLINE}install${NF} with the -f option to force the installation 1002 | " 1003 | 1004 | # Ensure the instance directory is empty yet 1005 | assert_raises "test $(ls -A ineo_for_test/instances/twitter)" 1 1006 | 1007 | # Create the instance with -f option 1008 | assert "./ineo create -f twitter" \ 1009 | " 1010 | ${GREEN}The instance ${BOLD}twitter${GREEN} was successfully created.${NF} 1011 | " 1012 | 1013 | # Ensure neo4j exists 1014 | assert_raises "test -f $(pwd)/ineo_for_test/instances/twitter/bin/neo4j" 0 1015 | 1016 | assert_end CreateAnInstanceOnAExistingDirectoryAndTryAgainWithFOption 1017 | } 1018 | tests+=('CreateAnInstanceOnAExistingDirectoryAndTryAgainWithFOption') 1019 | 1020 | 1021 | # ============================================================================== 1022 | # TEST INSTANCE ACTIONS (START, STATUS, RESTART, STOP) 1023 | # ============================================================================== 1024 | 1025 | actions=('start' 'status' 'restart' 'stop') 1026 | 1027 | ActionsWithIncorrectParameters() { 1028 | setup "${FUNCNAME[0]}" 1029 | 1030 | local params=( 1031 | "-x" 'x' 1032 | 1033 | ) 1034 | 1035 | local i j 1036 | for ((i=0; i<${#actions[*]}; i+=1)); do 1037 | for ((j=0; j<${#params[*]}; j+=2)); do 1038 | assert_raises "./ineo ${actions[i]} ${params[j]}" 1 1039 | assert "./ineo ${actions[i]} ${params[j]}" \ 1040 | " 1041 | ${PURPLE}Error -> Invalid argument or option ${BOLD}${params[j+1]} 1042 | 1043 | ${NF}View help about the command ${UNDERLINE}${actions[i]}${NF} typing: 1044 | ${CYAN}ineo help ${actions[i]}${NF} 1045 | " 1046 | done 1047 | done 1048 | 1049 | assert_end ActionsWithIncorrectParameters 1050 | } 1051 | tests+=('ActionsWithIncorrectParameters') 1052 | 1053 | 1054 | ActionsOnANonExistentInstance() { 1055 | setup "${FUNCNAME[0]}" 1056 | 1057 | # Make an installation 1058 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1059 | 1060 | local action 1061 | for action in "${actions[@]}"; do 1062 | assert_raises "./ineo $action twitter" 1 1063 | assert "./ineo $action twitter" \ 1064 | " 1065 | ${PURPLE}Error -> There is not an instance with the name ${BOLD}twitter 1066 | 1067 | ${NF}You can create an instance with the command: 1068 | ${CYAN}ineo create twitter${NF} 1069 | 1070 | " 1071 | done 1072 | 1073 | assert_end ActionsOnANonExistentInstance 1074 | } 1075 | tests+=('ActionsOnANonExistentInstance') 1076 | 1077 | 1078 | ActionsOnANotProperlyInstalledInstance() { 1079 | setup "${FUNCNAME[0]}" 1080 | 1081 | # Make an installation 1082 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1083 | 1084 | mkdir ineo_for_test/instances/twitter 1085 | 1086 | local action 1087 | for action in "${actions[@]}"; do 1088 | assert_raises "./ineo $action twitter" 1 1089 | assert "./ineo $action twitter" \ 1090 | " 1091 | ${PURPLE}Error -> The instance ${BOLD}twitter${PURPLE} seems that is not properly installed 1092 | 1093 | ${NF}You can recreate the instance with the command: 1094 | ${CYAN}ineo create -f twitter${NF} 1095 | " 1096 | done 1097 | 1098 | assert_end ActionsOnANotProperlyInstalledInstance 1099 | } 1100 | tests+=('ActionsOnANotProperlyInstalledInstance') 1101 | 1102 | 1103 | ExecuteActionsCorrectly() { 1104 | local version 1105 | for version in "${versions[@]}"; do 1106 | for edition in "${editions[@]}"; do 1107 | setup "${FUNCNAME[0]} ${version}-${edition}" 1108 | 1109 | # Make an installation 1110 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1111 | 1112 | assert_raises "./ineo create -e $edition -v $version twitter" 0 1113 | 1114 | # start 1115 | assert_raises "./ineo start twitter" 0 1116 | set_instance_pid twitter 1117 | assert_run_pid "${pid}" twitter 1118 | 1119 | # status running 1120 | assert "./ineo status twitter" \ 1121 | "$(get_running_message $version twitter $pid)" 1122 | 1123 | # restart 1124 | assert_raises "./ineo restart twitter" 0 1125 | set_instance_pid twitter 1126 | assert_run_pid "${pid}" twitter 1127 | 1128 | # status running 1129 | assert "./ineo status twitter" \ 1130 | "$(get_running_message $version twitter $pid)" 1131 | 1132 | # stop 1133 | assert_raises "./ineo stop twitter" 0 1134 | assert_not_run_pid $pid 1135 | 1136 | # status not running 1137 | assert "./ineo status twitter" \ 1138 | "$(get_not_running_message $version twitter)" 1139 | done 1140 | done 1141 | assert_end ExecuteActionsCorrectly 1142 | } 1143 | tests+=('ExecuteActionsCorrectly') 1144 | 1145 | ExecuteActionsOnVariousInstancesCorrectly() { 1146 | local version 1147 | #local editions=(community) 1148 | for version in "${versions[@]}"; do 1149 | for edition in "${editions[@]}"; do 1150 | setup "${FUNCNAME[0]} ${version}-${edition}" 1151 | 1152 | # Make an installation 1153 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1154 | 1155 | # Test confirming 1156 | if [[ ${version%%.*} < 3 ]]; then 1157 | assert_raises "./ineo create -p7474 -e $edition -v $version twitter" 0 1158 | assert_raises "./ineo create -p8484 -e $edition -v $version facebook" 0 1159 | else 1160 | assert_raises "./ineo create -p7474 -b7575 -e $edition -v $version twitter" 0 1161 | assert_raises "./ineo create -p8484 -b8585 -e $edition -v $version facebook" 0 1162 | fi 1163 | 1164 | 1165 | # start 1166 | assert_raises "echo -ne 'y\n' | ./ineo start" 0 1167 | 1168 | set_instance_pid twitter 1169 | local pid_twitter=$pid 1170 | assert_run_pid "${pid_twitter}" twitter 1171 | 1172 | set_instance_pid facebook 1173 | local pid_facebook=$pid 1174 | assert_run_pid "${pid_facebook}" facebook 1175 | 1176 | # status running 1177 | assert "./ineo status" \ 1178 | "$(get_running_message $version facebook $pid_facebook) 1179 | $(get_running_message $version twitter $pid_twitter)" 1180 | 1181 | # restart 1182 | assert_raises "echo -ne 'y\n' | ./ineo restart" 0 1183 | 1184 | set_instance_pid twitter 1185 | pid_twitter=$pid 1186 | assert_run_pid "${pid_twitter}" twitter 1187 | 1188 | set_instance_pid facebook 1189 | pid_facebook=$pid 1190 | assert_run_pid "${pid_facebook}" facebook 1191 | 1192 | # status running 1193 | assert "./ineo status" \ 1194 | "$(get_running_message $version facebook $pid_facebook) 1195 | $(get_running_message $version twitter $pid_twitter)" 1196 | 1197 | # stop 1198 | assert_raises "echo -ne 'y\n' | ./ineo stop" 0 1199 | assert_not_run_pid $pid_twitter 1200 | assert_not_run_pid $pid_facebook 1201 | 1202 | # status not running 1203 | assert "./ineo status" \ 1204 | "$(get_not_running_message $version facebook $pid_facebook) 1205 | $(get_not_running_message $version twitter $pid_twitter)" 1206 | 1207 | # Test forcing with -q 1208 | 1209 | # start 1210 | assert_raises "./ineo start -q" 0 1211 | 1212 | set_instance_pid twitter 1213 | pid_twitter=$pid 1214 | assert_run_pid "${pid_twitter}" twitter 1215 | 1216 | set_instance_pid facebook 1217 | pid_facebook=$pid 1218 | assert_run_pid "${pid_facebook}" facebook 1219 | 1220 | # status running 1221 | assert "./ineo status" \ 1222 | "$(get_running_message $version facebook $pid_facebook) 1223 | $(get_running_message $version twitter $pid_twitter)" 1224 | 1225 | # restart 1226 | assert_raises "./ineo restart -q" 0 1227 | 1228 | set_instance_pid twitter 1229 | pid_twitter=$pid 1230 | assert_run_pid "${pid_twitter}" twitter 1231 | 1232 | set_instance_pid facebook 1233 | pid_facebook=$pid 1234 | assert_run_pid "${pid_facebook}" facebook 1235 | 1236 | # status running 1237 | assert "./ineo status" \ 1238 | "$(get_running_message $version facebook $pid_facebook) 1239 | $(get_running_message $version twitter $pid_twitter)" 1240 | 1241 | assert_raises "./ineo stop -q" 0 1242 | assert_not_run_pid $pid_twitter 1243 | assert_not_run_pid $pid_facebook 1244 | 1245 | # status not running 1246 | assert "./ineo status" \ 1247 | "$(get_not_running_message $version facebook $pid_facebook) 1248 | $(get_not_running_message $version twitter $pid_twitter)" 1249 | done 1250 | done 1251 | assert_end ExecuteActionsOnVariousInstancesCorrectly 1252 | } 1253 | tests+=('ExecuteActionsOnVariousInstancesCorrectly') 1254 | 1255 | 1256 | # ============================================================================== 1257 | # TEST AUTOSTART 1258 | # ============================================================================== 1259 | 1260 | AutostartWithoutAnyInstance() { 1261 | setup "${FUNCNAME[0]}" 1262 | 1263 | # Make an installation 1264 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1265 | 1266 | local action 1267 | for action in "${actions[@]}"; do 1268 | assert_raises "./ineo autostart" 1 1269 | assert "./ineo autostart" \ 1270 | " 1271 | ${PURPLE}Error -> No instances created yet 1272 | 1273 | ${NF}Try create an instance with the command: 1274 | ${CYAN}ineo create [your_instance_name]${NF}" 1275 | done 1276 | 1277 | assert_end AutostartWithoutAnyInstance 1278 | } 1279 | tests+=('AutostartWithoutAnyInstance') 1280 | 1281 | 1282 | AutostartSomeInstances() { 1283 | setup "${FUNCNAME[0]}" 1284 | 1285 | # Make an installation 1286 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1287 | 1288 | assert_raises "./ineo create -p 7474 twitter" 0 1289 | assert_raises "./ineo create -p 8484 facebook" 0 1290 | assert_raises "./ineo create -p 9494 apple" 0 1291 | 1292 | ${SED_CMD} -E "/^.*ineo_start_auto=.*$/ s/.*/ineo_start_auto=1/g" \ 1293 | ${INEO_HOME}/instances/apple/.ineo 1294 | ${SED_CMD} -E "/^.*ineo_start_auto=.*$/ s/.*/ineo_start_auto=1/g" \ 1295 | ${INEO_HOME}/instances/twitter/.ineo 1296 | 1297 | assert_raises "./ineo autostart" 0 1298 | 1299 | set_instance_pid twitter 1300 | local pid_twitter=$pid 1301 | assert_run_pid "${pid_twitter}" twitter 1302 | 1303 | # should not have started at all, so no PID file yet 1304 | assert_raises \ 1305 | "test -f $INEO_HOME/instances/facebook/run/neo4j.pid" 1 1306 | 1307 | set_instance_pid apple 1308 | local pid_apple=$pid 1309 | assert_run_pid "${pid_apple}" apple 1310 | 1311 | assert_raises "./ineo stop -q" 0 1312 | assert_not_run_pid $pid_apple 1313 | assert_not_run_pid $pid_twitter 1314 | 1315 | assert_end AutostartSomeInstances 1316 | } 1317 | tests+=('AutostartSomeInstances') 1318 | 1319 | 1320 | AutostartWithDelay() { 1321 | setup "${FUNCNAME[0]}" 1322 | 1323 | # Make an installation 1324 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1325 | 1326 | assert_raises "./ineo create -p 7474 twitter" 0 1327 | assert_raises "./ineo create -p 8484 facebook" 0 1328 | 1329 | ${SED_CMD} -E "/^.*ineo_start_auto=.*$/ s/.*/ineo_start_auto=1/g" \ 1330 | ${INEO_HOME}/instances/facebook/.ineo 1331 | ${SED_CMD} -E "/^.*ineo_start_auto=.*$/ s/.*/ineo_start_auto=1/g" \ 1332 | ${INEO_HOME}/instances/twitter/.ineo 1333 | 1334 | local time=$(date +"%s") 1335 | assert_raises "./ineo autostart" 0 1336 | time=$(($(date +"%s")-${time})) 1337 | 1338 | assert_raises "[ ${time} -ge ${DEFAULT_AUTO_DELAY} ]" 0 1339 | 1340 | set_instance_pid twitter 1341 | local pid_twitter=$pid 1342 | assert_run_pid "${pid_twitter}" twitter 1343 | 1344 | set_instance_pid facebook 1345 | local pid_facebook=$pid 1346 | assert_run_pid "${pid_facebook}" facebook 1347 | 1348 | assert_raises "./ineo stop -q" 0 1349 | 1350 | 1351 | ${SED_CMD} -E "/^.*ineo_start_delay=.*$/ s/.*/ineo_start_delay=0/g" \ 1352 | ${INEO_HOME}/instances/facebook/.ineo 1353 | ${SED_CMD} -E "/^.*ineo_start_delay=.*$/ s/.*/ineo_start_delay=0/g" \ 1354 | ${INEO_HOME}/instances/twitter/.ineo 1355 | 1356 | time=$(date +"%s") 1357 | assert_raises "./ineo autostart" 0 1358 | time=$(($(date +"%s")-${time})) 1359 | 1360 | assert_raises "[ ${time} -lt ${DEFAULT_AUTO_DELAY} ]" 0 1361 | 1362 | set_instance_pid twitter 1363 | pid_twitter=$pid 1364 | assert_run_pid "${pid_twitter}" twitter 1365 | 1366 | set_instance_pid facebook 1367 | pid_facebook=$pid 1368 | assert_run_pid "${pid_facebook}" facebook 1369 | 1370 | assert_raises "./ineo stop -q" 0 1371 | assert_not_run_pid $pid_facebook 1372 | assert_not_run_pid $pid_twitter 1373 | 1374 | assert_end AutostartWithDelay 1375 | } 1376 | tests+=('AutostartWithDelay') 1377 | 1378 | 1379 | AutostartWithPriority() { 1380 | setup "${FUNCNAME[0]}" 1381 | 1382 | # Make an installation 1383 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1384 | 1385 | # testing starting order is not really easy to do, because the autostart 1386 | # is not running in a separate thread/process and cannot be "watched". 1387 | # so the "trick" is to use the same port and see which neo4j is able 1388 | # to start. the first one will win. 1389 | assert_raises "./ineo create -p 7474 twitter" 0 1390 | assert_raises "./ineo create -p 8484 facebook" 0 1391 | 1392 | ${SED_CMD} -E "/^.*ineo_start_auto=.*$/ s/.*/ineo_start_auto=1/g" \ 1393 | ${INEO_HOME}/instances/facebook/.ineo 1394 | ${SED_CMD} -E "/^.*ineo_start_auto=.*$/ s/.*/ineo_start_auto=1/g" \ 1395 | ${INEO_HOME}/instances/twitter/.ineo 1396 | 1397 | ${SED_CMD} -E "/^.*ineo_start_priority=.*$/ s/.*/ineo_start_priority=10/g" \ 1398 | ${INEO_HOME}/instances/facebook/.ineo 1399 | ${SED_CMD} -E "/^.*ineo_start_priority=.*$/ s/.*/ineo_start_priority=100/g" \ 1400 | ${INEO_HOME}/instances/twitter/.ineo 1401 | 1402 | assert_contains "./ineo autostart" ".*start 'twitter'.*start 'facebook'.*" 1403 | 1404 | set_instance_pid twitter 1405 | pid_twitter=$pid 1406 | assert_run_pid "${pid_twitter}" twitter 1407 | 1408 | set_instance_pid facebook 1409 | pid_facebook=$pid 1410 | assert_run_pid "${pid_facebook}" facebook 1411 | 1412 | assert_raises "./ineo stop -q" 0 1413 | 1414 | ${SED_CMD} -E "/^.*ineo_start_priority=.*$/ s/.*/ineo_start_priority=1/g" \ 1415 | ${INEO_HOME}/instances/twitter/.ineo 1416 | ${SED_CMD} -E "/^.*ineo_start_priority=.*$/ s/.*/ineo_start_priority=100/g" \ 1417 | ${INEO_HOME}/instances/facebook/.ineo 1418 | 1419 | assert_contains "./ineo autostart" ".*start 'facebook'.*start 'twitter'.*" 1420 | assert_raises "./ineo stop -q" 0 1421 | 1422 | assert_end AutostartWithPriority 1423 | } 1424 | tests+=('AutostartWithPriority') 1425 | 1426 | 1427 | # ============================================================================== 1428 | # TEST INSTANCES 1429 | # ============================================================================== 1430 | 1431 | ListWithIncorrectParameters() { 1432 | setup "${FUNCNAME[0]}" 1433 | 1434 | params=( 1435 | 'wrong' 1436 | '-q' 1437 | ) 1438 | 1439 | local param 1440 | for param in "${params[@]}"; do 1441 | assert_raises "./ineo list $param" 1 1442 | assert "./ineo list $param" \ 1443 | " 1444 | ${PURPLE}Error -> Invalid argument or option ${BOLD}$param 1445 | 1446 | ${NF}View help about the command ${UNDERLINE}list${NF} typing: 1447 | ${CYAN}ineo help list${NF} 1448 | " 1449 | done 1450 | 1451 | assert_end ListWithIncorrectParameters 1452 | } 1453 | tests+=('ListWithIncorrectParameters') 1454 | 1455 | 1456 | ListCorrectly() { 1457 | for version in "${versions[@]}"; do 1458 | for edition in "${editions[@]}"; do 1459 | setup "${FUNCNAME[0]} ${version}-${edition}" 1460 | 1461 | # Make an installation 1462 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1463 | 1464 | assert_raises "./ineo create -p7474 -s8484 -e $edition -v $version twitter" 0 1465 | assert_raises "./ineo create -p7575 -s8585 -e $edition -v $version facebook" 0 1466 | 1467 | assert_raises "./ineo list" 0 1468 | if [ ${version%%.*} -lt 3 ]; then 1469 | assert "./ineo list" \ 1470 | " 1471 | > instance 'facebook' 1472 | VERSION: $version 1473 | EDITION: $edition 1474 | PATH: $INEO_HOME/instances/facebook 1475 | PORT: 7575 1476 | HTTPS: 8585 1477 | 1478 | > instance 'twitter' 1479 | VERSION: $version 1480 | EDITION: $edition 1481 | PATH: $INEO_HOME/instances/twitter 1482 | PORT: 7474 1483 | HTTPS: 8484 1484 | " 1485 | else 1486 | assert "./ineo list" \ 1487 | " 1488 | > instance 'facebook' 1489 | VERSION: $version 1490 | EDITION: $edition 1491 | PATH: $INEO_HOME/instances/facebook 1492 | PORT: 7575 1493 | HTTPS: 8585 1494 | BOLT: 8586 1495 | 1496 | > instance 'twitter' 1497 | VERSION: $version 1498 | EDITION: $edition 1499 | PATH: $INEO_HOME/instances/twitter 1500 | PORT: 7474 1501 | HTTPS: 8484 1502 | BOLT: 8485 1503 | " 1504 | fi 1505 | done 1506 | done 1507 | 1508 | assert_end ListCorrectly 1509 | } 1510 | tests+=('ListCorrectly') 1511 | 1512 | 1513 | ListAliases() { 1514 | setup "${FUNCNAME[0]}" 1515 | 1516 | # Make an installation 1517 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1518 | 1519 | assert_raises "./ineo create twitter" 0 1520 | 1521 | if [ ${version%%.*} -lt 3 ]; then 1522 | assert "./ineo ls" \ 1523 | " 1524 | > instance 'twitter' 1525 | VERSION: ${versions[@]:(-1)} 1526 | EDITION: ${editions[0]} 1527 | PATH: $INEO_HOME/instances/twitter 1528 | PORT: 7474 1529 | HTTPS: 7475 1530 | " 1531 | else 1532 | assert "./ineo ls" \ 1533 | " 1534 | > instance 'twitter' 1535 | VERSION: ${versions[@]:(-1)} 1536 | EDITION: ${editions[0]} 1537 | PATH: $INEO_HOME/instances/twitter 1538 | PORT: 7474 1539 | HTTPS: 7475 1540 | BOLT: 7476 1541 | " 1542 | fi 1543 | 1544 | if [ ${version%%.*} -lt 3 ]; then 1545 | assert "./ineo instances" \ 1546 | " 1547 | > instance 'twitter' 1548 | VERSION: ${versions[@]:(-1)} 1549 | EDITION: ${editions[0]} 1550 | PATH: $INEO_HOME/instances/twitter 1551 | PORT: 7474 1552 | HTTPS: 7475 1553 | " 1554 | else 1555 | assert "./ineo instances" \ 1556 | " 1557 | > instance 'twitter' 1558 | VERSION: ${versions[@]:(-1)} 1559 | EDITION: ${editions[0]} 1560 | PATH: $INEO_HOME/instances/twitter 1561 | PORT: 7474 1562 | HTTPS: 7475 1563 | BOLT: 7476 1564 | " 1565 | fi 1566 | 1567 | assert_end ListAliases 1568 | } 1569 | tests+=('ListAliases') 1570 | 1571 | 1572 | # ============================================================================== 1573 | # TEST VERSIONS 1574 | # ============================================================================== 1575 | 1576 | VersionsWithIncorrectParameters() { 1577 | setup "${FUNCNAME[0]}" 1578 | 1579 | local params=( 1580 | 'wrong' 'wrong' 1581 | '-q' 'q' 1582 | ) 1583 | 1584 | local param 1585 | for ((i=0; i<${#params[*]}; i+=2)); do 1586 | assert_raises "./ineo versions ${params[i]}" 1 1587 | assert "./ineo versions ${params[i]}" \ 1588 | " 1589 | ${PURPLE}Error -> Invalid argument or option ${BOLD}${params[i+1]} 1590 | 1591 | ${NF}View help about the command ${UNDERLINE}versions${NF} typing: 1592 | ${CYAN}ineo help versions${NF} 1593 | " 1594 | done 1595 | 1596 | assert_end VersionsWithIncorrectParameters 1597 | } 1598 | tests+=('VersionsWithIncorrectParameters') 1599 | 1600 | 1601 | VersionsCorrectly() { 1602 | setup "${FUNCNAME[0]}" 1603 | 1604 | # Make an installation 1605 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1606 | 1607 | assert_raises "./ineo versions" 0 1608 | assert_raises "./ineo versions -u" 0 1609 | 1610 | assert_end VersionsCorrectly 1611 | } 1612 | tests+=('VersionsCorrectly') 1613 | 1614 | 1615 | # ============================================================================== 1616 | # TEST SHELL 1617 | # ============================================================================== 1618 | 1619 | ShellWithIncorrectParameters() { 1620 | setup "${FUNCNAME[0]}" 1621 | 1622 | local params=( 1623 | "-x" 'x' 1624 | "-x -y" 'x' 1625 | "-x twitter" 'x' 1626 | "facebook twitter" 'twitter' 1627 | "-x facebook twitter" 'x' 1628 | ) 1629 | 1630 | local i 1631 | for ((i=0; i<${#params[*]}; i+=2)); do 1632 | assert_raises "./ineo shell ${params[i]}" 1 1633 | assert "./ineo shell ${params[i]}" \ 1634 | " 1635 | ${PURPLE}Error -> Invalid argument or option ${BOLD}${params[i+1]} 1636 | 1637 | ${NF}View help about the command ${UNDERLINE}shell${NF} typing: 1638 | ${CYAN}ineo help shell${NF} 1639 | " 1640 | done 1641 | 1642 | assert_end ShellWithIncorrectParameters 1643 | } 1644 | tests+=('ShellWithIncorrectParameters') 1645 | 1646 | 1647 | StartAShellWithoutTheRequiredParameter() { 1648 | setup "${FUNCNAME[0]}" 1649 | 1650 | # Make an installation 1651 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1652 | 1653 | assert_raises "./ineo shell" 1 1654 | assert "./ineo shell" \ 1655 | " 1656 | ${PURPLE}Error -> shell requires an instance name 1657 | 1658 | ${NF}View help about the command ${UNDERLINE}shell${NF} typing: 1659 | ${CYAN}ineo help shell${NF} 1660 | " 1661 | 1662 | assert_end StartAShellWithoutTheRequiredParameter 1663 | } 1664 | tests+=('StartAShellWithoutTheRequiredParameter') 1665 | 1666 | 1667 | StartAShellWithANonExistentInstance() { 1668 | setup "${FUNCNAME[0]}" 1669 | 1670 | # Make an installation 1671 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1672 | 1673 | assert_raises "./ineo shell twitter" 1 1674 | assert "./ineo shell twitter" \ 1675 | " 1676 | ${PURPLE}Error -> There is not an instance with the name ${BOLD}twitter 1677 | 1678 | ${NF}List installed instances typing: 1679 | ${CYAN}ineo list${NF} 1680 | " 1681 | 1682 | assert_end StartAShellWithANonExistentInstance 1683 | } 1684 | tests+=('StartAShellWithANonExistentInstance') 1685 | 1686 | 1687 | # ============================================================================== 1688 | # TEST CONSOLE 1689 | # ============================================================================== 1690 | 1691 | ConsoleWithIncorrectParameters() { 1692 | setup "${FUNCNAME[0]}" 1693 | 1694 | local params=( 1695 | "-x" 'x' 1696 | "-x -y" 'x' 1697 | "-x twitter" 'x' 1698 | "facebook twitter" 'twitter' 1699 | "-x facebook twitter" 'x' 1700 | ) 1701 | 1702 | local i 1703 | for ((i=0; i<${#params[*]}; i+=2)); do 1704 | assert_raises "./ineo console ${params[i]}" 1 1705 | assert "./ineo console ${params[i]}" \ 1706 | " 1707 | ${PURPLE}Error -> Invalid argument or option ${BOLD}${params[i+1]} 1708 | 1709 | ${NF}View help about the command ${UNDERLINE}console${NF} typing: 1710 | ${CYAN}ineo help console${NF} 1711 | " 1712 | done 1713 | 1714 | assert_end ConsoleWithIncorrectParameters 1715 | } 1716 | tests+=('ConsoleWithIncorrectParameters') 1717 | 1718 | 1719 | StartModeConsoleWithoutTheRequiredParameter() { 1720 | setup "${FUNCNAME[0]}" 1721 | 1722 | # Make an installation 1723 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1724 | 1725 | assert_raises "./ineo console" 1 1726 | assert "./ineo console" \ 1727 | " 1728 | ${PURPLE}Error -> console requires an instance name 1729 | 1730 | ${NF}View help about the command ${UNDERLINE}console${NF} typing: 1731 | ${CYAN}ineo help console${NF} 1732 | " 1733 | 1734 | assert_end StartModeConsoleWithoutTheRequiredParameter 1735 | } 1736 | tests+=('StartModeConsoleWithoutTheRequiredParameter') 1737 | 1738 | 1739 | StartModeConsoleWithANonExistentInstance() { 1740 | setup "${FUNCNAME[0]}" 1741 | 1742 | # Make an installation 1743 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1744 | 1745 | assert_raises "./ineo console twitter" 1 1746 | assert "./ineo console twitter" \ 1747 | " 1748 | ${PURPLE}Error -> There is not an instance with the name ${BOLD}twitter 1749 | 1750 | ${NF}You can create an instance with the command: 1751 | ${CYAN}ineo create twitter${NF} 1752 | " 1753 | 1754 | assert_end StartModeConsoleWithANonExistentInstance 1755 | } 1756 | tests+=('StartModeConsoleWithANonExistentInstance') 1757 | 1758 | 1759 | # ============================================================================== 1760 | # TEST DESTROY 1761 | # ============================================================================== 1762 | 1763 | DestroyWithIncorrectParameters() { 1764 | setup "${FUNCNAME[0]}" 1765 | 1766 | local params=( 1767 | "-x" 'x' 1768 | "-x -y" 'x' 1769 | "-x twitter" 'x' 1770 | "facebook twitter" 'twitter' 1771 | "-x facebook twitter" 'x' 1772 | ) 1773 | 1774 | local i 1775 | for ((i=0; i<${#params[*]}; i+=2)); do 1776 | assert_raises "./ineo destroy ${params[i]}" 1 1777 | assert "./ineo destroy ${params[i]}" \ 1778 | " 1779 | ${PURPLE}Error -> Invalid argument or option ${BOLD}${params[i+1]} 1780 | 1781 | ${NF}View help about the command ${UNDERLINE}destroy${NF} typing: 1782 | ${CYAN}ineo help destroy${NF} 1783 | " 1784 | done 1785 | 1786 | assert_end DestroyWithIncorrectParameters 1787 | } 1788 | tests+=('DestroyWithIncorrectParameters') 1789 | 1790 | 1791 | DestroyAnInstanceWithoutTheRequiredParameter() { 1792 | setup "${FUNCNAME[0]}" 1793 | 1794 | # Make an installation 1795 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1796 | 1797 | assert_raises "./ineo destroy" 1 1798 | assert "./ineo destroy" \ 1799 | " 1800 | ${PURPLE}Error -> destroy requires an instance name 1801 | 1802 | ${NF}View help about the command ${UNDERLINE}destroy${NF} typing: 1803 | ${CYAN}ineo help destroy${NF} 1804 | " 1805 | 1806 | assert_end DestroyAnInstanceWithoutTheRequiredParameter 1807 | } 1808 | tests+=('DestroyAnInstanceWithoutTheRequiredParameter') 1809 | 1810 | 1811 | DestroyANonExistentInstance() { 1812 | setup "${FUNCNAME[0]}" 1813 | 1814 | # Make an installation 1815 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1816 | 1817 | assert_raises "./ineo destroy twitter" 1 1818 | assert "./ineo destroy twitter" \ 1819 | " 1820 | ${PURPLE}Error -> There is not an instance with the name ${BOLD}twitter 1821 | 1822 | ${NF}List installed instances typing: 1823 | ${CYAN}ineo list${NF} 1824 | " 1825 | 1826 | assert_end DestroyANonExistentInstance 1827 | } 1828 | tests+=('DestroyANonExistentInstance') 1829 | 1830 | 1831 | DestroyCorrectly() { 1832 | local version 1833 | for version in "${versions[@]}"; do 1834 | for edition in "${editions[@]}"; do 1835 | setup "${FUNCNAME[0]} ${version}-${edition}" 1836 | 1837 | # Make an installation 1838 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1839 | 1840 | # Test confirming without an instance running 1841 | 1842 | assert_raises "./ineo create -e $edition -v $version twitter" 0 1843 | sleep 1 1844 | assert_raises "echo -ne 'y\n' | ./ineo destroy twitter" 0 1845 | 1846 | assert_raises "./ineo create -e $edition -v $version twitter" 0 1847 | sleep 1 1848 | assert "echo -ne 'y\n' | ./ineo destroy twitter" \ 1849 | " 1850 | ${YELLOW}Warning -> Destroying the instance ${RED}twitter${YELLOW} will remove all data for this instance${NF} 1851 | 1852 | 1853 | 1854 | ${GREEN}The instance ${BOLD}twitter${GREEN} was successfully destroyed.${NF} 1855 | " 1856 | 1857 | # Test confirming with an instance running 1858 | 1859 | assert_raises "./ineo create -e $edition -v $version twitter" 0 1860 | assert_raises "./ineo start twitter" 0 1861 | 1862 | set_instance_pid twitter 1863 | assert_run_pid "${pid}" twitter 1864 | 1865 | sleep 1 1866 | assert_raises "echo -ne 'y\ny\n' | ./ineo destroy twitter" 0 1867 | 1868 | assert_not_run_pid $pid 1869 | 1870 | # Test forcing without an instance running 1871 | 1872 | assert_raises "./ineo create -e $edition -v $version twitter" 0 1873 | 1874 | sleep 1 1875 | assert_raises "./ineo destroy -f twitter" 0 1876 | 1877 | assert_raises "./ineo create -e $edition -v $version twitter" 0 1878 | sleep 1 1879 | assert "./ineo destroy -f twitter" \ 1880 | " 1881 | ${GREEN}The instance ${BOLD}twitter${GREEN} was successfully destroyed.${NF} 1882 | " 1883 | 1884 | # Test forcing with an instance running 1885 | 1886 | assert_raises "./ineo create -e $edition -v $version twitter" 0 1887 | assert_raises "./ineo start twitter" 0 1888 | 1889 | set_instance_pid twitter 1890 | assert_run_pid "${pid}" twitter 1891 | 1892 | sleep 1 1893 | assert_raises "./ineo destroy -f twitter" 0 1894 | 1895 | assert_not_run_pid $pid 1896 | done 1897 | done 1898 | assert_end DestroyCorrectly 1899 | } 1900 | tests+=('DestroyCorrectly') 1901 | 1902 | 1903 | # ============================================================================== 1904 | # TEST SET-PORT 1905 | # ============================================================================== 1906 | 1907 | SetPortWithIncorrectParameters() { 1908 | setup "${FUNCNAME[0]}" 1909 | 1910 | local params=( 1911 | "-x" 'x' 1912 | "-x -y" 'x' 1913 | "-x twitter" 'x' 1914 | "facebook 9898 twitter" 'twitter' 1915 | "-x facebook 9898" 'x' 1916 | ) 1917 | 1918 | local i 1919 | for ((i=0; i<${#params[*]}; i+=2)); do 1920 | assert_raises "./ineo set-port ${params[i]}" 1 1921 | assert "./ineo set-port ${params[i]}" \ 1922 | " 1923 | ${PURPLE}Error -> Invalid argument or option ${BOLD}${params[i+1]} 1924 | 1925 | ${NF}View help about the command ${UNDERLINE}set-port${NF} typing: 1926 | ${CYAN}ineo help set-port${NF} 1927 | " 1928 | done 1929 | 1930 | assert_end SetPortWithIncorrectParameters 1931 | } 1932 | tests+=('SetPortWithIncorrectParameters') 1933 | 1934 | 1935 | SetPortWithoutTheRequireParameters() { 1936 | setup "${FUNCNAME[0]}" 1937 | 1938 | # Make an installation 1939 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1940 | 1941 | assert_raises "./ineo create twitter" 0 1942 | 1943 | assert_raises "./ineo set-port" 1 1944 | assert "./ineo set-port" \ 1945 | " 1946 | ${PURPLE}Error -> ${BOLD}set-port${PURPLE} requires an instance name and a port number 1947 | 1948 | ${NF}View help about the command ${UNDERLINE}set-port${NF} typing: 1949 | ${CYAN}ineo help set-port${NF} 1950 | " 1951 | 1952 | assert_raises "./ineo set-port twitter" 1 1953 | assert "./ineo set-port twitter" \ 1954 | " 1955 | ${PURPLE}Error -> ${BOLD}set-port${PURPLE} requires an instance name and a port number 1956 | 1957 | ${NF}View help about the command ${UNDERLINE}set-port${NF} typing: 1958 | ${CYAN}ineo help set-port${NF} 1959 | " 1960 | 1961 | assert_end SetPortWithoutTheRequireParameters 1962 | } 1963 | tests+=('SetPortWithoutTheRequireParameters') 1964 | 1965 | 1966 | SetPortOnANonExistentInstance() { 1967 | setup "${FUNCNAME[0]}" 1968 | 1969 | # Make an installation 1970 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1971 | 1972 | assert_raises "./ineo set-port twitter 7575" 1 1973 | assert "./ineo set-port twitter 7474" \ 1974 | " 1975 | ${PURPLE}Error -> There is not an instance with the name ${BOLD}twitter${PURPLE} or is not properly installed 1976 | 1977 | ${NF}List installed instances typing: 1978 | ${CYAN}ineo list${NF} 1979 | " 1980 | 1981 | assert_end SetPortOnANonExistentInstance 1982 | } 1983 | tests+=('SetPortOnANonExistentInstance') 1984 | 1985 | 1986 | SetPortWithAnIncorrectNumberPort() { 1987 | setup "${FUNCNAME[0]}" 1988 | 1989 | # Make an installation 1990 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 1991 | 1992 | assert_raises "./ineo create twitter" 0 1993 | 1994 | assert_raises "./ineo set-port twitter aaa" 1 1995 | assert "./ineo set-port twitter aaa" \ 1996 | " 1997 | ${PURPLE}Error -> The port must be a positive integer number 1998 | 1999 | ${NF}View help about the command ${UNDERLINE}set-port${NF} typing: 2000 | ${CYAN}ineo help set-port${NF} 2001 | " 2002 | 2003 | assert_end SetPortWithAnIncorrectNumberPort 2004 | } 2005 | tests+=('SetPortWithAnIncorrectNumberPort') 2006 | 2007 | 2008 | SetPortWithAnIncorrectOutOfRangePort() { 2009 | setup "${FUNCNAME[0]}" 2010 | 2011 | # Make an installation 2012 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 2013 | 2014 | assert_raises "./ineo create twitter" 0 2015 | 2016 | assert_raises "./ineo set-port twitter 65536" 1 2017 | assert "./ineo set-port twitter 65536" \ 2018 | " 2019 | ${PURPLE}Error -> The port must be a number between ${BOLD}1${PURPLE} and ${BOLD}65535 2020 | 2021 | ${NF}View help about the command ${UNDERLINE}set-port${NF} typing: 2022 | ${CYAN}ineo help set-port${NF} 2023 | " 2024 | 2025 | assert_raises "./ineo set-port twitter 0" 1 2026 | assert "./ineo set-port twitter 0" \ 2027 | " 2028 | ${PURPLE}Error -> The port must be a number between ${BOLD}1${PURPLE} and ${BOLD}65535 2029 | 2030 | ${NF}View help about the command ${UNDERLINE}set-port${NF} typing: 2031 | ${CYAN}ineo help set-port${NF} 2032 | " 2033 | 2034 | assert_end SetPortWithAnIncorrectOutOfRangePort 2035 | } 2036 | tests+=('SetPortWithAnIncorrectOutOfRangePort') 2037 | 2038 | 2039 | SetBoltPortWithIncorrectVersion() { 2040 | setup "${FUNCNAME[0]}" 2041 | 2042 | # Make an installation 2043 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 2044 | 2045 | # Create a instance with version 2.3.6 but Bolt port only works on version 2046 | # 3.0 or higher 2047 | assert_raises "./ineo create -v 2.3.6 twitter" 0 2048 | 2049 | assert_raises "./ineo set-port -b twitter 7575" 1 2050 | assert "./ineo set-port -b twitter 7474" \ 2051 | " 2052 | ${PURPLE}Error -> Bolt port only works with Neo4j 3.0 or higher 2053 | 2054 | ${NF}View help about the command ${UNDERLINE}set-port${NF} typing: 2055 | ${CYAN}ineo help set-port${NF} 2056 | " 2057 | 2058 | assert_end SetBoltPortWithIncorrectVersion 2059 | } 2060 | tests+=('SetBoltPortWithIncorrectVersion') 2061 | 2062 | 2063 | SetBoltAndSslPortAtTheSameTime() { 2064 | setup "${FUNCNAME[0]}" 2065 | 2066 | # Make an installation 2067 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 2068 | 2069 | assert_raises "./ineo create -v 3.0.3 twitter" 0 2070 | 2071 | assert_raises "./ineo set-port -s -b twitter 7575" 1 2072 | assert "./ineo set-port -s -b twitter 7474" \ 2073 | " 2074 | ${PURPLE}Error -> ${BOLD}set-port${PURPLE} can't set bolt and ssl port at the same time 2075 | 2076 | ${NF}View help about the command ${UNDERLINE}set-port${NF} typing: 2077 | ${CYAN}ineo help set-port${NF} 2078 | 2079 | " 2080 | 2081 | assert_end SetBoltAndSslPortAtTheSameTime 2082 | } 2083 | tests+=('SetBoltAndSslPortAtTheSameTime') 2084 | 2085 | 2086 | SetPortCorrectly() { 2087 | local version 2088 | for version in "${versions[@]}"; do 2089 | for edition in "${editions[@]}"; do 2090 | setup "${FUNCNAME[0]} ${version}-${edition}" 2091 | 2092 | # Make an installation 2093 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 2094 | 2095 | # Test http port 2096 | assert_raises "./ineo create -e $edition -v $version twitter" 0 2097 | 2098 | assert_raises "./ineo set-port twitter 1" 0 2099 | assert "./ineo set-port twitter 1" \ 2100 | " 2101 | ${GREEN}The http port was successfully changed to ${BOLD}1${GREEN}.${NF} 2102 | " 2103 | 2104 | assert_raises "./ineo set-port twitter 65535" 0 2105 | assert "./ineo set-port twitter 65535" \ 2106 | " 2107 | ${GREEN}The http port was successfully changed to ${BOLD}65535${GREEN}.${NF} 2108 | " 2109 | 2110 | # Test https port 2111 | assert_raises "./ineo set-port -s twitter 1" 0 2112 | assert "./ineo set-port -s twitter 1" \ 2113 | " 2114 | ${GREEN}The https port was successfully changed to ${BOLD}1${GREEN}.${NF} 2115 | " 2116 | 2117 | assert_raises "./ineo set-port -s twitter 65535" 0 2118 | assert "./ineo set-port -s twitter 65535" \ 2119 | " 2120 | ${GREEN}The https port was successfully changed to ${BOLD}65535${GREEN}.${NF} 2121 | " 2122 | 2123 | # Test bolt port 2124 | if [ ${version%%.*} -gt 2 ]; then 2125 | assert_raises "./ineo set-port -b twitter 1" 0 2126 | assert "./ineo set-port -b twitter 1" \ 2127 | " 2128 | ${GREEN}The bolt port was successfully changed to ${BOLD}1${GREEN}.${NF} 2129 | " 2130 | 2131 | assert_raises "./ineo set-port -b twitter 65535" 0 2132 | assert "./ineo set-port -b twitter 65535" \ 2133 | " 2134 | ${GREEN}The bolt port was successfully changed to ${BOLD}65535${GREEN}.${NF} 2135 | " 2136 | fi 2137 | done 2138 | done 2139 | assert_end SetPortCorrectly 2140 | } 2141 | tests+=('SetPortCorrectly') 2142 | 2143 | # ============================================================================== 2144 | # TEST SET-CONFIG 2145 | # ============================================================================== 2146 | 2147 | SetConfigWithIncorrectParameters() { 2148 | setup "${FUNCNAME[0]}" 2149 | 2150 | local params=( 2151 | "-x" 'x' 2152 | ) 2153 | 2154 | local i 2155 | for ((i=0; i<${#params[*]}; i+=2)); do 2156 | assert_raises "./ineo set-config ${params[i]}" 1 2157 | assert "./ineo set-config ${params[i]}" \ 2158 | " 2159 | ${PURPLE}Error -> Invalid argument or option ${BOLD}${params[i+1]} 2160 | 2161 | ${NF}View help about the command ${UNDERLINE}set-config${NF} typing: 2162 | ${CYAN}ineo help set-config${NF} 2163 | " 2164 | done 2165 | 2166 | params=( 2167 | "instance" 2168 | "instance param" 2169 | "instance param value more" 2170 | "-d instance" 2171 | "-d instance param value" 2172 | ) 2173 | 2174 | for ((i=0; i<${#params[*]}; i+=1)); do 2175 | assert_raises "./ineo set-config ${params[i]}" 1 2176 | assert "./ineo set-config ${params[i]}" \ 2177 | " 2178 | ${PURPLE}Error -> ${BOLD}set-config${PURPLE} requires an instance name, parameter and value 2179 | 2180 | ${NF}View help about the command ${UNDERLINE}set-config${NF} typing: 2181 | ${CYAN}ineo help set-config${NF} 2182 | " 2183 | done 2184 | 2185 | assert_end SetConfigWithIncorrectParameters 2186 | } 2187 | tests+=('SetConfigWithIncorrectParameters') 2188 | 2189 | SetConfigWithCorrectParameters() { 2190 | setup "${FUNCNAME[0]}" 2191 | 2192 | # Make an installation 2193 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 2194 | 2195 | assert_raises "./ineo create twitter" 0 2196 | 2197 | # add non-existing param 2198 | assert_raises "grep twitter.one.a $(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf" 1 2199 | assert_raises "./ineo set-config twitter twitter.one.a 1" 0 2200 | assert_raises "grep twitter.one.a $(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf" 0 2201 | assert "grep twitter.one.a $(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf" "twitter.one.a=1" 2202 | 2203 | # uncomment existing param 2204 | assert_raises "grep '^#dbms.active_database' $(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf" 0 2205 | assert "grep '^#dbms.active_database' $(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf" "#dbms.active_database=graph.db" 2206 | assert_raises "./ineo set-config twitter dbms.active_database graph.db" 0 2207 | assert_raises "grep '^dbms.active_database' $(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf" 0 2208 | assert "grep '^dbms.active_database' $(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf" "dbms.active_database=graph.db" 2209 | 2210 | # uncomment existing param with backslash 2211 | assert_raises "grep '^#dbms.directories.data' $(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf" 0 2212 | assert "grep '^#dbms.directories.data' $(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf" "#dbms.directories.data=data" 2213 | assert_raises "./ineo set-config twitter dbms.directories.data /path/to/data" 0 2214 | assert_raises "grep '^dbms.directories.data' $(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf" 0 2215 | assert "grep '^dbms.directories.data' $(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf" "dbms.directories.data=/path/to/data" 2216 | 2217 | # comment existing param 2218 | assert_raises "grep '^dbms.connector.bolt.enabled' $(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf" 0 2219 | assert "grep '^dbms.connector.bolt.enabled' $(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf" "dbms.connector.bolt.enabled=true" 2220 | assert_raises "./ineo set-config -d twitter dbms.connector.bolt.enabled" 0 2221 | assert_raises "grep '^#dbms.connector.bolt.enabled' $(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf" 0 2222 | assert "grep '^#dbms.connector.bolt.enabled' $(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf" "#dbms.connector.bolt.enabled=true" 2223 | 2224 | assert "./ineo set-config -q twitter dbms.connector.bolt.enabled true" "" 2225 | assert "./ineo set-config -dq twitter dbms.connector.bolt.enabled" "" 2226 | 2227 | assert_end SetConfigWithCorrectParameters 2228 | } 2229 | tests+=('SetConfigWithCorrectParameters') 2230 | 2231 | # ============================================================================== 2232 | # TEST GET-CONFIG 2233 | # ============================================================================== 2234 | 2235 | GetConfigWithIncorrectParameters() { 2236 | setup "${FUNCNAME[0]}" 2237 | 2238 | local params=( 2239 | "-x" 'x' 2240 | ) 2241 | 2242 | local i 2243 | for ((i=0; i<${#params[*]}; i+=2)); do 2244 | assert_raises "./ineo get-config ${params[i]}" 1 2245 | assert "./ineo get-config ${params[i]}" \ 2246 | " 2247 | ${PURPLE}Error -> Invalid argument or option ${BOLD}${params[i+1]} 2248 | 2249 | ${NF}View help about the command ${UNDERLINE}get-config${NF} typing: 2250 | ${CYAN}ineo help get-config${NF} 2251 | " 2252 | done 2253 | 2254 | params=( 2255 | "instance" 2256 | "-a instance param" 2257 | ) 2258 | 2259 | for ((i=0; i<${#params[*]}; i+=1)); do 2260 | assert_raises "./ineo get-config ${params[i]}" 1 2261 | assert "./ineo get-config ${params[i]}" \ 2262 | " 2263 | ${PURPLE}Error -> ${BOLD}get-config${PURPLE} requires an instance name and parameter 2264 | 2265 | ${NF}View help about the command ${UNDERLINE}get-config${NF} typing: 2266 | ${CYAN}ineo help get-config${NF} 2267 | " 2268 | done 2269 | 2270 | assert_end GetConfigWithIncorrectParameters 2271 | } 2272 | tests+=('GetConfigWithIncorrectParameters') 2273 | 2274 | GetConfigWithCorrectParameters() { 2275 | setup "${FUNCNAME[0]}" 2276 | 2277 | # Make an installation 2278 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 2279 | 2280 | assert_raises "./ineo create twitter" 0 2281 | assert_raises "./ineo create facebook" 0 2282 | assert_raises "./ineo create apple" 0 2283 | 2284 | local params=( 2285 | "twitter" 2286 | "facebook" 2287 | "apple" 2288 | ) 2289 | 2290 | local i 2291 | for ((i=0; i<${#params[*]}; i+=1)); do 2292 | # insert param to all instances 2293 | assert_raises "./ineo set-config ${params[i]} all.one.a 1" 0 2294 | assert_raises "./ineo set-config ${params[i]} all.one.b 2" 0 2295 | assert_raises "./ineo set-config ${params[i]} all.two.a 3" 0 2296 | assert_raises "./ineo set-config ${params[i]} all.two.b 4" 0 2297 | done 2298 | 2299 | # insert param to all but one instance 2300 | assert_raises "./ineo set-config twitter twitter.one.a 1" 0 2301 | assert_raises "./ineo set-config twitter twitter.one.b 2" 0 2302 | assert_raises "./ineo set-config apple apple.one.a 1" 0 2303 | assert_raises "./ineo set-config apple apple.one.b 2" 0 2304 | 2305 | # try all formats with single instance and single param 2306 | assert_raises "./ineo get-config twitter twitter.one.a" 0 2307 | assert "./ineo get-config twitter twitter.one.a" "twitter.one.a=1" 2308 | 2309 | assert_raises "./ineo get-config -o list twitter twitter.one.a" 0 2310 | assert "./ineo get-config -o list twitter twitter.one.a" \ 2311 | " 2312 | > instance 'twitter' 2313 | twitter.one.a=1" 2314 | 2315 | assert_raises "./ineo get-config -o ini twitter twitter.one.a" 0 2316 | assert "./ineo get-config -o ini twitter twitter.one.a" "[twitter]\ntwitter.one.a=1" 2317 | 2318 | assert_raises "./ineo get-config -o line twitter twitter.one.a" 0 2319 | assert "./ineo get-config -o line twitter twitter.one.a" "twitter.one.a=1" 2320 | 2321 | assert_raises "./ineo get-config -o value twitter twitter.one.a" 0 2322 | assert "./ineo get-config -o value twitter twitter.one.a" "1" 2323 | 2324 | 2325 | # try all formats with all instance and single param existing in all instances 2326 | assert_raises "./ineo get-config -a all.one.a" 0 2327 | assert "./ineo get-config -a all.one.a" \ 2328 | " 2329 | > instance 'apple' 2330 | all.one.a=1 2331 | 2332 | 2333 | > instance 'facebook' 2334 | all.one.a=1 2335 | 2336 | 2337 | > instance 'twitter' 2338 | all.one.a=1" 2339 | 2340 | assert_raises "./ineo get-config -a -o list all.one.a" 0 2341 | assert "./ineo get-config -a -o list all.one.a" \ 2342 | " 2343 | > instance 'apple' 2344 | all.one.a=1 2345 | 2346 | 2347 | > instance 'facebook' 2348 | all.one.a=1 2349 | 2350 | 2351 | > instance 'twitter' 2352 | all.one.a=1" 2353 | 2354 | 2355 | assert_raises "./ineo get-config -a -o ini all.one.a" 0 2356 | assert "./ineo get-config -a -o ini all.one.a" \ 2357 | "[apple] 2358 | all.one.a=1 2359 | 2360 | [facebook] 2361 | all.one.a=1 2362 | 2363 | [twitter] 2364 | all.one.a=1" 2365 | 2366 | assert_raises "./ineo get-config -a -o line all.one.a" 0 2367 | assert "./ineo get-config -a -o line all.one.a" \ 2368 | " 2369 | > instance 'apple' 2370 | all.one.a=1 2371 | 2372 | 2373 | > instance 'facebook' 2374 | all.one.a=1 2375 | 2376 | 2377 | > instance 'twitter' 2378 | all.one.a=1" 2379 | 2380 | 2381 | assert_raises "./ineo get-config -a -o value all.one.a" 0 2382 | assert "./ineo get-config -a -o value all.one.a" \ 2383 | " 2384 | > instance 'apple' 2385 | all.one.a=1 2386 | 2387 | 2388 | > instance 'facebook' 2389 | all.one.a=1 2390 | 2391 | 2392 | > instance 'twitter' 2393 | all.one.a=1" 2394 | 2395 | 2396 | # try multi formats with all instance and single param existing in one instance 2397 | assert_raises "./ineo get-config -a -o list twitter.one.a" 0 2398 | assert "./ineo get-config -a -o list twitter.one.a" \ 2399 | " 2400 | > instance 'apple' 2401 | WARNING: \"twitter.one.a\" doesn't exist in the \"apple\" configuration 2402 | 2403 | 2404 | > instance 'facebook' 2405 | WARNING: \"twitter.one.a\" doesn't exist in the \"facebook\" configuration 2406 | 2407 | 2408 | > instance 'twitter' 2409 | twitter.one.a=1" 2410 | 2411 | assert_raises "./ineo get-config -a -o ini twitter.one.a" 0 2412 | assert "./ineo get-config -a -o ini twitter.one.a" \ 2413 | "[apple] 2414 | WARNING: \"twitter.one.a\" doesn't exist in the \"apple\" configuration 2415 | 2416 | [facebook] 2417 | WARNING: \"twitter.one.a\" doesn't exist in the \"facebook\" configuration 2418 | 2419 | [twitter] 2420 | twitter.one.a=1" 2421 | 2422 | 2423 | # try quiet mode on multi formats with all instance and single param existing in one instance 2424 | assert_raises "./ineo get-config -a -q -o list twitter.one.a" 0 2425 | assert "./ineo get-config -a -q -o list twitter.one.a" \ 2426 | " 2427 | > instance 'apple' 2428 | 2429 | 2430 | > instance 'facebook' 2431 | 2432 | 2433 | > instance 'twitter' 2434 | twitter.one.a=1" 2435 | 2436 | assert_raises "./ineo get-config -a -q -o ini twitter.one.a" 0 2437 | assert "./ineo get-config -a -q -o ini twitter.one.a" \ 2438 | "[apple] 2439 | [facebook] 2440 | [twitter] 2441 | twitter.one.a=1" 2442 | 2443 | 2444 | # try all formats with one instance and asterix param 2445 | assert_raises "./ineo get-config -o list twitter twitter.one.*" 0 2446 | assert "./ineo get-config -o list twitter twitter.one.*" \ 2447 | " 2448 | > instance 'twitter' 2449 | twitter.one.a=1 2450 | twitter.one.b=2" 2451 | 2452 | assert_raises "./ineo get-config -o ini twitter twitter.one.*" 0 2453 | assert "./ineo get-config -o ini twitter twitter.one.*" \ 2454 | "[twitter] 2455 | twitter.one.a=1 2456 | twitter.one.b=2" 2457 | 2458 | assert_raises "./ineo get-config -o line twitter twitter.one.*" 0 2459 | assert "./ineo get-config -o line twitter twitter.one.*" \ 2460 | "twitter.one.a=1 2461 | twitter.one.b=2" 2462 | 2463 | assert_raises "./ineo get-config -o line twitter all.*.b" 0 2464 | assert "./ineo get-config -o line twitter all.*.b" \ 2465 | "all.one.b=2 2466 | all.two.b=4" 2467 | 2468 | assert_raises "./ineo get-config -o value twitter twitter.one.*" 0 2469 | assert "./ineo get-config -o value twitter twitter.one.*" \ 2470 | "twitter.one.a=1 2471 | twitter.one.b=2" 2472 | 2473 | # try multi formats with all instance and asterix param 2474 | assert_raises "./ineo get-config -a -o list twitter.one.*" 0 2475 | assert "./ineo get-config -a -o list twitter.one.*" \ 2476 | " 2477 | > instance 'apple' 2478 | 2479 | 2480 | > instance 'facebook' 2481 | 2482 | 2483 | > instance 'twitter' 2484 | twitter.one.a=1 2485 | twitter.one.b=2" 2486 | 2487 | assert_raises "./ineo get-config -a -o ini twitter.one.*" 0 2488 | assert "./ineo get-config -a -o ini twitter.one.*" \ 2489 | "[apple] 2490 | [facebook] 2491 | [twitter] 2492 | twitter.one.a=1 2493 | twitter.one.b=2" 2494 | 2495 | 2496 | assert_end GetConfigWithCorrectParameters 2497 | } 2498 | tests+=('GetConfigWithCorrectParameters') 2499 | 2500 | # ============================================================================== 2501 | # TEST BACKUP 2502 | # ============================================================================== 2503 | 2504 | BackupWithIncorrectParameters() { 2505 | setup "${FUNCNAME[0]}" 2506 | 2507 | local params=( 2508 | "-x" 'x' 2509 | "-x -y" 'x' 2510 | "-x twitter" 'x' 2511 | "facebook twitter" 'twitter' 2512 | "-x facebook" 'x' 2513 | ) 2514 | 2515 | local i 2516 | for ((i=0; i<${#params[*]}; i+=2)); do 2517 | assert_raises "./ineo backup ${params[i]}" 1 2518 | assert "./ineo backup ${params[i]}" \ 2519 | " 2520 | ${PURPLE}Error -> Invalid argument or option ${BOLD}${params[i+1]} 2521 | 2522 | ${NF}View help about the command ${UNDERLINE}backup${NF} typing: 2523 | ${CYAN}ineo help backup${NF} 2524 | " 2525 | done 2526 | 2527 | assert_end BackupWithIncorrectParameters 2528 | } 2529 | tests+=('BackupWithIncorrectParameters') 2530 | 2531 | 2532 | BackupWithoutTheRequireParameters() { 2533 | setup "${FUNCNAME[0]}" 2534 | 2535 | # Make an installation 2536 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 2537 | 2538 | assert_raises "./ineo create twitter" 0 2539 | 2540 | assert_raises "./ineo backup" 1 2541 | assert "./ineo backup" \ 2542 | " 2543 | ${PURPLE}Error -> ${BOLD}backup${PURPLE} requires an instance name 2544 | 2545 | ${NF}View help about the command ${UNDERLINE}backup${NF} typing: 2546 | ${CYAN}ineo help backup${NF} 2547 | " 2548 | 2549 | assert_end BackupWithoutTheRequireParameters 2550 | } 2551 | tests+=('BackupWithoutTheRequireParameters') 2552 | 2553 | 2554 | BackupOnANonExistentInstance() { 2555 | setup "${FUNCNAME[0]}" 2556 | 2557 | # Make an installation 2558 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 2559 | 2560 | assert_raises "./ineo backup twitter" 1 2561 | assert "./ineo backup twitter" \ 2562 | " 2563 | ${PURPLE}Error -> There is not an instance with the name ${BOLD}twitter${PURPLE} or is not properly installed 2564 | 2565 | ${NF}List installed instances typing: 2566 | ${CYAN}ineo instances${NF} 2567 | " 2568 | 2569 | assert_end BackupOnANonExistentInstance 2570 | } 2571 | tests+=('BackupOnANonExistentInstance') 2572 | 2573 | 2574 | BackupCorrectly() { 2575 | local version 2576 | local minor_version_number 2577 | for version in "${versions[@]}"; do 2578 | for edition in "${editions[@]}"; do 2579 | setup "${FUNCNAME[0]} ${version}-${edition}" 2580 | 2581 | # Make an installation 2582 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 2583 | 2584 | # Test confirming without an instance running 2585 | 2586 | assert_raises "./ineo create -e $edition -v $version twitter" 0 2587 | 2588 | minor_version_number=${version%.*} 2589 | if [[ "${minor_version_number}" < "3.1" ]]; then 2590 | # only neo4j >=3.x is supported for backup 2591 | assert_raises "./ineo backup twitter" 1 2592 | 2593 | assert "./ineo backup twitter" \ 2594 | " 2595 | ${PURPLE}Error -> ${BOLD}backup${PURPLE} requires instance to run Neo4j version 3.1 or higher 2596 | 2597 | ${NF}View help about the command ${UNDERLINE}backup${NF} typing: 2598 | ${CYAN}ineo help backup${NF} 2599 | 2600 | " 2601 | continue 2602 | fi 2603 | 2604 | 2605 | # start to create graph.db 2606 | assert_raises "./ineo start twitter" 0 2607 | set_instance_pid twitter 2608 | assert_run_pid "${pid}" twitter 2609 | 2610 | assert_raises "./ineo backup -p /tmp/ineo$$.dump twitter" 0 2611 | assert_raises "test -s /tmp/ineo$$.dump" 0 2612 | rm /tmp/ineo$$.dump 2613 | 2614 | # check if instance was restarted after backup 2615 | set_instance_pid twitter 2616 | assert_run_pid "${pid}" twitter 2617 | 2618 | assert_raises "./ineo stop twitter" 0 2619 | assert_not_run_pid $pid 2620 | 2621 | done 2622 | done 2623 | assert_end BackupCorrectly 2624 | } 2625 | tests+=('BackupCorrectly') 2626 | 2627 | 2628 | BackupPath() { 2629 | setup "${FUNCNAME[0]}" 2630 | 2631 | # Make an installation 2632 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 2633 | 2634 | assert_raises "./ineo create -v ${LAST_VERSION} twitter" 0 2635 | 2636 | # start to create graph.db 2637 | assert_raises "./ineo start twitter" 0 2638 | set_instance_pid twitter 2639 | assert_run_pid "${pid}" twitter 2640 | 2641 | # stop 2642 | assert_raises "./ineo stop twitter" 0 2643 | assert_not_run_pid $pid 2644 | 2645 | # check path including filename 2646 | assert_raises "./ineo backup -p /tmp/ineo$$.dump twitter" 0 2647 | assert_raises "test -s /tmp/ineo$$.dump" 0 2648 | rm /tmp/ineo$$.dump 2649 | 2650 | assert "./ineo status twitter" \ 2651 | "$(get_not_running_message $version twitter)" 2652 | 2653 | # check path without filename 2654 | mkdir /tmp/ineo$$ 2655 | assert_raises "./ineo backup -p /tmp/ineo$$/ twitter" 0 2656 | assert_raises "test -s /tmp/ineo$$/ineo_twitter_*.dump" 0 2657 | rm -rf /tmp/ineo$$/ 2658 | 2659 | assert_end BackupPath 2660 | } 2661 | tests+=('BackupPath') 2662 | 2663 | 2664 | 2665 | # ============================================================================== 2666 | # TEST RESTORE 2667 | # ============================================================================== 2668 | 2669 | RestoreWithIncorrectParameters() { 2670 | setup "${FUNCNAME[0]}" 2671 | 2672 | local params=( 2673 | "-x" 'x' 2674 | "-x -y" 'x' 2675 | "-x twitter" 'x' 2676 | "-x facebook" 'x' 2677 | ) 2678 | 2679 | local i 2680 | for ((i=0; i<${#params[*]}; i+=2)); do 2681 | assert_raises "./ineo restore ${params[i]}" 1 2682 | assert "./ineo restore ${params[i]}" \ 2683 | " 2684 | ${PURPLE}Error -> Invalid argument or option ${BOLD}${params[i+1]} 2685 | 2686 | ${NF}View help about the command ${UNDERLINE}restore${NF} typing: 2687 | ${CYAN}ineo help restore${NF} 2688 | " 2689 | done 2690 | 2691 | assert_end RestoreWithIncorrectParameters 2692 | } 2693 | tests+=('RestoreWithIncorrectParameters') 2694 | 2695 | 2696 | RestoreWithoutTheRequireParameters() { 2697 | setup "${FUNCNAME[0]}" 2698 | 2699 | # Make an installation 2700 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 2701 | 2702 | assert_raises "./ineo create twitter" 0 2703 | 2704 | assert_raises "./ineo restore nosuchfile" 1 2705 | assert "./ineo restore nosuchfile" \ 2706 | " 2707 | ${PURPLE}Error -> No dump file ${BOLD}nosuchfile${PURPLE} found${NF} 2708 | " 2709 | 2710 | assert_raises "./ineo restore ineo" 1 2711 | assert "./ineo restore ineo" \ 2712 | " 2713 | ${PURPLE}Error -> ${BOLD}restore${PURPLE} requires an instance name 2714 | 2715 | ${NF}View help about the command ${UNDERLINE}restore${NF} typing: 2716 | ${CYAN}ineo help restore${NF} 2717 | " 2718 | 2719 | assert_end RestoreWithoutTheRequireParameters 2720 | } 2721 | tests+=('RestoreWithoutTheRequireParameters') 2722 | 2723 | 2724 | RestoreOnANonExistentInstance() { 2725 | setup "${FUNCNAME[0]}" 2726 | 2727 | # Make an installation 2728 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 2729 | 2730 | assert_raises "./ineo restore ineo twitter" 1 2731 | assert "./ineo restore ineo twitter" \ 2732 | " 2733 | ${PURPLE}Error -> There is not an instance with the name ${BOLD}twitter${PURPLE} or is not properly installed 2734 | 2735 | ${NF}List installed instances typing: 2736 | ${CYAN}ineo instances${NF} 2737 | " 2738 | 2739 | assert_end RestoreOnANonExistentInstance 2740 | } 2741 | tests+=('RestoreOnANonExistentInstance') 2742 | 2743 | 2744 | RestoreCorrectly() { 2745 | local version 2746 | local minor_version_number 2747 | for version in "${versions[@]}"; do 2748 | for edition in "${editions[@]}"; do 2749 | setup "${FUNCNAME[0]} ${version}-${edition}" 2750 | 2751 | # Make an installation 2752 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 2753 | 2754 | # Test confirming without an instance running 2755 | 2756 | assert_raises "./ineo create -e $edition -v $version twitter" 0 2757 | 2758 | minor_version_number=${version%.*} 2759 | if [[ "${minor_version_number}" < "3.1" ]]; then 2760 | # only neo4j >=3.x is supported for restore 2761 | assert_raises "./ineo restore ineo twitter" 1 2762 | 2763 | assert "./ineo restore ineo twitter" \ 2764 | " 2765 | ${PURPLE}Error -> ${BOLD}restore${PURPLE} requires instance to run Neo4j version 3.1 or higher 2766 | 2767 | ${NF}View help about the command ${UNDERLINE}restore${NF} typing: 2768 | ${CYAN}ineo help restore${NF} 2769 | 2770 | " 2771 | continue 2772 | fi 2773 | 2774 | 2775 | # create dump file, if not exists yet 2776 | if [[ ! -e /tmp/ineo$$.dump ]]; then 2777 | # start to create graph.db 2778 | assert_raises "./ineo start twitter" 0 2779 | set_instance_pid twitter 2780 | assert_run_pid "${pid}" twitter 2781 | 2782 | assert_raises "./ineo backup -p /tmp/ineo$$.dump twitter" 0 2783 | assert_raises "test -s /tmp/ineo$$.dump" 0 2784 | fi 2785 | 2786 | # Neo4J versions >= 3.x are not creating empty graph.db without a start of the instance 2787 | if [[ ! -d "ineo_for_test/instances/twitter/data/databases/graph.db/" ]]; then 2788 | assert_raises "./ineo start twitter" 0 2789 | set_instance_pid twitter 2790 | assert_run_pid "${pid}" twitter 2791 | fi 2792 | assert_raises "./ineo restore -f /tmp/ineo$$.dump twitter" 0 2793 | 2794 | 2795 | # check if instance can be started after restore 2796 | assert_raises "./ineo start twitter" 0 2797 | set_instance_pid twitter 2798 | assert_run_pid "${pid}" twitter 2799 | 2800 | assert_raises "./ineo stop twitter" 0 2801 | assert_not_run_pid $pid 2802 | 2803 | done 2804 | done 2805 | 2806 | rm /tmp/ineo$$.dump 2807 | 2808 | assert_end RestoreCorrectly 2809 | } 2810 | tests+=('RestoreCorrectly') 2811 | 2812 | 2813 | RestoreForce() { 2814 | setup "${FUNCNAME[0]}" 2815 | 2816 | # Make an installation 2817 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 2818 | 2819 | assert_raises "./ineo create -v ${LAST_VERSION} twitter" 0 2820 | 2821 | # start to create graph.db 2822 | assert_raises "./ineo start twitter" 0 2823 | set_instance_pid twitter 2824 | assert_run_pid "${pid}" twitter 2825 | 2826 | assert_raises "./ineo backup -p /tmp/ineo$$.dump twitter" 0 2827 | assert_raises "test -s /tmp/ineo$$.dump" 0 2828 | 2829 | # use force to prevent interaction 2830 | assert_raises "./ineo restore -f /tmp/ineo$$.dump twitter" 0 2831 | 2832 | assert_raises "echo -ne 'y\n' | ./ineo restore /tmp/ineo$$.dump twitter" 0 2833 | 2834 | # assert "echo -ne 'y\n' | ./ineo restore /tmp/ineo$$.dump twitter" \ 2835 | #" 2836 | # ${YELLOW}Warning -> ${RED}restore${YELLOW} on the instance ${BOLD}twitter${YELLOW} will overwrite all existing data for this instance${NF} 2837 | # 2838 | # 2839 | # ${GREEN}The data for the instance ${BOLD}twitter${GREEN} was successfully restored${NF} 2840 | #" 2841 | 2842 | 2843 | # check if instance can be started after restore 2844 | assert_raises "./ineo start twitter" 0 2845 | set_instance_pid twitter 2846 | assert_run_pid "${pid}" twitter 2847 | 2848 | assert_raises "./ineo stop twitter" 0 2849 | assert_not_run_pid $pid 2850 | 2851 | rm /tmp/ineo$$.dump 2852 | 2853 | 2854 | assert_end RestoreForce 2855 | } 2856 | tests+=('RestoreForce') 2857 | 2858 | 2859 | 2860 | # ============================================================================== 2861 | # TEST CLEAR-DATA 2862 | # ============================================================================== 2863 | 2864 | ClearDataWithIncorrectParameters() { 2865 | setup "${FUNCNAME[0]}" 2866 | 2867 | local params=( 2868 | "-x" 'x' 2869 | "-x -y" 'x' 2870 | "-x twitter" 'x' 2871 | "facebook twitter" 'twitter' 2872 | "-x facebook" 'x' 2873 | ) 2874 | 2875 | local i 2876 | for ((i=0; i<${#params[*]}; i+=2)); do 2877 | assert_raises "./ineo delete-db ${params[i]}" 1 2878 | assert "./ineo delete-db ${params[i]}" \ 2879 | " 2880 | ${PURPLE}Error -> Invalid argument or option ${BOLD}${params[i+1]} 2881 | 2882 | ${NF}View help about the command ${UNDERLINE}delete-db${NF} typing: 2883 | ${CYAN}ineo help delete-db${NF} 2884 | " 2885 | done 2886 | 2887 | assert_end ClearDataWithIncorrectParameters 2888 | } 2889 | tests+=('ClearDataWithIncorrectParameters') 2890 | 2891 | 2892 | ClearDataWithoutTheRequireParameters() { 2893 | setup "${FUNCNAME[0]}" 2894 | 2895 | # Make an installation 2896 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 2897 | 2898 | assert_raises "./ineo create twitter" 0 2899 | 2900 | assert_raises "./ineo delete-db" 1 2901 | assert "./ineo delete-db" \ 2902 | " 2903 | ${PURPLE}Error -> ${BOLD}delete-db${PURPLE} requires an instance name 2904 | 2905 | ${NF}View help about the command ${UNDERLINE}delete-db${NF} typing: 2906 | ${CYAN}ineo help delete-db${NF} 2907 | " 2908 | 2909 | assert_end ClearDataWithoutTheRequireParameters 2910 | } 2911 | tests+=('ClearDataWithoutTheRequireParameters') 2912 | 2913 | 2914 | ClearDataOnANonExistentInstance() { 2915 | setup "${FUNCNAME[0]}" 2916 | 2917 | # Make an installation 2918 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 2919 | 2920 | assert_raises "./ineo delete-db twitter" 1 2921 | assert "./ineo delete-db twitter" \ 2922 | " 2923 | ${PURPLE}Error -> There is not an instance with the name ${BOLD}twitter${PURPLE} or is not properly installed 2924 | 2925 | ${NF}List installed instances typing: 2926 | ${CYAN}ineo list${NF} 2927 | " 2928 | 2929 | assert_end ClearDataOnANonExistentInstance 2930 | } 2931 | tests+=('ClearDataOnANonExistentInstance') 2932 | 2933 | 2934 | ClearDataCorrectly() { 2935 | local version 2936 | local dbFolder 2937 | for version in "${versions[@]}"; do 2938 | for edition in "${editions[@]}"; do 2939 | setup "${FUNCNAME[0]} ${version}-${edition}" 2940 | dbFolder=$(database_folder_version "${version}") 2941 | 2942 | # Make an installation 2943 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 2944 | 2945 | # Test confirming without an instance running 2946 | 2947 | assert_raises "./ineo create -e $edition -v $version twitter" 0 2948 | # Create a fake directory 2949 | assert_raises "mkdir ineo_for_test/instances/twitter${dbFolder}/graph.db" 0 2950 | assert_raises "test -d ineo_for_test/instances/twitter${dbFolder}/graph.db" 0 2951 | 2952 | assert_raises "echo -ne 'y\n' | ./ineo delete-db twitter" 0 2953 | 2954 | # Create a fake directory 2955 | assert_raises "mkdir ineo_for_test/instances/twitter${dbFolder}/graph.db" 0 2956 | assert_raises "test -d ineo_for_test/instances/twitter${dbFolder}/graph.db" 0 2957 | 2958 | assert "echo -ne 'y\n' | ./ineo delete-db twitter" \ 2959 | " 2960 | ${YELLOW}Warning -> ${RED}delete-db${YELLOW} on the instance ${BOLD}twitter${YELLOW} will remove all data for this instance${NF} 2961 | 2962 | 2963 | ${GREEN}The data for the instance ${BOLD}twitter${GREEN} was successfully removed${NF} 2964 | " 2965 | 2966 | assert_raises "test -d ineo_for_test/instances/twitter${dbFolder}/graph.db" 1 2967 | 2968 | # Test confirming with an instance running 2969 | 2970 | # Create a fake directory 2971 | assert_raises "mkdir ineo_for_test/instances/twitter${dbFolder}/graph.db" 0 2972 | assert_raises "test -d ineo_for_test/instances/twitter${dbFolder}/graph.db" 0 2973 | 2974 | assert_raises "./ineo start twitter" 0 2975 | 2976 | set_instance_pid twitter 2977 | assert_run_pid "${pid}" twitter 2978 | 2979 | assert_raises "echo -ne 'y\ny\n' | ./ineo delete-db twitter" 0 2980 | 2981 | assert_raises "test -d ineo_for_test/instances/twitter${dbFolder}/graph.db" 1 2982 | 2983 | assert_not_run_pid $pid 2984 | 2985 | # Test forcing without an instance running 2986 | 2987 | # Create a fake directory 2988 | assert_raises "mkdir ineo_for_test/instances/twitter${dbFolder}/graph.db" 0 2989 | assert_raises "test -d ineo_for_test/instances/twitter${dbFolder}/graph.db" 0 2990 | 2991 | assert_raises "./ineo delete-db -f twitter" 0 2992 | 2993 | assert_raises "test -d ineo_for_test/instances/twitter${dbFolder}/graph.db" 1 2994 | 2995 | # Create a fake directory 2996 | assert_raises "mkdir ineo_for_test/instances/twitter${dbFolder}/graph.db" 0 2997 | assert_raises "test -d ineo_for_test/instances/twitter${dbFolder}/graph.db" 0 2998 | 2999 | assert "./ineo delete-db -f twitter" \ 3000 | " 3001 | ${GREEN}The data for the instance ${BOLD}twitter${GREEN} was successfully removed${NF} 3002 | " 3003 | 3004 | assert_raises "test -d ineo_for_test/instances/twitter${dbFolder}/graph.db" 1 3005 | 3006 | # Test forcing with an instance running 3007 | 3008 | # Create a fake directory 3009 | assert_raises "mkdir ineo_for_test/instances/twitter${dbFolder}/graph.db" 0 3010 | assert_raises "test -d ineo_for_test/instances/twitter${dbFolder}/graph.db" 0 3011 | 3012 | assert_raises "./ineo start twitter" 0 3013 | 3014 | set_instance_pid twitter 3015 | assert_run_pid "${pid}" twitter 3016 | 3017 | assert_raises "./ineo delete-db -f twitter" 0 3018 | 3019 | assert_not_run_pid $pid 3020 | 3021 | assert_raises "test -d ineo_for_test/instances/twitter${dbFolder}/graph.db" 1 3022 | done 3023 | done 3024 | assert_end ClearDataCorrectly 3025 | } 3026 | tests+=('ClearDataCorrectly') 3027 | 3028 | 3029 | ClearDataCorrectlyWithoutADatabaseFile() { 3030 | local version 3031 | for version in "${versions[@]}"; do 3032 | for edition in "${editions[@]}"; do 3033 | setup "${FUNCNAME[0]} ${version}-${edition}" 3034 | 3035 | # Make an installation 3036 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 3037 | 3038 | # Test confirming without an instance running 3039 | 3040 | assert_raises "./ineo create -e $edition -v $version twitter" 0 3041 | assert_raises "test -d ineo_for_test/instances/twitter/data/databases/graph.db" 1 3042 | 3043 | assert_raises "echo -ne 'y\n' | ./ineo delete-db twitter" 0 3044 | 3045 | assert "echo -ne 'y\n' | ./ineo delete-db twitter" \ 3046 | " 3047 | ${YELLOW}Warning -> ${RED}delete-db${YELLOW} on the instance ${BOLD}twitter${YELLOW} will remove all data for this instance${NF} 3048 | 3049 | 3050 | There is not a database on the instance ${UNDERLINE}twitter${NF}, so nothing was removed 3051 | " 3052 | 3053 | # Test confirming with an instance running 3054 | 3055 | assert_raises "./ineo start twitter" 0 3056 | 3057 | set_instance_pid twitter 3058 | assert_run_pid "${pid}" twitter 3059 | 3060 | assert_raises "echo -ne 'y\ny\n' | ./ineo delete-db twitter" 0 3061 | 3062 | assert_raises "test -d ineo_for_test/instances/twitter/data/databases/graph.db" 1 3063 | 3064 | assert_not_run_pid $pid 3065 | 3066 | # Test forcing without an instance running 3067 | 3068 | assert_raises "./ineo delete-db -f twitter" 0 3069 | 3070 | assert "./ineo delete-db -f twitter" \ 3071 | " 3072 | There is not a database on the instance ${UNDERLINE}twitter${NF}, so nothing was removed 3073 | " 3074 | 3075 | # Test forcing with an instance running 3076 | 3077 | assert_raises "./ineo start twitter" 0 3078 | 3079 | set_instance_pid twitter 3080 | assert_run_pid "${pid}" twitter 3081 | 3082 | assert_raises "./ineo delete-db -f twitter" 0 3083 | 3084 | assert_not_run_pid $pid 3085 | 3086 | assert_raises "test -d ineo_for_test/instances/twitter/data/databases/graph.db" 1 3087 | done 3088 | done 3089 | assert_end ClearDataCorrectlyWithoutADatabaseFile 3090 | } 3091 | tests+=('ClearDataCorrectlyWithoutADatabaseFile') 3092 | 3093 | # ============================================================================== 3094 | # TEST UPDATE 3095 | # ============================================================================== 3096 | 3097 | UpdateWithIncorrectParameters() { 3098 | setup "${FUNCNAME[0]}" 3099 | 3100 | local params=( 3101 | "-x" '-x' 3102 | "-x -y" '-x' 3103 | "facebook" 'facebook' 3104 | "facebook twitter" 'facebook' 3105 | "-x facebook" '-x' 3106 | ) 3107 | 3108 | local i 3109 | for ((i=0; i<${#params[*]}; i+=2)); do 3110 | assert_raises "./ineo update ${params[i]}" 1 3111 | assert "./ineo update ${params[i]}" \ 3112 | " 3113 | ${PURPLE}Error -> Invalid argument or option ${BOLD}${params[i+1]} 3114 | 3115 | ${NF}View help about the command ${UNDERLINE}update${NF} typing: 3116 | ${CYAN}ineo help update${NF} 3117 | " 3118 | done 3119 | 3120 | assert_end UpdateWithIncorrectParameters 3121 | } 3122 | tests+=('UpdateWithIncorrectParameters') 3123 | 3124 | 3125 | UpdateCorrectly() { 3126 | setup "${FUNCNAME[0]}" 3127 | 3128 | # Make an installation 3129 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 3130 | assert_raises "./ineo update" 0 3131 | 3132 | setup "${FUNCNAME[0]}" 3133 | assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0 3134 | old_version=$(sed -n '/^VERSION=\(.*\)$/s//\1/p' $INEO_HOME/bin/ineo) 3135 | 3136 | assert "./ineo update" \ 3137 | " 3138 | ${GREEN}Ineo was successfully upgraded from ${BOLD}$old_version${GREEN} to ${BOLD}x.x.x${NF} 3139 | " 3140 | 3141 | assert_raises "test $(sed -n '/^VERSION=\(.*\)$/s//\1/p' $INEO_HOME/bin/ineo) = 'x.x.x'" 0 3142 | 3143 | assert_end UpdateCorrectly 3144 | } 3145 | tests+=('UpdateCorrectly') 3146 | 3147 | 3148 | if [[ -z "$test_name" ]]; then 3149 | for test in "${tests[@]}"; do 3150 | "$test" 3151 | done 3152 | echo -e "\nTests executed in ${SECONDS}sec" 3153 | else 3154 | "$test_name" 3155 | fi 3156 | 3157 | # vim: syntax=sh ts=2 sw=2 et sr softtabstop=2 --------------------------------------------------------------------------------