blob: 2601e0b1aa68dca97655dd9633f70379202c781d [file] [log] [blame]
Chase Qi4a4caa32016-09-06 17:22:46 +08001#!/bin/sh
2
3. ../../lib/sh-test-lib
4OUTPUT="$(pwd)/output"
5RESULT_FILE="${OUTPUT}/result.txt"
6
7usage() {
8 echo "Usage: $0 [-s <true|false>]" 1>&2
9 exit 1
10}
11
12while getopts "s:" o; do
13 case "$o" in
14 s) SKIP_INSTALL="${OPTARG}" ;;
15 *) usage ;;
16 esac
17done
18
19! check_root && error_msg "This script must be run as root"
20[ -d "${OUTPUT}" ] && mv "${OUTPUT}" "${OUTPUT}_$(date +%Y%m%d%H%M%S)"
21mkdir -p "${OUTPUT}"
22
23# Install lamp and use systemctl for service management. Tested on Ubuntu 16.04,
24# Debian 8, CentOS 7 and Fedora 24. systemctl should available on newer releases
25# as well.
26if [ "${SKIP_INSTALL}" = "True" ] || [ "${SKIP_INSTALL}" = "true" ]; then
27 warn_msg "LAMP package installation skipped"
28else
29 dist_name
30 case "${dist}" in
31 Debian|Ubuntu)
32 if [ "${dist}" = "Debian" ]; then
33 pkgs="apache2 mysql-server php5-mysql php5-common libapache2-mod-php5"
34 elif [ "${dist}" = "Ubuntu" ]; then
35 pkgs="apache2 mysql-server php-mysql php-common libapache2-mod-php"
36 fi
37 install_deps "curl ${pkgs}"
38 echo "extension=mysqli.so" >> /etc/php5/apache2/php.ini
39 systemctl restart apache2
40 systemctl restart mysql
41 ;;
42 CentOS|Fedora)
43 pkgs="httpd mariadb-server mariadb php php-mysql"
44 install_deps "curl ${pkgs}"
45 systemctl start httpd.service
46 systemctl start mariadb
47 ;;
48 *)
49 error_msg "Unsupported distribution!"
50 esac
51fi
52
53cp ./html/* /var/www/html/
54
55# Test Apache.
56curl -o "${OUPUT}/index.html" "http://localhost/index.html"
57grep "Test Page for the Apache HTTP Server" "${OUPUT}/index.html"
58check_return "apache2-test-page"
59
60# Test MySQL.
61mysqladmin -u root password lamptest
62mysql --user="root" --password="lamptest" -e "show databases"
63check_return "mysql-show-databases"
64
65# Test PHP.
66curl -o "${OUTPUT}/phpinfo.html" "http://localhost/info.php"
67grep "PHP Version" "${OUTPUT}/phpinfo.html"
68check_return "phpinfo"
69
70# PHP Connect to MySQL.
71curl -o "${OUTPUT}/connect-db" "http://localhost/connect-db.php"
72grep "Connected successfully" "${OUTPUT}/connect-db"
73exit_on_fail "php-connect-db"
74
75# PHP Create a MySQL Database.
76curl -o "${OUTPUT}/create-db" "http://localhost/create-db.php"
77grep "Database created successfully" "${OUTPUT}/create-db"
78check_return "php-create-db"
79
80# PHP Create MySQL table.
81curl -o "${OUTPUT}/create-table" "http://localhost/create-table.php"
82grep "Table MyGuests created successfully" "${OUTPUT}/create-table"
83check_return "php-create-table"
84
85# PHP add record to MySQL table.
86curl -o "${OUTPUT}/add-record" "http://localhost/add-record.php"
87grep "New record created successfully" "${OUTPUT}/add-record"
88check_return "php-add-record"
89
90# PHP select record from MySQL table.
91curl -o "${OUTPUT}/select-record" "http://localhost/select-record.php"
92grep "id: 1 - Name: John Doe" "${OUTPUT}/select-record"
93check_return "php-select-record"
94
95# PHP delete record from MySQL table.
96curl -o "${OUTPUT}/delete-record" "http://localhost/delete-record.php"
97grep "Record deleted successfully" "${OUTPUT}/delete-record"
98check_return "php-delete-record"