websoft9/scripts/install.sh

80 lines
2.4 KiB
Bash
Raw Normal View History

2022-07-14 01:27:59 +00:00
#!/bin/bash
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
clear
# Check if user is root
[ $(id -u) != "0" ] && { echo "Error: You must be root to run this script, please use 'sudo su -' command to change root"; exit 1; }
version(){
echo "version: 0.1"
echo "updated date: 2019-12-30"
}
Show_Help(){
version
echo "Usage: $0 command ...[parameters]...
--help, -h Show this help message
--version, -v Show version info
"
}
echo "Pre-installation is starting, please wait for 1-3 minutes..."
# OracleLinux need install oaclelinux-developer-release-e* oracle-nodejs-release-e* oracle-epel-release-e* in Image before this script
if command -v yum > /dev/null; then
2023-04-05 06:55:20 +00:00
2022-07-14 01:27:59 +00:00
sudo yum install -y epel-release 1>/dev/null 2>&1
2023-02-16 01:24:54 +00:00
sudo yum install yum-utils git libselinux-python python python3 -y 1>/dev/null 2>&1
2022-07-14 01:27:59 +00:00
sudo python3 -m pip install -U --force-reinstall requests docker 1>/dev/null 2>&1
if command -v amazon-linux-extras > /dev/null; then
echo "amazon-linux-extras install ansible2"
sudo amazon-linux-extras install ansible2
else
echo "yum install ansible"
sudo yum install ansible sshpass -y 1>/dev/null 2>&1
fi
fi
if command -v apt > /dev/null; then
sudo apt-get install git python python3 git -y 1>/dev/null 2>&1
sudo apt install software-properties-common -y 1>/dev/null 2>&1
if [[ $(cat /etc/os-release |grep VERSION_CODENAME |cut -d= -f2) == focal ]];then
2022-08-16 03:18:40 +00:00
echo "have ansible pkg"
2022-07-14 01:27:59 +00:00
elif [[ $(cat /etc/os-release |grep VERSION_CODENAME |cut -d= -f2) == bionic ]];then
sudo apt-add-repository --yes --update ppa:ansible/ansible
fi
sudo apt install ansible sshpass -y
fi
2022-08-16 03:18:40 +00:00
2022-07-14 01:27:59 +00:00
sudo echo "Pre-installation has beend completed"
2023-02-27 09:41:03 +00:00
# r:repository; i:init
while getopts ":r:"":i:" opt
do
case $opt in
r)
repo_name=$OPTARG;;
i)
repo_init=$OPTARG
;;
?)
echo "no repository"
exit 1;;
esac
done
echo $repo_name
echo $repo_init
2022-07-14 01:27:59 +00:00
cd /tmp
2023-04-17 07:14:27 +00:00
rm -rf StackHub
2023-04-17 06:45:57 +00:00
wget -N https://websoft9.github.io/StackHub/scripts/githubclone.sh && bash githubclone.sh websoft9 StackHub
2023-04-17 07:00:39 +00:00
cd StackHub/apps
2022-08-16 03:18:40 +00:00
sudo echo "localhost" > hosts
2022-08-16 03:26:58 +00:00
ansible-playbook -i hosts application.yml -c local -e init=$repo_init -e appname=$repo_name
2022-09-01 06:22:27 +00:00
if [ $repo_init -ne 0 ]; then
2022-09-01 05:59:36 +00:00
echo "Image build success!"
2022-08-16 07:18:30 +00:00
else
echo "System must restart after 2s, then installation completed"; sleep 2 ; sudo reboot
2022-08-16 06:19:46 +00:00
fi