gogs_install.sh

#!/bin/bash
#
#********************************************************************
#Author         : shchangming
#QQ             : 414945814
#Date           : 2019-03-01
#FileName       : gogs_install.sh
#URL            : https://www.cnblogs.com/shichangming
#Description    : The test script
#Copyright (C)  : 2019 All rights reserved
#********************************************************************

# this scripts only for CentOS

_PACKAGE='gogs0.11.4_amd64.tar.gz'
_ADMIN_PASSWD='123456'
_RUN_USER="git"
_USER_PASSWD='gogs'
_DB_ADMIN='root'
_IP='192.168.27.100'
_WEB_PORT=3000
_DB_PORT=3306
_APP_NAME="gogs"

if [ $UID -ne 0 ];then
    echo 'you should be root to install'
    exit 119
fi

which mysql &> /dev/null
if [ $? -ne 0 ];then
    echo 'MySql or Mariadb is not installed ...'
    exit 120
fi

ss -lt|grep mysql &> /dev/null
if [ $? -ne 0 ];then
    echo 'mysql not started ...'
    exit 121
fi

which git &> /dev/null
if [ $? -ne 0 ];then
    echo 'will install git ...'
    sleep 1
    yum install git -y 
fi


read -p "PACKAGE=[${_PACKAGE}]: " package
read -p "ADMIN_PASSWD=[${_ADMIN_PASSWD}]: " admin_passwd
read -p "RUN_USER=[${_RUN_USER}]: " run_user

[ -n "$run_user" ] && RUN_USER=$run_user || RUN_USER=$_RUN_USER
id ${RUN_USER} &> /dev/null || useradd ${RUN_USER} -m

read -p "USER_PASSWD=[${_USER_PASSWD}]: " user_passwd
read -p "DB_ADMIN=[${_DB_ADMIN}]: " db_admin
read -p "INSTALL_DIR=[/home/${RUN_USER}]: " install_dir
read -p "IP=[${_IP}]: " ip
read -p "WEB_PORT=[${_WEB_PORT}]: " web_port
read -p "DB_PORT=[${_DB_PORT}]: " db_port
read -p "APP_NAME=[${_APP_NAME}]: " app_name
[ -n "$package" ] && PACKAGE=$package || PACKAGE=$_PACKAGE
[ -n "$admin_passwd" ] && ADMIN_PASSWD=$admin_passwd || ADMIN_PASSWD=$_ADMIN_PASSWD
[ -n "$user_passwd" ] && USER_PASSWD=$user_passwd || USER_PASSWD=$_USER_PASSWD
[ -n "$db_admin" ] && DB_ADMIN=$db_admin || DB_ADMIN=$_DB_ADMIN
[ -n "$install_dir" ] &&  INSTALL_DIR=${install_dir} || INSTALL_DIR=/home/${RUN_USER}
[ -n "$ip" ] && IP=$ip || IP=$_IP
[ -n "$web_port" ] && WEB_PORT=$web_port || WEB_PORT=$_WEB_PORT
[ -n "$db_port" ] && DB_PORT=$db_port || DB_PORT=$_DB_PORT
[ -n "$app_name" ] && APP_NAME=$app_name || APP_NAME=$_APP_NAME

mkdir -p ${INSTALL_DIR} && chown -R ${RUN_USER}.${RUN_USER} ${INSTALL_DIR}

install() {
	tar xf ${PACKAGE} -C ${INSTALL_DIR}/ && \
	mysql -u ${DB_ADMIN} -p${ADMIN_PASSWD}< ${INSTALL_DIR}/gogs/scripts/mysql.sql && \
	mysql -u ${DB_ADMIN} -p${ADMIN_PASSWD} -e "grant all on gogs.* to 'gogs'@'%' identified by \"${USER_PASSWD}\"" && \
	mkdir -p ${INSTALL_DIR}/gogs/custom/conf && \
	cat > ${INSTALL_DIR}/gogs/custom/conf/app.ini <<-EOF
	APP_NAME = ${APP_NAME}
	RUN_USER = ${RUN_USER}
	RUN_MODE = dev
	
	[server]
	HTTP_ADDR = ${IP}
	HTTP_PORT = ${WEB_PORT}
	
	[database]
	DB_TYPE = mysql
	HOST = ${IP}:${DB_PORT}
	NAME = gogs
	USER = gogs
	PASSWD = gogs
	
	[security]
	INSTALL_LOCK = false
	SECRET_KEY = jiubugaosuni
	EOF

	chown -R ${RUN_USER}.${RUN_USER} ${INSTALL_DIR} || exit 112
}


finish() {
	echo "========== please use command follwing to start gogs============"
	echo "sudo -u ${RUN_USER} ${INSTALL_DIR}/gogs/gogs web &"
	
	echo "========== after start gogs, please input URL following to finish install============"
	echo "http://${IP}:${WEB_PORT}"

	echo -e "\033[31m======== you should better disable the option [Gravatar] while install on browser\n\t\totherwise log in will be very slowly =========\033[0m"
}

main() {
	install
	finish
}
main
posted @ 2019-03-03 21:10  scm1911  阅读(229)  评论(0)    收藏  举报
/** ####################################################################### */