This repository has been archived by the owner on Mar 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-phpunit-symlink.sh
91 lines (69 loc) · 2.69 KB
/
create-phpunit-symlink.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
# ==============================================================================
# MIT License - Copyright (c) 2017 Dealerdirect B.V.
# ==============================================================================
# ==============================================================================
set -o errexit
set -o errtrace
set -o nounset
set -o pipefail
#-------------------------------------------------------------------------------
readonly EX_OK=0
readonly EX_NOT_ENOUGH_PARAMETERS=65
readonly EX_UNSUPPORTED_PHP_VERSION=66
readonly EX_COULD_NOT_CREATE_SYMLINK=67
# ==============================================================================
# ==============================================================================
createPhpunitSymlink() {
local sTarget
local sLinkName
local sVersion
local iExitCode
iExitCode="${EX_OK}"
readonly sLinkName='phpunit.phar'
if [[ "$#" != 1 ]];then
iExitCode="${EX_NOT_ENOUGH_PARAMETERS}"
echo ' ! ERROR: Not enough parameters given' >&2
echo ' One parameter expected: the PHP version to create a PhpUnit symlink for' >&2
elif [[ "$1" = '--help' ]];then
echo 'One parameter expected: the PHP version to create a PhpUnit symlink for'
else
readonly sVersion="${1}"
case "${sVersion}" in
5.4*|5.5*)
sTarget='phpunit-4.8.35.phar'
;;
5.6*)
sTarget='phpunit-5.7.19.phar'
;;
7.0*|7.1*)
sTarget='phpunit-6.1.3.phar'
;;
*)
iExitCode="${EX_UNSUPPORTED_PHP_VERSION}"
echo " ! ERROR: Given PHP version '${sVersion}' is not supported" >&2
echo ' Use one of 5.4, 5.5, 5.6, 7.0 or 7.1' >&2
;;
esac
if [[ "${iExitCode}" = "${EX_OK}" ]];then
echo "-----> Creating symlink for '${sTarget}'"
ln --symbolic --force "${sTarget}" "${sLinkName}" || {
iExitCode="${EX_COULD_NOT_CREATE_SYMLINK}"
echo ' ! ERROR: Could not create symlink' >&2
}
fi
fi
return "${iExitCode}"
}
# ==============================================================================
# ==============================================================================
# RUN LOGIC
# ------------------------------------------------------------------------------
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
export -f createPhpunitSymlink
else
createPhpunitSymlink "${@}"
exit $?
fi
# ==============================================================================
#EOF