-
Notifications
You must be signed in to change notification settings - Fork 0
/
.lib
46 lines (44 loc) · 1.35 KB
/
.lib
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
#!/bin/sh
# @author Thomas Baier <thomas.baier.halle@gmail.com>
# @license MIT
# --- texts --- #
INFO_CURRENT_VERSION='Current PHP version:'
INFO_CHOICE_LABEL='Choose binary to switch to:'
SUCCESS_SWITCHED='Successfully switched to PHP-Binary'
ERROR_NO_BINARIES='No PHP binaries found!'
ERROR_NO_ALTERNATIVE_BINARIES='No alternative PHP binaries found!'
ERROR_PHP_INSTALLATION='No PHP installation found!'
ERROR_UNKNOWN_OPTION='Option does not exist!'
# colors
COLOR_RED='\033[0;31m'
COLOR_GREEN='\033[0;32m'
COLOR_BLUE='\033[0;36m'
COLOR_BLUE='\033[0;34m'
COLOR_ORANGE='\033[0;33m'
COLOR_END='\033[0m'
# --- helper functions --- #
error () {
printf "${COLOR_RED}ERROR:${COLOR_END} $*\n"
exit 1
}
info () {
printf "${COLOR_BLUE}INFO:${COLOR_END} $*\n"
}
success () {
printf "${COLOR_GREEN}INFO:${COLOR_END} $*\n"
}
validate_choice () {
case $1 in
''|*[!0-9]*) error ${ERROR_UNKNOWN_OPTION} ;;
esac
# compare choice range with input
if [ "$1" -gt "$CHOICES_COUNT" ]; then
error ${ERROR_UNKNOWN_OPTION}
fi
change_php_version $1
}
change_php_version () {
php_binary_to_switch=$(echo ${PHP_ALTERNATIVES} | cut -f "$1" -d " ")
sudo update-alternatives --set php ${php_binary_to_switch} 2>&1 >/dev/null
success ${SUCCESS_SWITCHED} ${php_binary_to_switch} with version name $(${php_binary_to_switch} -r 'echo PHP_VERSION;')
}