2020-07-10 13:48:42 +00:00
#!/bin/bash
2020-08-20 04:52:22 +00:00
2020-07-10 13:48:42 +00:00
set -o errexit
is_command_present( ) {
2020-09-02 11:12:33 +00:00
type " $1 " >/dev/null 2>& 1
}
is_mac( ) {
[ [ $OSTYPE = = darwin* ] ]
2020-07-10 13:48:42 +00:00
}
2020-08-20 04:52:22 +00:00
# This function checks if the relevant ports required by Appsmith are available or not
# The script should error out in case they aren't available
2020-08-03 15:02:54 +00:00
check_ports_occupied( ) {
2020-09-02 11:12:33 +00:00
local port_check_output
local ports_pattern = "80|443"
if is_mac; then
port_check_output = " $( netstat -anp tcp | awk '$6 == "LISTEN" && $4 ~ /^.*\.(' " $ports_pattern " ')$/' ) "
elif is_command_present ss; then
# The `ss` command seems to be a better/faster version of `netstat`, but is not available on all Linux
# distributions by default. Other distributions have `ss` but no `netstat`. So, we try for `ss` first, then
# fallback to `netstat`.
port_check_output = " $( ss --all --numeric --tcp | awk '$1 == "LISTEN" && $4 ~ /^.*:(' " $ports_pattern " ')$/' ) "
elif is_command_present netstat; then
port_check_output = " $( netstat --all --numeric --tcp | awk '$6 == "LISTEN" && $4 ~ /^.*:(' " $ports_pattern " ')$/' ) "
fi
if [ [ -n $port_check_output ] ] ; then
2020-10-27 14:31:30 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2020-10-27 14:31:30 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "Installation Error" ,
"data" : {
"os" : "'" $os "'" ,
"error" : "port taken"
}
} ' > /dev/null
2020-09-02 11:12:33 +00:00
echo "+++++++++++ ERROR ++++++++++++++++++++++"
echo "Appsmith requires ports 80 & 443 to be open. Please shut down any other service(s) that may be running on these ports."
2021-02-04 10:17:06 +00:00
echo "You can run appsmith on another port following this guide https://docs.appsmith.com/v/v1.2.1/troubleshooting-guide/deployment-errors"
2020-09-02 11:12:33 +00:00
echo "++++++++++++++++++++++++++++++++++++++++"
echo ""
2020-10-29 06:34:43 +00:00
exit 1
2020-09-02 11:12:33 +00:00
fi
2020-08-03 15:02:54 +00:00
}
2020-07-10 13:48:42 +00:00
install_docker( ) {
2020-09-02 11:12:33 +00:00
echo "++++++++++++++++++++++++"
echo "Setting up docker repos"
2020-07-10 13:48:42 +00:00
2020-09-02 11:12:33 +00:00
if [ [ $package_manager = = apt-get ] ] ; then
apt_cmd = "sudo apt-get --yes --quiet"
$apt_cmd update
2020-10-16 05:27:16 +00:00
$apt_cmd install software-properties-common gnupg-agent
curl -fsSL " https://download.docker.com/linux/ $os /gpg " | sudo apt-key add -
2020-07-10 13:48:42 +00:00
sudo add-apt-repository \
2020-10-16 05:27:16 +00:00
" deb [arch=amd64] https://download.docker.com/linux/ $os $( lsb_release -cs) stable "
2020-09-02 11:12:33 +00:00
$apt_cmd update
echo "Installing docker"
$apt_cmd install docker-ce docker-ce-cli containerd.io
2021-04-27 15:13:22 +00:00
2020-10-27 05:14:03 +00:00
elif [ [ $package_manager = = zypper ] ] ; then
zypper_cmd = "sudo zypper --quiet --no-gpg-checks --non-interactive"
echo "Installing docker"
if [ [ $os = = sles ] ] ; then
os_sp = " $( cat /etc/*-release | awk -F= '$1 == "VERSION_ID" { gsub(/"/, ""); print $2; exit }' ) "
os_arch = " $( uname -i) "
2021-04-27 15:13:22 +00:00
sudo SUSEConnect -p " sle-module-containers/ $os_sp / $os_arch " -r ''
2020-10-27 05:14:03 +00:00
fi
$zypper_cmd install docker docker-runc containerd
2021-01-22 09:48:12 +00:00
sudo systemctl enable docker.service
2021-04-27 15:13:22 +00:00
2020-07-10 13:48:42 +00:00
else
2020-09-02 11:12:33 +00:00
yum_cmd = "sudo yum --assumeyes --quiet"
$yum_cmd install yum-utils
2021-07-22 09:57:34 +00:00
os_in_repo_link = " $os "
if [ [ $os = = rhel ] ] ; then
# For RHEL, there's no separate repo link. We can use the CentOS one though.
os_in_repo_link = centos
fi
sudo yum-config-manager --add-repo " https://download.docker.com/linux/ $os_in_repo_link /docker-ce.repo "
2020-09-02 11:12:33 +00:00
echo "Installing docker"
$yum_cmd install docker-ce docker-ce-cli containerd.io
2020-07-10 13:48:42 +00:00
fi
2020-08-16 12:06:34 +00:00
}
2020-07-10 13:48:42 +00:00
2020-08-16 12:06:34 +00:00
install_docker_compose( ) {
2020-10-27 05:14:03 +00:00
if [ [ $package_manager = = "apt-get" || $package_manager = = "zypper" || $package_manager = = "yum" ] ] ; then
2020-09-02 11:12:33 +00:00
if [ [ ! -f /usr/bin/docker-compose ] ] ; then
2020-10-16 05:27:16 +00:00
echo "++++++++++++++++++++++++"
echo "Installing docker-compose"
2020-08-16 12:06:34 +00:00
sudo curl -L " https://github.com/docker/compose/releases/download/1.26.0/docker-compose- $( uname -s) - $( uname -m) " -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
echo "docker-compose installed!"
2020-08-20 04:52:22 +00:00
echo ""
2020-08-16 12:06:34 +00:00
fi
else
2020-10-27 14:31:30 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2020-10-27 14:31:30 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "Installation Error" ,
"data" : {
"os" : "'" $os "'" ,
"error" : "Docker Compose Not Found"
}
} ' > /dev/null
2020-08-16 12:06:34 +00:00
echo "+++++++++++ IMPORTANT READ ++++++++++++++++++++++"
echo "docker-compose not found! Please install docker-compose first and then continue with this installation."
echo "Refer https://docs.docker.com/compose/install/ for installing docker-compose."
echo "+++++++++++++++++++++++++++++++++++++++++++++++++"
2020-10-29 06:34:43 +00:00
exit 1
2020-08-16 12:06:34 +00:00
fi
2020-07-13 10:30:53 +00:00
}
start_docker( ) {
2020-08-20 04:52:22 +00:00
if ! sudo systemctl is-active docker.service > /dev/null; then
echo "Starting docker service"
sudo systemctl start docker.service
2020-07-13 10:30:53 +00:00
fi
2020-07-10 13:48:42 +00:00
}
2020-07-16 06:17:45 +00:00
check_os( ) {
2020-09-02 11:12:33 +00:00
if is_mac; then
2020-07-16 06:17:45 +00:00
package_manager = "brew"
desired_os = 1
2021-04-27 15:13:22 +00:00
os = "mac"
2020-07-16 06:17:45 +00:00
return
fi
2021-04-27 15:13:22 +00:00
local os_name = " $(
cat /etc/*-release \
| awk -F= '$1 == "NAME" { gsub(/"/, ""); print $2; exit }' \
| tr '[:upper:]' '[:lower:]'
) "
2020-08-03 15:02:54 +00:00
2020-09-02 11:12:33 +00:00
case " $os_name " in
2021-04-27 15:13:22 +00:00
ubuntu*)
2020-07-16 06:17:45 +00:00
desired_os = 1
2020-10-16 05:27:16 +00:00
os = "ubuntu"
package_manager = "apt-get"
; ;
2021-04-27 15:13:22 +00:00
debian*)
2020-10-16 05:27:16 +00:00
desired_os = 1
os = "debian"
2020-07-16 06:17:45 +00:00
package_manager = "apt-get"
; ;
2021-04-27 15:13:22 +00:00
linux\ mint*)
2021-01-25 07:55:10 +00:00
desired_os = 1
os = "linux mint"
package_manager = "apt-get"
; ;
2021-04-27 15:13:22 +00:00
red\ hat*)
2020-09-02 11:12:33 +00:00
desired_os = 1
2021-07-14 14:28:49 +00:00
os = "rhel"
2020-07-16 06:17:45 +00:00
package_manager = "yum"
; ;
2021-04-27 15:13:22 +00:00
centos*)
2020-09-02 11:12:33 +00:00
desired_os = 1
2020-10-16 05:27:16 +00:00
os = "centos"
2020-07-16 06:17:45 +00:00
package_manager = "yum"
; ;
2021-04-27 15:13:22 +00:00
sles*)
2020-10-27 05:14:03 +00:00
desired_os = 1
os = "sles"
package_manager = "zypper"
; ;
2021-04-27 15:13:22 +00:00
opensuse*)
2020-10-27 05:14:03 +00:00
desired_os = 1
os = "opensuse"
package_manager = "zypper"
; ;
2020-09-02 11:12:33 +00:00
*)
desired_os = 0
2021-04-27 15:13:22 +00:00
os = " Not Found: $os_name "
2020-07-16 06:17:45 +00:00
esac
}
overwrite_file( ) {
2020-08-20 04:52:22 +00:00
local relative_path = " $1 "
local template_file = " $2 "
local full_path = " $install_dir / $relative_path "
2020-07-16 06:17:45 +00:00
2020-09-02 11:12:33 +00:00
if [ [ -f $full_path ] ] && ! confirm y " File $relative_path already exists. Would you like to replace it? " ; then
echo " You chose NOT to replace existing file: ' $full_path '. "
rm -f " $template_file "
echo " File $template_file removed from source directory. "
echo ""
2020-07-16 06:17:45 +00:00
else
2020-08-20 04:52:22 +00:00
mv -f " $template_file " " $full_path "
2020-07-16 06:17:45 +00:00
fi
}
2021-01-22 09:48:12 +00:00
# This function prompts the user for an input for a non-empty Mongo root password.
2020-08-14 05:52:15 +00:00
read_mongo_password( ) {
2020-09-02 11:12:33 +00:00
read -srp 'Set the mongo password: ' mongo_root_password
while [ [ -z $mongo_root_password ] ] ; do
2020-08-14 05:52:15 +00:00
echo ""
echo ""
echo "+++++++++++ ERROR ++++++++++++++++++++++"
echo "The mongo password cannot be empty. Please input a valid password string."
echo "++++++++++++++++++++++++++++++++++++++++"
echo ""
2020-09-02 11:12:33 +00:00
read -srp 'Set the mongo password: ' mongo_root_password
2021-01-22 09:48:12 +00:00
done
2020-08-14 05:52:15 +00:00
}
2021-01-22 09:48:12 +00:00
# This function prompts the user for an input for a non-empty Mongo username.
2020-08-14 05:52:15 +00:00
read_mongo_username( ) {
2020-09-02 11:12:33 +00:00
read -rp 'Set the mongo root user: ' mongo_root_user
while [ [ -z $mongo_root_user ] ] ; do
2020-08-14 05:52:15 +00:00
echo ""
echo "+++++++++++ ERROR ++++++++++++++++++++++"
echo "The mongo username cannot be empty. Please input a valid username string."
echo "++++++++++++++++++++++++++++++++++++++++"
echo ""
2020-09-02 11:12:33 +00:00
read -rp 'Set the mongo root user: ' mongo_root_user
2020-08-20 04:52:22 +00:00
done
2020-08-14 05:52:15 +00:00
}
wait_for_containers_start( ) {
2020-08-20 04:52:22 +00:00
local timeout = $1
# The while loop is important because for-loops don't work for dynamic values
while [ [ $timeout -gt 0 ] ] ; do
status_code = " $( curl -s -o /dev/null -w "%{http_code}" http://localhost/api/v1 || true ) "
2020-08-14 05:52:15 +00:00
if [ [ status_code -eq 401 ] ] ; then
break
else
2020-08-20 04:52:22 +00:00
echo -ne " Waiting for all containers to start. This check will timeout in $timeout seconds...\r\c "
2020-08-14 05:52:15 +00:00
fi
2020-08-20 04:52:22 +00:00
( ( timeout--) )
2020-08-14 05:52:15 +00:00
sleep 1
done
2020-08-20 04:52:22 +00:00
echo ""
2020-08-14 05:52:15 +00:00
}
2020-08-17 05:40:01 +00:00
urlencode( ) {
# urlencode <string>
2020-09-02 11:12:33 +00:00
local old_lc_collate = " $LC_COLLATE "
2020-08-17 05:40:01 +00:00
LC_COLLATE = C
local length = " ${# 1 } "
for ( ( i = 0; i < length; i++ ) ) ; do
local c = " ${ 1 : i : 1 } "
case $c in
[ a-zA-Z0-9.~_-] ) printf " $c " ; ;
*) printf '%%%02X' " ' $c " ; ;
esac
done
2020-09-02 11:12:33 +00:00
LC_COLLATE = " $old_lc_collate "
}
generate_password( ) {
2021-02-16 06:53:53 +00:00
local gen_string = " $( /usr/bin/python -c 'import random, string; print("".join(random.choice(string.ascii_letters + string.digits) for _ in range(13)))' 2>/dev/null) "
if [ [ -n $gen_string ] ] ; then
echo " $gen_string "
else
# Picked up the following method of generation from : https://gist.github.com/earthgecko/3089509
LC_ALL = C tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 13 | head -n 1
fi
2020-09-02 11:12:33 +00:00
}
confirm( ) {
local default = " $1 " # Should be `y` or `n`.
local prompt = " $2 "
local options = "y/N"
if [ [ $default = = y || $default = = Y ] ] ; then
options = "Y/n"
fi
local answer
2020-09-16 12:38:53 +00:00
read -rp " $prompt [ $options ] " answer
2020-09-02 11:12:33 +00:00
if [ [ -z $answer ] ] ; then
# No answer given, the user just hit the Enter key. Take the default value as the answer.
answer = " $default "
else
# An answer was given. This means the user didn't get to hit Enter so the cursor on the same line. Do an empty
# echo so the cursor moves to a new line.
echo
fi
[ [ yY = ~ $answer ] ]
}
2020-09-03 12:34:58 +00:00
init_ssl_cert( ) {
local domain = " $1 "
echo " Creating certificate for ' $domain '. "
local rsa_key_size = 4096
local data_path = "./data/certbot"
if [ [ -d " $data_path " ] ] ; then
if ! confirm n " Existing certificate data found at ' $data_path '. Continue and replace existing certificate? " ; then
return
fi
fi
mkdir -p " $data_path " /{ conf,www}
if ! [ [ -e " $data_path /conf/options-ssl-nginx.conf " && -e " $data_path /conf/ssl-dhparams.pem " ] ] ; then
echo "### Downloading recommended TLS parameters..."
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf > " $data_path /conf/options-ssl-nginx.conf "
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem > " $data_path /conf/ssl-dhparams.pem "
echo
fi
echo " ### Requesting Let's Encrypt certificate for ' $domain '... "
local email
read -rp 'Enter email address to create SSL certificate: (Optional, but strongly recommended): ' email
if [ [ -z $email ] ] ; then
local email_arg = "--register-unsafely-without-email"
else
local email_arg = " --email $email --no-eff-email "
fi
if confirm n 'Do you want to create certificate in staging mode (which is used for dev purposes and is not subject to rate limits)?' ; then
local staging_arg = "--staging"
else
local staging_arg = ""
fi
echo " ### Generating OpenSSL key for ' $domain '... "
local live_path = " /etc/letsencrypt/live/ $domain "
certbot_cmd \
" sh -c \"mkdir -p ' $live_path ' && openssl req -x509 -nodes -newkey rsa:1024 -days 1 \
-keyout '$live_path/privkey.pem' \
-out '$live_path/fullchain.pem' \
-subj '/CN=localhost' \
\" "
echo
echo "### Starting nginx..."
sudo docker-compose up --force-recreate --detach nginx
echo
echo " ### Removing key now that validation is done for $domain ... "
certbot_cmd \
" rm -Rfv /etc/letsencrypt/live/ $domain /etc/letsencrypt/archive/ $domain /etc/letsencrypt/renewal/ $domain .conf "
echo
# The following command exits with a non-zero status code even if the certificate was generated, but some checks failed.
# So we explicitly ignore such failure with a `|| true` in the end, to avoid bash quitting on us because this looks like
# a failed command.
certbot_cmd " certbot certonly --webroot --webroot-path=/var/www/certbot \
$staging_arg \
$email_arg \
--domains $domain \
--rsa-key-size $rsa_key_size \
--agree-tos \
--force-renewal" \
|| true
echo
echo "### Reloading nginx..."
sudo docker-compose exec nginx nginx -s reload
}
certbot_cmd( ) {
sudo docker-compose run --rm --entrypoint " $1 " certbot
}
2020-09-02 11:12:33 +00:00
echo_contact_support( ) {
echo " Please contact <support@appsmith.com> with your OS details and version ${ 1 :- . } "
2020-08-17 05:40:01 +00:00
}
2020-08-20 04:52:22 +00:00
bye( ) { # Prints a friendly good bye message and exits the script.
2020-10-29 06:34:43 +00:00
if [ " $? " -ne 0 ] ; then
set +o errexit
echo "Please share your email if you wish to receive support with the installation"
read -rp 'Email: ' email
2020-10-16 05:27:16 +00:00
2020-10-29 06:34:43 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2020-10-29 06:34:43 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "Installation Support" ,
"data" : {
"os" : "'" $os "'" ,
"email" : "'" $email "'"
}
} ' > /dev/null
echo ""
echo -e "\nWe will reach out to you at the email provided shortly, Exiting for now. Bye! 👋 \n"
exit 0
fi
2020-08-20 04:52:22 +00:00
}
2020-11-11 18:24:19 +00:00
ask_telemetry( ) {
echo ""
echo "+++++++++++ IMPORTANT ++++++++++++++++++++++"
echo -e "Thank you for installing appsmith! We want to be transparent and request that you share anonymous usage data with us."
echo -e "This data is purely statistical in nature and helps us understand your needs & provide better support to your self-hosted instance."
2021-02-03 15:15:16 +00:00
echo -e "You can read more about what information is collected in our documentation https://docs.appsmith.com/v/v1.2.1/setup/telemetry"
2020-11-11 18:24:19 +00:00
echo -e ""
if confirm y 'Would you like to share anonymous usage data and receive better support?' ; then
disable_telemetry = "false"
else
disable_telemetry = "true"
2021-01-22 09:48:12 +00:00
echo "Please note that even though telemetry is disabled, your Appsmith server will connect to cloud to fetch release notes and to check for updates."
2020-11-11 18:24:19 +00:00
fi
echo "++++++++++++++++++++++++++++++++++++++++++++"
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2020-11-11 18:24:19 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "Installation Telemetry" ,
"data" : {
"disable-telemetry" : "'" $disable_telemetry "'"
}
} ' > /dev/null
}
2020-10-16 05:27:16 +00:00
echo -e "👋 Thank you for trying out Appsmith! "
2020-07-10 13:48:42 +00:00
echo ""
2020-08-20 04:52:22 +00:00
# Checking OS and assigning package manager
2020-07-10 13:48:42 +00:00
desired_os = 0
2020-09-16 10:30:27 +00:00
os = ""
2020-10-16 05:27:16 +00:00
echo -e "🕵️ Detecting your OS"
2020-07-16 06:17:45 +00:00
check_os
2020-10-16 05:27:16 +00:00
2020-10-03 07:05:49 +00:00
APPSMITH_INSTALLATION_ID = $( curl -s 'https://api64.ipify.org' )
2020-07-10 13:48:42 +00:00
2020-09-21 13:35:58 +00:00
# Run bye if failure happens
trap bye EXIT
2020-10-16 05:27:16 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
2020-09-16 09:57:44 +00:00
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2020-09-16 14:21:02 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
2020-09-07 16:53:24 +00:00
"event" : "Installation Started" ,
2020-09-16 09:57:44 +00:00
"data" : {
2021-03-16 07:55:37 +00:00
"os" : "'" $os "'" ,
2021-03-16 08:34:22 +00:00
"platform" : "docker"
2020-09-16 09:57:44 +00:00
}
2020-10-16 05:27:16 +00:00
} ' > /dev/null
2020-09-07 16:53:24 +00:00
2020-07-10 13:48:42 +00:00
if [ [ $desired_os -eq 0 ] ] ; then
2020-08-20 04:52:22 +00:00
echo ""
2021-01-25 07:55:10 +00:00
echo "This script is currently meant to install Appsmith on Mac OS X, Ubuntu, Debian, Linux Mint, Red Hat, CentOS, SLES or openSUSE machines."
2020-09-02 11:12:33 +00:00
echo_contact_support " if you wish to extend this support."
2020-10-27 14:31:30 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2020-10-27 14:31:30 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "Installation Error" ,
"data" : {
"os" : "'" $os "'" ,
"error" : "OS Not Supported"
}
} ' > /dev/null
2020-10-29 06:34:43 +00:00
exit 1
2020-08-20 04:52:22 +00:00
else
2021-03-16 07:55:37 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2021-03-16 07:55:37 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "OS Check Passed" ,
"data" : {
"os" : "'" $os "'" ,
2021-03-16 08:34:22 +00:00
"platform" : "docker"
2021-03-16 07:55:37 +00:00
}
} ' > /dev/null
2020-10-16 05:27:16 +00:00
echo "🙌 You're on an OS that is supported by this installation script."
2020-08-20 04:52:22 +00:00
echo ""
fi
2020-09-02 11:12:33 +00:00
if [ [ $EUID -eq 0 ] ] ; then
2020-10-26 07:02:45 +00:00
echo "+++++++++++ ERROR ++++++++++++++++++++++"
2020-09-02 11:12:33 +00:00
echo "Please do not run this script as root/sudo."
2020-10-26 07:02:45 +00:00
echo "++++++++++++++++++++++++++++++++++++++++"
2020-10-27 14:31:30 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2020-10-27 14:31:30 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "Installation Error" ,
"data" : {
"os" : "'" $os "'" ,
"error" : "Running as Root"
}
} ' > /dev/null
2020-10-29 06:34:43 +00:00
exit 1
2020-07-10 13:48:42 +00:00
fi
2021-03-16 07:55:37 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2021-03-16 07:55:37 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "Root Check Passed" ,
"data" : {
"os" : "'" $os "'" ,
2021-03-16 08:34:22 +00:00
"platform" : "docker"
2021-03-16 07:55:37 +00:00
}
} ' > /dev/null
2020-07-10 13:48:42 +00:00
2020-08-03 15:02:54 +00:00
check_ports_occupied
2021-03-16 07:55:37 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2021-03-16 07:55:37 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "Port Check Passed" ,
"data" : {
"os" : "'" $os "'" ,
2021-03-16 08:34:22 +00:00
"platform" : "docker"
2021-03-16 07:55:37 +00:00
}
} ' > /dev/null
2021-04-26 10:51:54 +00:00
read -rp 'Create an Installation Directory: [appsmith]' install_dir
2020-09-02 11:12:33 +00:00
install_dir = " ${ install_dir :- appsmith } "
if [ [ $install_dir != /* ] ] ; then
# If it's not an absolute path, prepend current working directory to it, to make it an absolute path.
install_dir = " $PWD / $install_dir "
fi
2021-04-29 13:53:17 +00:00
if [ [ -e " $install_dir " && -n " $( ls -A " $install_dir " ) " ] ] ; then
echo " The path ' $install_dir ' is already present and is non-empty. Please run the script again with a different path to install new. "
2020-09-02 11:12:33 +00:00
echo "If you're trying to update your existing installation, that happens automatically through WatchTower."
echo_contact_support " if you're facing problems with the auto-updates."
2020-10-29 06:34:43 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2020-10-29 06:34:43 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "Installation Error" ,
"data" : {
"os" : "'" $os "'" ,
2021-03-16 07:55:37 +00:00
"error" : "Directory Exists" ,
"directory" : "'" $install_dir "'"
2020-10-29 06:34:43 +00:00
}
} ' > /dev/null
exit 1
2020-08-03 15:02:54 +00:00
fi
2021-03-16 07:55:37 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2021-03-16 07:55:37 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "Directory Check Passed" ,
"data" : {
"os" : "'" $os "'" ,
2021-03-16 08:34:22 +00:00
"platform" : "docker"
2021-03-16 07:55:37 +00:00
}
} ' > /dev/null
2020-08-14 05:52:15 +00:00
# Check is Docker daemon is installed and available. If not, the install & start Docker for Linux machines. We cannot automatically install Docker Desktop on Mac OS
2020-09-02 11:12:33 +00:00
if ! is_command_present docker; then
2020-10-27 05:14:03 +00:00
if [ [ $package_manager = = "apt-get" || $package_manager = = "zypper" || $package_manager = = "yum" ] ] ; then
2020-08-14 05:52:15 +00:00
install_docker
else
echo ""
echo "+++++++++++ IMPORTANT READ ++++++++++++++++++++++"
2020-10-27 05:14:03 +00:00
echo "Docker Desktop must be installed manually on Mac OS to proceed. Docker can only be installed automatically on Ubuntu / openSUSE / SLES / Redhat / Cent OS"
2020-08-14 05:52:15 +00:00
echo "https://docs.docker.com/docker-for-mac/install/"
echo "++++++++++++++++++++++++++++++++++++++++++++++++"
2020-10-29 06:34:43 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2020-10-29 06:34:43 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "Installation Error" ,
"data" : {
"os" : "'" $os "'" ,
"error" : "Docker not installed"
}
} ' > /dev/null
2020-09-02 11:12:33 +00:00
exit 1
2020-08-14 05:52:15 +00:00
fi
fi
2021-03-16 07:55:37 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2021-03-16 07:55:37 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "Docker Check Passed" ,
"data" : {
"os" : "'" $os "'" ,
2021-03-16 08:34:22 +00:00
"platform" : "docker"
2021-03-16 07:55:37 +00:00
}
} ' > /dev/null
2020-08-17 11:03:37 +00:00
# Install docker-compose
if ! is_command_present docker-compose; then
install_docker_compose
fi
2020-08-14 05:52:15 +00:00
# Starting docker service
2020-10-27 05:14:03 +00:00
if [ [ $package_manager = = "yum" || $package_manager = = "zypper" || $package_manager = = "apt-get" ] ] ; then
2020-08-14 05:52:15 +00:00
start_docker
fi
2020-09-02 11:12:33 +00:00
echo " Installing Appsmith to ' $install_dir '. "
mkdir -p " $install_dir "
2020-07-16 06:17:45 +00:00
echo ""
2020-07-10 13:48:42 +00:00
2021-02-04 10:16:07 +00:00
if confirm y "Is this a fresh installation?" ; then
2021-03-16 07:55:37 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2021-03-16 07:55:37 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "Fresh Install" ,
"data" : {
"os" : "'" $os "'" ,
2021-03-16 08:34:22 +00:00
"platform" : "docker"
2021-03-16 07:55:37 +00:00
}
} ' > /dev/null
2020-07-10 13:48:42 +00:00
mongo_host = "mongo"
mongo_database = "appsmith"
2020-09-02 11:12:33 +00:00
2020-08-14 05:52:15 +00:00
# We invoke functions to read the mongo credentials from the user because they MUST be non-empty
read_mongo_username
read_mongo_password
2020-07-16 10:21:52 +00:00
# Since the mongo was automatically setup, this must be the first time installation. Generate encryption credentials for this scenario
auto_generate_encryption = "true"
2020-09-02 11:12:33 +00:00
else
2021-02-24 11:49:58 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2021-02-24 11:49:58 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "Existing Installation"
} ' > /dev/null
2020-12-10 10:07:11 +00:00
echo 'You are trying to connect to an existing appsmith database. Abort if you want to install appsmith using the default database'
2020-10-26 17:19:03 +00:00
read -rp 'Enter your existing appsmith mongo db host: ' mongo_host
read -rp 'Enter your existing appsmith mongo root user: ' mongo_root_user
read -srp 'Enter your existing appsmith mongo password: ' mongo_root_password
2021-02-04 10:16:07 +00:00
echo ""
2020-10-26 17:19:03 +00:00
read -rp 'Enter your existing appsmith mongo database name: ' mongo_database
2020-09-02 11:12:33 +00:00
# It is possible that this isn't the first installation.
echo ""
# In this case be more cautious of auto generating the encryption keys. Err on the side of not generating the encryption keys
if confirm y "Do you have any existing data in the database?" ; then
auto_generate_encryption = "false"
else
auto_generate_encryption = "true"
fi
2020-07-10 13:48:42 +00:00
fi
echo ""
2020-07-16 10:21:52 +00:00
2020-08-17 05:40:01 +00:00
# urlencoding the Mongo username and password
2020-09-02 11:12:33 +00:00
encoded_mongo_root_user = $( urlencode " $mongo_root_user " )
encoded_mongo_root_password = $( urlencode " $mongo_root_password " )
2020-08-17 05:40:01 +00:00
2020-07-14 09:15:08 +00:00
encryptionEnv = ./template/encryption.env
if test -f " $encryptionEnv " ; then
echo "CAUTION : This isn't your first time installing appsmith. Encryption password and salt already exist. Do you want to override this? NOTE: Overwriting the existing salt and password would lead to you losing access to sensitive information encrypted using the same"
echo "1) No. Conserve the older encryption password and salt and continue"
2020-07-16 10:21:52 +00:00
echo "2) Yes. Overwrite the existing encryption (NOT SUGGESTED) with autogenerated encryption password and salt"
echo "3) Yes. Overwrite the existing encryption (NOT SUGGESTED) with manually entering the encryption password and salt"
2020-09-02 11:12:33 +00:00
read -rp 'Enter option number [1]: ' overwrite_encryption
2020-07-14 09:15:08 +00:00
overwrite_encryption = ${ overwrite_encryption :- 1 }
2020-07-16 10:21:52 +00:00
auto_generate_encryption = "false"
2020-07-14 09:15:08 +00:00
if [ [ $overwrite_encryption -eq 1 ] ] ; then
setup_encryption = "false"
elif [ [ $overwrite_encryption -eq 2 ] ] ; then
2020-07-16 10:21:52 +00:00
setup_encryption = "true"
2020-09-02 11:12:33 +00:00
auto_generate_encryption = "true"
2020-07-16 10:21:52 +00:00
elif [ [ $overwrite_encryption -eq 3 ] ] ; then
setup_encryption = "true"
auto_generate_encryption = "false"
2020-07-14 09:15:08 +00:00
fi
else
setup_encryption = "true"
fi
if [ [ " $setup_encryption " = "true" ] ] ; then
2020-07-16 10:21:52 +00:00
if [ [ " $auto_generate_encryption " = "false" ] ] ; then
echo "Please enter the salt and password found in the encyption.env file of your previous appsmith installation "
2020-09-02 11:12:33 +00:00
read -rp 'Enter your encryption password: ' user_encryption_password
read -rp 'Enter your encryption salt: ' user_encryption_salt
elif [ [ " $auto_generate_encryption " = "true" ] ] ; then
user_encryption_password = $( generate_password)
user_encryption_salt = $( generate_password)
2020-07-14 09:15:08 +00:00
fi
fi
2020-07-16 10:21:52 +00:00
2020-07-14 09:15:08 +00:00
echo ""
2020-08-03 15:02:54 +00:00
2021-03-16 07:55:37 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2021-03-16 07:55:37 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "Salt Generation Done" ,
"data" : {
"os" : "'" $os "'" ,
2021-03-16 08:34:22 +00:00
"platform" : "docker"
2021-03-16 07:55:37 +00:00
}
} ' > /dev/null
2020-09-02 11:12:33 +00:00
if confirm n "Do you have a custom domain that you would like to link? (Only for cloud installations)" ; then
2020-10-16 05:27:16 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
2020-09-16 09:57:44 +00:00
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2020-09-16 14:21:02 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
2020-09-16 09:57:44 +00:00
"event" : "Installation Custom Domain" ,
"data" : {
2020-09-16 14:21:02 +00:00
"os" : "'" $os "'"
2020-09-16 09:57:44 +00:00
}
2020-10-16 05:27:16 +00:00
} ' > /dev/null
2020-07-30 05:48:48 +00:00
echo ""
2020-07-27 06:55:45 +00:00
echo "+++++++++++ IMPORTANT PLEASE READ ++++++++++++++++++++++"
2020-07-13 11:27:46 +00:00
echo "Please update your DNS records with your domain registrar"
echo "You can read more about this in our Documentation"
2021-02-03 15:15:16 +00:00
echo "https://docs.appsmith.com/v/v1.2.1/setup#custom-domains"
2020-07-27 06:55:45 +00:00
echo "+++++++++++++++++++++++++++++++++++++++++++++++"
2020-07-30 05:48:48 +00:00
echo ""
2020-07-13 11:27:46 +00:00
echo "Would you like to provision an SSL certificate for your custom domain / subdomain?"
2020-09-02 11:12:33 +00:00
if confirm y '(Your DNS records must be updated for us to proceed)' ; then
2021-03-16 07:55:37 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2021-03-16 07:55:37 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "SSL Provisioning Start" ,
"data" : {
"os" : "'" $os "'" ,
2021-03-16 08:34:22 +00:00
"platform" : "docker"
2021-03-16 07:55:37 +00:00
}
} ' > /dev/null
2020-09-02 11:12:33 +00:00
read -rp 'Enter the domain or subdomain on which you want to host appsmith (example.com / app.example.com): ' custom_domain
fi
2020-07-10 13:48:42 +00:00
fi
NGINX_SSL_CMNT = ""
if [ [ -z $custom_domain ] ] ; then
NGINX_SSL_CMNT = "#"
fi
2020-11-11 18:24:19 +00:00
ask_telemetry
2020-08-14 05:52:15 +00:00
echo ""
2020-08-20 04:52:22 +00:00
echo "Downloading the configuration templates..."
2021-04-29 13:53:17 +00:00
templates_dir = " $install_dir /tmp "
2020-09-02 11:12:33 +00:00
mkdir -p " $templates_dir "
(
cd " $templates_dir "
curl --remote-name-all --silent --show-error \
2020-09-03 12:34:58 +00:00
https://raw.githubusercontent.com/appsmithorg/appsmith/master/deploy/template/docker-compose.yml.sh \
https://raw.githubusercontent.com/appsmithorg/appsmith/master/deploy/template/mongo-init.js.sh \
https://raw.githubusercontent.com/appsmithorg/appsmith/master/deploy/template/docker.env.sh \
https://raw.githubusercontent.com/appsmithorg/appsmith/master/deploy/template/nginx_app.conf.sh \
https://raw.githubusercontent.com/appsmithorg/appsmith/master/deploy/template/encryption.env.sh
2020-07-16 06:17:45 +00:00
)
2020-07-10 13:48:42 +00:00
2020-09-02 11:12:33 +00:00
# Create needed folder structure.
2020-09-03 12:34:58 +00:00
mkdir -p " $install_dir /data/ " { nginx,mongo/db}
2020-07-10 13:48:42 +00:00
2020-08-14 05:52:15 +00:00
echo ""
2020-07-10 13:48:42 +00:00
echo "Generating the configuration files from the templates"
2021-04-29 13:53:17 +00:00
bash " $templates_dir /nginx_app.conf.sh " " $NGINX_SSL_CMNT " " $custom_domain " > " $templates_dir /nginx_app.conf "
bash " $templates_dir /docker-compose.yml.sh " " $mongo_root_user " " $mongo_root_password " " $mongo_database " > " $templates_dir /docker-compose.yml "
bash " $templates_dir /mongo-init.js.sh " " $mongo_root_user " " $mongo_root_password " > " $templates_dir /mongo-init.js "
bash " $templates_dir /docker.env.sh " " $encoded_mongo_root_user " " $encoded_mongo_root_password " " $mongo_host " " $disable_telemetry " > " $templates_dir /docker.env "
2020-09-02 11:12:33 +00:00
if [ [ " $setup_encryption " = "true" ] ] ; then
2021-04-29 13:53:17 +00:00
bash " $templates_dir /encryption.env.sh " " $user_encryption_password " " $user_encryption_salt " > " $templates_dir /encryption.env "
2020-07-16 06:17:45 +00:00
fi
2020-07-10 13:48:42 +00:00
2021-04-29 13:53:17 +00:00
overwrite_file "data/nginx/app.conf.template" " $templates_dir /nginx_app.conf "
overwrite_file "docker-compose.yml" " $templates_dir /docker-compose.yml "
overwrite_file "data/mongo/init.js" " $templates_dir /mongo-init.js "
overwrite_file "docker.env" " $templates_dir /docker.env "
overwrite_file "encryption.env" " $templates_dir /encryption.env "
2020-07-10 13:48:42 +00:00
echo ""
2021-03-16 08:01:17 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2021-03-16 08:01:17 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "Config Files Generated" ,
"data" : {
"os" : "'" $os "'" ,
2021-03-16 08:34:22 +00:00
"platform" : "docker"
2021-03-16 08:01:17 +00:00
}
} ' > /dev/null
2020-08-20 04:52:22 +00:00
cd " $install_dir "
if [ [ -n $custom_domain ] ] ; then
2020-09-03 12:34:58 +00:00
init_ssl_cert " $custom_domain "
2020-07-10 13:48:42 +00:00
else
2020-08-03 15:02:54 +00:00
echo "No domain found. Skipping generation of SSL certificate."
2020-07-10 13:48:42 +00:00
fi
2020-09-03 12:34:58 +00:00
rm -rf " $templates_dir "
2020-08-17 05:40:01 +00:00
echo ""
2020-08-03 15:02:54 +00:00
echo "Pulling the latest container images"
2020-07-10 13:48:42 +00:00
sudo docker-compose pull
2020-08-17 05:40:01 +00:00
echo ""
2020-07-10 13:48:42 +00:00
echo "Starting the Appsmith containers"
2020-08-20 04:52:22 +00:00
# The docker-compose command does some nasty stuff for the `--detach` functionality. So we add a `|| true` so that the
# script doesn't exit because this command looks like it failed to do it's thing.
sudo docker-compose up --detach --remove-orphans || true
2020-08-14 05:52:15 +00:00
wait_for_containers_start 60
2020-08-03 15:02:54 +00:00
echo ""
2020-08-14 05:52:15 +00:00
if [ [ $status_code -ne 401 ] ] ; then
echo "+++++++++++ ERROR ++++++++++++++++++++++"
echo "The containers didn't seem to start correctly. Please run the following command to check containers that may have errored out:"
echo ""
2020-08-20 04:52:22 +00:00
echo -e " cd \" $install_dir \" && sudo docker-compose ps -a "
2021-02-04 10:17:06 +00:00
echo "Please read our troubleshooting guide https://docs.appsmith.com/v/v1.2.1/troubleshooting-guide/deployment-errors"
2021-02-04 10:16:07 +00:00
echo "or reach us on Discord for support https://discord.com/invite/rBTTVJp"
2020-08-14 05:52:15 +00:00
echo "++++++++++++++++++++++++++++++++++++++++"
2020-10-16 05:27:16 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
2020-09-16 09:57:44 +00:00
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2020-10-29 06:34:43 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
"event" : "Installation Error" ,
"data" : {
"os" : "'" $os "'" ,
"error" : "Containers not started"
}
2020-10-16 05:27:16 +00:00
} ' > /dev/null
2020-10-29 06:34:43 +00:00
exit 1
2020-09-07 15:00:51 +00:00
else
2020-10-16 05:27:16 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
2020-09-16 09:57:44 +00:00
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2020-09-16 14:21:02 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
2020-09-07 17:33:28 +00:00
"event" : "Installation Success" ,
2020-09-16 09:57:44 +00:00
"data" : {
2020-09-16 14:21:02 +00:00
"os" : "'" $os "'"
2020-09-16 09:57:44 +00:00
}
2020-10-16 05:27:16 +00:00
} ' > /dev/null
2020-10-29 06:34:43 +00:00
echo "++++++++++++++++++ SUCCESS ++++++++++++++++++++++"
2020-08-20 14:54:27 +00:00
echo "Your installation is complete!"
2020-08-17 05:40:01 +00:00
echo ""
2020-08-20 04:52:22 +00:00
if [ [ -z $custom_domain ] ] ; then
echo "Your application is running on 'http://localhost'."
else
echo " Your application is running on 'https:// $custom_domain '. "
fi
2020-08-20 14:54:27 +00:00
echo ""
2020-08-14 05:52:15 +00:00
echo "+++++++++++++++++++++++++++++++++++++++++++++++++"
echo ""
2020-09-07 15:00:51 +00:00
echo "Need help Getting Started?"
2020-08-14 05:52:15 +00:00
echo "Join our Discord server https://discord.com/invite/rBTTVJp"
2020-11-11 18:24:19 +00:00
echo ""
2020-09-07 17:33:28 +00:00
echo "Please share your email to receive support & updates about appsmith!"
2020-09-07 16:53:24 +00:00
read -rp 'Email: ' email
2020-10-16 05:27:16 +00:00
curl -s --location --request POST 'https://hook.integromat.com/dkwb6i52am93pi30ojeboktvj32iw0fa' \
2020-09-16 09:57:44 +00:00
--header 'Content-Type: text/plain' \
2021-04-14 02:31:49 +00:00
--data ' {
2020-09-16 14:21:02 +00:00
"userId" : "'" $APPSMITH_INSTALLATION_ID "'" ,
2020-09-07 17:33:28 +00:00
"event" : "Identify Successful Installation" ,
2020-09-16 09:57:44 +00:00
"data" : {
2020-09-16 12:38:53 +00:00
"os" : "'" $os "'" ,
2020-09-16 14:21:02 +00:00
"email" : "'" $email "'"
2020-09-16 09:57:44 +00:00
}
2020-10-16 05:27:16 +00:00
} ' > /dev/null
2020-08-14 05:52:15 +00:00
fi
2020-11-11 18:24:19 +00:00
echo -e "\Thank you!\n"