Skip to content

Commit

Permalink
Merge pull request #200 from Gid733/master
Browse files Browse the repository at this point in the history
Updated linux installation script
  • Loading branch information
renemadsen authored Jan 11, 2019
2 parents 76bf28d + 6a5cc73 commit afcb121
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 53 deletions.
14 changes: 14 additions & 0 deletions docs/Linux/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ Configuration wizard ask you a 4 parameters to setup
* Defines on which port application will be available
* __Default value__: 80

Script can be launched with key parameters:
```
sudo ./install.sh --port=80 --hostname=example.org --launch-env=Production --username=user --ssl --silent
```

```BASH
--port= - Defines on which port application will be available
--hostname= - Hostname that NGINX should use as route to webapp
--launch-env= -Which launching environment should use dotnet
--username= - Non-root username who launched that script
--ssl - Setup SSL
--silent - enables non-interactive installation mode
```

## Installation process

All installation process is automated, after installation eFrom application will be available on host and port that you specified in configuration
Expand Down
209 changes: 156 additions & 53 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,60 @@
#! /bin/bash

## Parameters parsing
for i in "$@"
do
case $i in
-s|--silent)
NODIALOG=1
shift
;;
-p=*|--port=*)
PORT="${i#*=}"
shift
;;
-h=*|--hostname=*)
SERVERNAME="${i#*=}"
shift
;;
-e=*|--launch-env=*)
ASPENV="${i#*=}"
shift
;;
-u=*|--username=*)
CURENTUSER="${i#*=}"
shift
;;
--ssl)
SSL="y"
shift
;;
*)
# unknown option
;;
esac
done

# Defaults

if [[ -z "$PORT" ]]; then
PORT=80
fi

if [[ -z "$ASPENV" ]]; then
ASPENV="Production"
fi

if [[ -z "$SSL" ]]; then
SSL="n"
fi


dialog_progress() {
echo "$1" | dialog --guage "$2" 10 70 0
if [[ -z "$NODIALOG" ]]; then
echo "$1" | dialog --guage "$2" 10 70 0
else
echo "[$1%] Installing: $2 "
fi
}

install_node() {
Expand All @@ -11,18 +64,18 @@ install_node() {
}

adding_mircosoft_cert() {
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
wget -q https://packages.microsoft.com/config/ubuntu/18.04/prod.list
mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
chown root:root /etc/apt/sources.list.d/microsoft-prod.list
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
wget -q https://packages.microsoft.com/config/ubuntu/18.04/prod.list
mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
chown root:root /etc/apt/sources.list.d/microsoft-prod.list
}

install_dotnetcore() {
apt install -y apt-transport-https &&\
apt update &&\
apt install -y aspnetcore-runtime-2.1 dotnet-sdk-2.1
apt install -y dotnet-runtime-2.2 dotnet-sdk-2.2
}

setup_nginx_conf() {
Expand Down Expand Up @@ -68,27 +121,19 @@ preparing_backend() {
su $CURENTUSER -c \
"npm i && npm run build"

#dialog_progress 70 "Building Web API"

cd ../eFormAPI/eFormAPI.Web/
su $CURENTUSER -c \
"dotnet publish -o out"
mkdir -p /opt/www/aspnetcore/eform-app
mkdir -p /out/www/aspnetcore/eform-app/wwwroot

#dialog_progress 80 "Copy WebAPI to /opt"

rsync -aP out/* /opt/www/aspnetcore/eform-app

#dialog_progress 85 "Copy Web Dashboard to /opt"

cd ../../
cd eform-client
rsync -aP dist/* /opt/www/aspnetcore/eform-app/wwwroot
chown -R www-data:www-data /opt/www

#dialog_progress 85 "Register eForm service in systemctl"

cat > /etc/systemd/system/eform.service << EndOfUnitFile
[Unit]
Description=eForm application
Expand All @@ -107,47 +152,97 @@ WantedBy=multi-user.target
EndOfUnitFile
}

setup_ssl() {
add-apt-repository -y ppa:certbot/certbot >> logfile 2>> errlog
apt update >> logfile 2>> errlog &&\
apt install -y python-certbot-nginx >> logfile 2>> errlog
certbot --nginx -d $SERVERNAME --redirect --register-unsafely-without-email --agree-tos --non-interactive >> logfile 2>> errlog
if [[ $? != 0 ]]; then
showerror "SSL installing failed"
fi
}

dialog_form() {
## Install dialog framework
apt update && apt install -y dialog

exec 3>&1
PARAMS=$(dialog --ok-label "Install" \
--backtitle "Microting eForm setup wizard" \
--title "Configuration" \
--form "Define installation parameters for eForm installer" 15 80 0 \
"Username(Required):" 1 1 "$CURENTUSER" 1 20 40 0 \
"hostname(optional):" 2 1 "$SERVERNAME" 2 20 40 0 \
"Launch environment:" 3 1 "$ASPENV" 3 20 40 0 \
"Port:" 4 1 "$PORT" 4 20 40 0 \
"SSL(y/n):" 5 1 "$SSL" 5 20 40 0 \
2>&1 1>&3)

if [[ $? != 0 ]];
then
exit 0; # Cancel button pressed
fi

exec 3>&-

ARRAY=($PARAMS)

if [[ ${#ARRAY[@]} < 4 ]]; then
showerror "Not all required fields filed!"
exit 1
fi

if [[ ${#ARRAY[@]} == 4 ]]; then
CURENTUSER=${ARRAY[0,0]}
SERVERNAME=""
ASPENV=${ARRAY[0,1]}
PORT=${ARRAY[0,2]}
SSL=${ARRAY[0,3]}
else
CURENTUSER=${ARRAY[0,0]}
SERVERNAME=${ARRAY[0,1]}
ASPENV=${ARRAY[0,2]}
PORT=${ARRAY[0,3]}
SSL=${ARRAY[0,4]}
fi
}

showerror() {
if [[ -z "$NODIALOG" ]]; then
dialog --title "Error" --msgbox "'$1'" 10 50
exit 1
else
echo "Error: $1"
exit 1
fi
}

## INIT
if [[ $EUID -ne 0 ]]; then
echo "Run this script via sudo"
echo "Error: Run this script via sudo"
exit 1
fi

## Install dialog framework
apt update && apt install -y dialog

exec 3>&1
PARAMS=$(dialog --ok-label "Install" \
--backtitle "Microting eForm setup wizard" \
--title "Configuration" \
--form "Define installation parameters for eForm installer" 15 80 0 \
"Username(Required):" 1 1 "" 1 20 40 0 \
"hostname(optional):" 2 1 "" 2 20 40 0 \
"Launch environment:" 3 1 "Production" 3 20 40 0 \
"Port:" 4 1 "80" 4 20 40 0 \
2>&1 1>&3)
exec 3>&-

ARRAY=($PARAMS)

if [[ ${#ARRAY[@]} < 3 ]]; then
dialog --title "Error" --msgbox 'Not all required fields filed!' 6 20
exit 1
fi
# Windows CMD.exe dialog fix
export NCURSES_NO_UTF8_ACS=1

if [[ ${#ARRAY[@]} == 3 ]]; then
CURENTUSER=${ARRAY[0,0]}
SERVERNAME=""
ASPENV=${ARRAY[0,1]}
PORT=${ARRAY[0,2]}
## Dialog/cmd params wizard switch
if [[ -z "$NODIALOG" ]]; then
dialog_form
else
CURENTUSER=${ARRAY[0,0]}
SERVERNAME=${ARRAY[0,1]}
ASPENV=${ARRAY[0,2]}
PORT=${ARRAY[0,3]}
echo "non-interactive installing started!"
fi

# Last validations
if [[ ( -z "$SERVERNAME" ) && ( "$SSL" == "y" ) ]]; then
showerror "SSL require servername specified!"
fi

if [[ -z "$CURENTUSER" ]]; then
showerror "Username not specified!"
fi

## Installing
## Installing scenario

dialog_progress 0 "Installing nodejs"
install_node >> logfile 2>> errlog
Expand All @@ -163,18 +258,23 @@ dialog_progress 25 "Installing NGINX"
apt install -y nginx >> logfile 2>> errlog

dialog_progress 30 "Setting default host at default config"
setup_nginx_conf
setup_nginx_conf >> logfile 2>> errlog

dialog_progress 40 "Reloading nginx"
nginx -s reload >> logfile 2>> errlog

dialog_progress 50 "Cloning project"
su $CURENTUSER -c \
"git clone https://github.com/microting/eform-angular-frontend.git -b netcore" > logfile 2> errlog
"git clone https://github.com/microting/eform-angular-frontend.git -b master" > logfile 2> errlog

dialog_progress 60 "Preparing WEB dashboard"
preparing_backend >> logfile 2>> errlog

if [[ "$SSL" == "y" ]]; then
dialog_progress 75 "Installing LetsEncrypt"
setup_ssl
fi

dialog_progress 90 "Starting eForm"
systemctl daemon-reload >> logfile 2>> errlog
systemctl enable eform.service >> logfile 2>> errlog
Expand All @@ -184,7 +284,10 @@ dialog_progress 100 "Cleanup"
cd ../../
rm -rf eform-angular-frontend >> logfile 2>> errlog

clear
dialog --title "Ready" --msgbox 'eForms installed! Check logfile and errorfile if something wrong' 6 20
if [[ -z "$NODIALOG" ]]; then
dialog --title "Ready" --msgbox 'eForms installed! Check logfile and errorfile if something wrong' 6 20
else
echo "eForms installed! Check logfile and errorfile if something wrong"
fi

clear
exit 0

0 comments on commit afcb121

Please sign in to comment.