post_install() {

    echo "Set up mysql database"
    mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
    systemctl start mysqld.service && sleep 2
    mysql -u root -e "CREATE USER 'ethoscope'@'localhost' IDENTIFIED BY 'ethoscope'"
    mysql -u root -e "CREATE USER 'ethoscope'@'%' IDENTIFIED BY 'ethoscope'"
    mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'ethoscope'@'localhost' WITH GRANT OPTION";
    mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'ethoscope'@'%' WITH GRANT OPTION";
    chown -R mysql:mysql /var/lib/mysql

    echo "setup mariadb configuration"
    echo '[server]' > /etc/my.cnf.d/server.cnf
    echo 'log-bin=mysql-bin' >> /etc/my.cnf.d/server.cnf
    echo 'binlog_format=mixed' >> /etc/my.cnf.d/server.cnf
    echo 'expire_logs_days = 10' >> /etc/my.cnf.d/server.cnf
    echo 'max_binlog_size  = 100M' >> /etc/my.cnf.d/server.cnf

    #create the python package for the ethoscope
    cd /opt/ethoscope-node/src/
    python setup.py develop

    echo "enable the virtuascope and mysqldb services"
    cp /opt/ethoscope-node/scripts/virtuascope.service /usr/lib/systemd/system/
    systemctl enable virtuascope
    systemctl enable mysqld
    systemctl start virtuascope

}

pre_remove() {
    echo "disabling systemd service files"
    systemctl stop ethoscope_virtuascope
    systemctl disable ethoscope_virtuascope
}
