You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
INSTALL_DIR="${INSTALL_DIR:-/opt}"
MIRROR_SITE="${MIRROR_SITE:-https://d.chaifeng.com/mirror}"
SOFTWARE_CACHE_DIR="${SOFTWARE_CACHE_DIR:-/vagrant}"
typeset -A JDK_VERSION_MAP
JDK_VERSION_MAP[8u131]='jdk1.8.0_131'
Global functions
function apt_install() {
[[ ! -e /var/cache/apt/force_update ]] \
|| [[ "$(( $(date +%s) - $(date -r /var/cache/apt/pkgcache.bin +%s) ))" -gt $(( 3600 * 24 * 3 )) ]] \
&& apt-get update \
&& touch /var/cache/apt/force_update
while [[ -n "${1:-}" ]]; do
PACKAGE="$1"
if apt-cache policy "$PACKAGE" | grep -F 'Installed: (none)'; then
DEBIAN_FRONTEND=noninteractive apt-get install -y "$PACKAGE"
fi
shift
done
}
function get_url() {
URL="$1"
ARCHIVE_FILE="${SOFTWARE_CACHE_DIR}/$(basename "$URL")"
test -n "$URL"
[[ -e "${ARCHIVE_FILE}" ]] \
|| curl --silent -o "${ARCHIVE_FILE}" "${URL}"
}
function unarchive() {
FILE="$1"
CREATES="$2"
[[ -n "$CREATES" ]] && [[ -e "$CREATES" ]] && return 0
if [[ "$FILE" == *.tar.gz ]] || [[ "$FILE" == *.tgz ]]; then
tar -zxf "$FILE"
elif [[ "$FILE" == *.zip ]]; then
type unzip || apt-get install -y unzip
unzip "$FILE"
else
echo "Unknow file format, $FILE"
return 2
fi
}
Install dependent applications
Install MySQL
apt_install mysql-client mysql-server
Create database user and grant permission
mysql -uroot mysql <<< "select * from user where user='${DATABASE_USER}';" | grep -F mysql_native_password \
|| echo "CREATE USER '${DATABASE_USER}'@'%' IDENTIFIED BY '${DATABASE_PASS}';" | mysql -uroot
echo "GRANT ALL PRIVILEGES ON * . * TO '${DATABASE_USER}'@'%';" | mysql -uroot
echo 'CREATE DATABASE /*!32312 IF NOT EXISTS*/ '"${DATABASE_NAME}"' /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */;' | mysql -uroot