Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # Copyright 2015 Red Hat, Inc.
- #
- # NAME
- # demo-create-mysql - grading/setup script for DO276
- #
- # SYNOPSIS
- # demo-create-mysql {setup|grade|solve|reset}
- #
- # setup - no setup is needed for this lab
- # grade - checks if the docker image was pulled and it is running
- # solve - installs a mysql:5.5 image with the name demo-mysql-basic
- # reset - destroys the mysql container and remove the image from the local repository
- #
- # All functions only work on workstation
- #
- # DESCRIPTION
- # This script is used by the Demo: Creating a MySQL database instance
- #
- # CHANGELOG
- # * Thu Feb 04 2016 Ricardo Jun <jtaniguc@redhat.com>
- # - Updated to fix the command issued for the lab
- # * Thu Dec 17 2015 Ricardo Jun <jtaniguc@redhat.com>
- # - Updated the script name
- # - include sudo to the commands
- # * Wed Dec 16 2015 Ricardo Jun <jtaniguc@redhat.com>
- # - original code
- PATH=/usr/bin:/bin:/usr/sbin:/sbin
- # Initialize and set some variables
- target='workstation'
- # This defines which subcommands are supported (solve, reset, etc.).
- # Corresponding lab_COMMAND functions must be defined.
- declare -a valid_commands=(setup grade solve reset)
- # Additional functions for this grading script
- function print_usage {
- local problem_name=$(basename $0 | sed -e 's/^lab-//')
- cat << EOF
- This script controls the setup and grading of this lab.
- Usage: lab ${problem_name} COMMAND
- lab ${problem_name} -h|--help
- COMMAND is one of: ${valid_commands[@]}
- EOF
- }
- function lab_setup {
- docker_service=$(sudo systemctl status docker.service | grep running | wc -l)
- echo -n " Check if docker daemon is running ... "
- if [ $docker_service -eq 1 ]
- then
- print_SUCCESS
- else
- print_FAIL
- fi
- }
- function lab_grade {
- docker_images=$(docker images | grep "mysql" | grep "5.5" | wc -l 2>/dev/null)
- docker_running_mysql=$(docker ps -a | grep "demo-mysql-basic" | grep "mysql:5.5" | wc -l 2>/dev/null)
- docker_verify_credentials=$(docker exec -it demo-mysql-basic mysql -uuser1 -pmypa55 -N -s -e "show databases;" | grep items | wc -l 2>/dev/null)
- docker_verify_credentials_root=$(docker exec -it demo-mysql-basic mysql -uroot -pr00tpa55 -N -s -e "show databases;" | grep items | wc -l 2>/dev/null)
- echo -n " Check Correct Docker Image ... "
- if [ $docker_images -eq 1 ]
- then
- print_PASS
- else
- print_FAIL
- fi
- echo -n " Check Correct Name And Image ... "
- if [[ $docker_running_mysql -eq 1 ]]
- then
- print_PASS
- else
- print_FAIL
- fi
- echo -n " Check Correct Login/Password to access MySQL ... "
- if [[ $docker_verify_credentials -eq 1 ]]
- then
- print_PASS
- else
- print_FAIL
- fi
- echo -n " Check Root user/Password to access MySQL ... "
- if [[ $docker_verify_credentials_root -eq 1 ]]
- then
- print_PASS
- else
- print_FAIL
- fi
- }
- function lab_solve {
- lab_setup
- lab_reset
- echo -n ' Solving the lab for you ... '
- docker run --name demo-mysql-basic -e MYSQL_USER=user1 -e MYSQL_PASSWORD=mypa55 -e MYSQL_DATABASE=items -e MYSQL_ROOT_PASSWORD=r00tpa55 -d mysql:5.5 2>/dev/null 1>/dev/null
- print_SUCCESS
- sleep 15
- echo
- }
- function lab_reset {
- echo -n ' Stopping containers ... '
- docker stop demo-mysql-basic 2>/dev/null 1>/dev/null
- print_SUCCESS
- echo -n ' Removing containers ... '
- docker rm demo-mysql-basic 2>/dev/null 1>/dev/null
- print_SUCCESS
- echo -n ' Removing images ... '
- docker rmi mysql:5.5 2>/dev/null 1>/dev/null
- print_SUCCESS
- echo
- }
- ############### Don't EVER change anything below this line ###############
- # Source library of functions
- source /usr/local/lib/labtool.shlib
- source /usr/local/lib/labtool.do276.shlib
- grading_main_program "$@"
Add Comment
Please, Sign In to add comment