From a020aa6eaf4d1489f18e1c753f34f60d67fdccae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20K=C3=B6lk=C3=B6y?= Date: Tue, 21 Feb 2023 22:08:25 +0300 Subject: [PATCH 01/17] do not need to handle OS difference here --- bin/installer.sh | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/bin/installer.sh b/bin/installer.sh index 83805fbfc2a..a3f96deb5c5 100755 --- a/bin/installer.sh +++ b/bin/installer.sh @@ -46,12 +46,4 @@ else fi fi -DATE=$(date +%Y-%m-%d:%H:%M:%S) -if [[ ! -z "$APT_GET_CMD" ]]; then - bash countly/bin/countly.install.sh 2>&1 | tee "countly/log/countly-install-$DATE.log" -elif [[ ! -z "$YUM_CMD" ]]; then - bash countly/bin/countly.install_rhel.sh 2>&1 | tee "countly/log/countly-install-$DATE.log" -else - echo "error can't install Countly" - exit 1; -fi \ No newline at end of file +bash countly/bin/countly.install.sh \ No newline at end of file From ebad72fa7a341e16ada918e9153a57e57974ea9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20K=C3=B6lk=C3=B6y?= Date: Tue, 21 Feb 2023 22:11:02 +0300 Subject: [PATCH 02/17] add path check since we handle installation by countly user now --- bin/countly.install.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bin/countly.install.sh b/bin/countly.install.sh index 53318f6a099..49d0d0f6056 100755 --- a/bin/countly.install.sh +++ b/bin/countly.install.sh @@ -3,6 +3,16 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DATE=$(date +%Y-%m-%d:%H:%M:%S) totalm=$(free -m | awk '/^Mem:/{print $2}') +if [[ "$DIR" = '/root'* ]]; then + echo "You cannot install Countly under /root. Suggested paths: /opt or /usr." + exit 1 +elif [[ "$DIR" = '/home'* ]]; then + if ! [[ "$DIR" = '/home/countly'* ]]; then + echo "You cannot install Countly under home directory of any other user. Suggested paths: /opt or /usr." + exit 1 + fi +fi + if [ "$INSIDE_DOCKER" == "1" ]; then if [ -f /etc/lsb-release ]; then apt install sudo -y From 227f9c6a05dde43fb619e73d09f2eeb2d48a042e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20K=C3=B6lk=C3=B6y?= Date: Tue, 21 Feb 2023 22:15:24 +0300 Subject: [PATCH 03/17] simplify MongoDB installation --- bin/scripts/mongodb.install.sh | 70 ++++++++++------------------------ 1 file changed, 20 insertions(+), 50 deletions(-) diff --git a/bin/scripts/mongodb.install.sh b/bin/scripts/mongodb.install.sh index a81e7c57bfe..24ce7351f87 100644 --- a/bin/scripts/mongodb.install.sh +++ b/bin/scripts/mongodb.install.sh @@ -358,76 +358,46 @@ function mongodb_check() { } if [ $# -eq 0 ]; then + #install latest mongodb if [ -f /etc/redhat-release ]; then - #install latest mongodb + CENTOS_RELEASE="$(rpm --eval '%{centos_ver}')" - #select source based on release - if grep -q -i "release 6" /etc/redhat-release ; then - echo "[mongodb-org-4.4] -name=MongoDB Repository -baseurl=https://repo.mongodb.org/yum/redhat/6/mongodb-org/4.4/x86_64/ -gpgcheck=1 -enabled=1 -gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc" > /etc/yum.repos.d/mongodb-org-4.4.repo - elif grep -q -i "release 7" /etc/redhat-release ; then - echo "[mongodb-org-4.4] -name=MongoDB Repository -baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/ -gpgcheck=1 -enabled=1 -gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc" > /etc/yum.repos.d/mongodb-org-4.4.repo - elif grep -q -i "release 8" /etc/redhat-release ; then - echo "[mongodb-org-4.4] + if [[ "$CENTOS_RELEASE" != "7" && "$CENTOS_RELEASE" != "8" ]]; then + echo "Unsupported OS version, only support CentOS/RHEL 8 and 7" + exit 1 + fi + + echo "[mongodb-org-4.4] name=MongoDB Repository -baseurl=https://repo.mongodb.org/yum/redhat/8/mongodb-org/4.4/x86_64/ +baseurl=https://repo.mongodb.org/yum/redhat/${CENTOS_RELEASE}/mongodb-org/4.4/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc" > /etc/yum.repos.d/mongodb-org-4.4.repo - fi + yum install -y mongodb-org fi if [ -f /etc/lsb-release ]; then - #install latest mongodb - wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add - UBUNTU_YEAR="$(lsb_release -sr | cut -d '.' -f 1)"; - if [ "$UBUNTU_YEAR" == "16" ]; then - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list ; - elif [ "$UBUNTU_YEAR" == "18" ]; then - echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list ; - elif [ "$UBUNTU_YEAR" == "22" ]; then - wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb ; - dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb ; - rm -rf libssl1.1_1.1.1f-1ubuntu2_amd64.deb - echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list ; - else - echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list ; + if [[ "$UBUNTU_YEAR" != "18" && "$UBUNTU_YEAR" != "20" && "$UBUNTU_YEAR" != "22" ]]; then + echo "Unsupported OS version, only support Ubuntu 22, 20 and 18" + exit 1 fi + + wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add - + UBUNTU_RELEASE="$(lsb_release -cs)" + echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu ${UBUNTU_RELEASE}/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list ; + apt-get update - #install mongodb DEBIAN_FRONTEND="noninteractive" apt-get -y install mongodb-org || (echo "Failed to install mongodb." ; exit) fi #backup config and remove configuration to prevent duplicates mongodb_configure - if [ -f /etc/redhat-release ]; then - #mongodb might need to be started - if grep -q -i "release 6" /etc/redhat-release ; then - service mongod restart > /dev/null || echo "mongodb service does not exist" - else - systemctl restart mongod > /dev/null || echo "mongodb systemctl job does not exist" - fi - fi - - if [ -f /etc/lsb-release ]; then - if [[ "$(/sbin/init --version)" =~ upstart ]]; then - restart mongod > /dev/null || echo "mongodb upstart job does not exist" - else - systemctl restart mongod || echo "mongodb systemctl job does not exist" - fi 2> /dev/null - fi + #mongodb might need to be restarted + systemctl restart mongod > /dev/null || echo "mongodb systemctl job does not exist" mongodb_check elif [ "$1" == "check" ]; then From 9458d9b405f339e09a3fa47f18a320c5cad1e1ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20K=C3=B6lk=C3=B6y?= Date: Tue, 21 Feb 2023 22:21:35 +0300 Subject: [PATCH 04/17] fix indents, if block styles etc --- bin/countly.install_rhel.sh | 5 +++-- bin/countly.install_ubuntu.sh | 24 +++++++++++------------- bin/scripts/init_countly_user.sh | 1 + 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/bin/countly.install_rhel.sh b/bin/countly.install_rhel.sh index 351aae1dae8..923517254db 100755 --- a/bin/countly.install_rhel.sh +++ b/bin/countly.install_rhel.sh @@ -24,10 +24,10 @@ if grep -q -i "release 8" /etc/redhat-release ; then fi sudo yum -y install epel-release + # see https://github.com/koalaman/shellcheck/issues/1871 wget https://github.com/koalaman/shellcheck/releases/download/v0.7.1/shellcheck-v0.7.1.linux.x86_64.tar.xz sudo tar -C /usr/local/bin/ -xf shellcheck-v0.7.1.linux.x86_64.tar.xz --no-anchored 'shellcheck' --strip=1 - sudo ln -sf /usr/local/bin/shellcheck /usr/bin/shellcheck if [ ! -x "$(command -v python)" ]; then @@ -52,11 +52,11 @@ enabled=1" | sudo tee /etc/yum.repos.d/nginx.repo >/dev/null sudo yum install devtoolset-8 -y sudo yum install devtoolset-8-gcc* -y + #shellcheck source=/dev/null source /opt/rh/devtoolset-8/enable && echo -e "\nsource /opt/rh/devtoolset-8/enable" | sudo tee -a /etc/profile sudo yum install -y epel-release sudo yum install -y ShellCheck - else echo "Unsupported OS version, only support RHEL/Centos 8 and 7" exit 1 @@ -111,6 +111,7 @@ sudo yum install numactl -y #install mongodb sudo bash "$DIR/scripts/mongodb.install.sh" + if [ "$INSIDE_DOCKER" == "1" ]; then sudo sed -i 's/ fork/# fork/g' /etc/mongod.conf sudo mongod -f /etc/mongod.conf & diff --git a/bin/countly.install_ubuntu.sh b/bin/countly.install_ubuntu.sh index d766a5b284c..97d9951322a 100644 --- a/bin/countly.install_ubuntu.sh +++ b/bin/countly.install_ubuntu.sh @@ -20,6 +20,7 @@ sudo apt-get -y install wget build-essential libkrb5-dev git sqlite3 unzip bzip2 if [[ "$UBUNTU_YEAR" = "22" ]]; then sudo apt-get -y install python2 python2-dev + if [[ ! -h /usr/bin/python ]]; then sudo ln -s /usr/bin/python2.7 /usr/bin/python sudo ln -s /usr/bin/python2-config /usr/bin/python-config @@ -68,7 +69,7 @@ set +e NODE_JS_CMD=$(which nodejs) set -e if [[ -z "$NODE_JS_CMD" ]]; then - sudo ln -s "$(which node)" /usr/bin/nodejs + sudo ln -s "$(which node)" /usr/bin/nodejs fi #if npm is not installed, install it too @@ -77,8 +78,7 @@ if ! (command -v npm >/dev/null) then fi #install supervisor -if [ "$INSIDE_DOCKER" != "1" ] -then +if [ "$INSIDE_DOCKER" != "1" ]; then sudo apt-get -y install supervisor || (echo "Failed to install supervisor." ; exit) cp "$DIR/config/supervisord.example.conf" "$DIR/config/supervisord.conf" fi @@ -96,15 +96,15 @@ npm config set prefix "$DIR/../.local/" #install mongodb sudo bash "$DIR/scripts/mongodb.install.sh" -if [ "$INSIDE_DOCKER" == "1" ] -then - bash "$DIR/commands/docker/mongodb.sh" & - until mongo --eval "db.stats()" | grep "collections" - do +if [ "$INSIDE_DOCKER" == "1" ]; then + bash "$DIR/commands/docker/mongodb.sh" & + + until mongo --eval "db.stats()" | grep "collections"; do echo echo "waiting for MongoDB to allocate files..." sleep 1 done + sleep 3 fi @@ -116,8 +116,7 @@ countly save /etc/nginx/nginx.conf "$DIR/config/nginx" sudo cp "$DIR/config/nginx.server.conf" /etc/nginx/conf.d/default.conf sudo cp "$DIR/config/nginx.conf" /etc/nginx/nginx.conf -if [ "$INSIDE_DOCKER" != "1" ] -then +if [ "$INSIDE_DOCKER" != "1" ]; then sudo /etc/init.d/nginx restart fi @@ -130,7 +129,7 @@ cp -n "$DIR/../api/config.sample.js" "$DIR/../api/config.js" cp -n "$DIR/../frontend/express/config.sample.js" "$DIR/../frontend/express/config.js" if [ ! -f "$DIR/../plugins/plugins.json" ]; then - cp "$DIR/../plugins/plugins.default.json" "$DIR/../plugins/plugins.json" + cp "$DIR/../plugins/plugins.default.json" "$DIR/../plugins/plugins.json" fi if [ ! -f "/etc/timezone" ]; then @@ -163,8 +162,7 @@ sudo countly task dist-all sudo countly check after install #finally start countly api and dashboard -if [ "$INSIDE_DOCKER" != "1" ] -then +if [ "$INSIDE_DOCKER" != "1" ]; then sudo countly start fi diff --git a/bin/scripts/init_countly_user.sh b/bin/scripts/init_countly_user.sh index 82d701ea387..799923693dd 100644 --- a/bin/scripts/init_countly_user.sh +++ b/bin/scripts/init_countly_user.sh @@ -3,6 +3,7 @@ #get current directory DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" COUNTLY_DIR="$( cd "$DIR"/../../ && pwd )" + #check if user not created yet if [ "$(getent passwd countly)x" == 'x' ]; then #create countly user From 95078f956a279bd46d29bd19ff781a5f109cffa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20K=C3=B6lk=C3=B6y?= Date: Tue, 21 Feb 2023 22:22:50 +0300 Subject: [PATCH 05/17] lets keep DIR on the top as usual --- bin/countly.install_ubuntu.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/countly.install_ubuntu.sh b/bin/countly.install_ubuntu.sh index 97d9951322a..9bf5964a0ac 100644 --- a/bin/countly.install_ubuntu.sh +++ b/bin/countly.install_ubuntu.sh @@ -2,6 +2,8 @@ set -e +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + UBUNTU_YEAR="$(lsb_release -sr | cut -d '.' -f 1)"; if [[ "$UBUNTU_YEAR" != "18" && "$UBUNTU_YEAR" != "20" && "$UBUNTU_YEAR" != "22" ]]; then @@ -9,8 +11,6 @@ if [[ "$UBUNTU_YEAR" != "18" && "$UBUNTU_YEAR" != "20" && "$UBUNTU_YEAR" != "22" exit 1 fi -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - bash "$DIR/scripts/logo.sh"; #update package index From 340aed1a3f946523301a418cc65a1aced128a6bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20K=C3=B6lk=C3=B6y?= Date: Tue, 21 Feb 2023 22:23:47 +0300 Subject: [PATCH 06/17] fix repeating package names --- bin/countly.install_ubuntu.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bin/countly.install_ubuntu.sh b/bin/countly.install_ubuntu.sh index 9bf5964a0ac..808da833f14 100644 --- a/bin/countly.install_ubuntu.sh +++ b/bin/countly.install_ubuntu.sh @@ -16,7 +16,7 @@ bash "$DIR/scripts/logo.sh"; #update package index sudo apt-get update -sudo apt-get -y install wget build-essential libkrb5-dev git sqlite3 unzip bzip2 shellcheck +sudo apt-get -y install wget build-essential libkrb5-dev git sqlite3 unzip bzip2 shellcheck curl gnupg2 ca-certificates lsb-release if [[ "$UBUNTU_YEAR" = "22" ]]; then sudo apt-get -y install python2 python2-dev @@ -31,11 +31,10 @@ fi #Install GCC && G++> 7 version sudo apt-get -y install software-properties-common -sudo apt-get -y install build-essential -sudo apt-get install gcc g++ make +sudo apt-get -y install gcc g++ make #Install dependancies required by the puppeteer -sudo apt-get -y install libgbm-dev libgbm1 gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget +sudo apt-get -y install libgbm-dev libgbm1 gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils if sudo apt-cache pkgnames | grep -q python-software-properties; then sudo apt-get -y install python-software-properties From 232b1fdf5e64ddd69d4984ca4521f6e495d802e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20K=C3=B6lk=C3=B6y?= Date: Tue, 21 Feb 2023 22:32:24 +0300 Subject: [PATCH 07/17] keep calling done script at the end --- bin/countly.install_ubuntu.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bin/countly.install_ubuntu.sh b/bin/countly.install_ubuntu.sh index 808da833f14..6b362e5250b 100644 --- a/bin/countly.install_ubuntu.sh +++ b/bin/countly.install_ubuntu.sh @@ -165,9 +165,8 @@ if [ "$INSIDE_DOCKER" != "1" ]; then sudo countly start fi -bash "$DIR/scripts/done.sh"; - -if [ "$INSIDE_DOCKER" == "1" ] -then +if [ "$INSIDE_DOCKER" == "1" ]; then kill -2 "$(pgrep mongo)" -fi \ No newline at end of file +fi + +bash "$DIR/scripts/done.sh"; \ No newline at end of file From c2c51150e84c1425e3dd0903210fce08ebf70bee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20K=C3=B6lk=C3=B6y?= Date: Tue, 21 Feb 2023 22:35:08 +0300 Subject: [PATCH 08/17] change order of additional repositories --- bin/countly.install_ubuntu.sh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/bin/countly.install_ubuntu.sh b/bin/countly.install_ubuntu.sh index 6b362e5250b..044713a9c44 100644 --- a/bin/countly.install_ubuntu.sh +++ b/bin/countly.install_ubuntu.sh @@ -46,15 +46,7 @@ if ! (command -v apt-add-repository >/dev/null) then sudo apt-get -y install software-properties-common fi -#add node.js repo -#echo | apt-add-repository ppa:chris-lea/node.js -wget -qO- https://deb.nodesource.com/setup_14.x | sudo -E bash - - -#update once more after adding new repos -sudo apt-get update - #install nginx -sudo apt-get -y install curl gnupg2 ca-certificates lsb-release echo "deb http://nginx.org/packages/ubuntu $(lsb_release -cs) nginx" \ | sudo tee /etc/apt/sources.list.d/nginx.list curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add - @@ -62,6 +54,10 @@ sudo apt-get update sudo apt-get -y install nginx #install node.js +#add node.js repo +#echo | apt-add-repository ppa:chris-lea/node.js +wget -qO- https://deb.nodesource.com/setup_14.x | sudo -E bash - +sudo apt-get update sudo apt-get -y install nodejs || (echo "Failed to install nodejs." ; exit) set +e From 24f9c5a24e1a4e7c8d67eae962a47879192d157b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20K=C3=B6lk=C3=B6y?= Date: Tue, 21 Feb 2023 23:07:10 +0300 Subject: [PATCH 09/17] fix pass directory check for github actions --- .github/workflows/main.yml | 22 +++++++++++----------- bin/countly.install.sh | 14 ++++++++------ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7f54991fa72..498df32cdd6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,7 +22,7 @@ jobs: steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 - + - name: Github Actions Azure connection fix run: | # Workaround for https://github.com/actions/runner-images/issues/675#issuecomment-1381389712 @@ -30,28 +30,28 @@ jobs: - name: Installing Countly shell: bash - run: sudo bash ./bin/countly.install.sh - + run: sudo bash ./bin/countly.install.sh gh + - name: NodeJS version shell: bash run: node --version - + - name: NPM version shell: bash run: npm --version - + - name: Mongo version shell: bash run: mongo --version - + - name: ShellCheck shell: bash run: countly shellcheck - + - name: ESLint shell: bash run: npx eslint . - + - name: DistFiles shell: bash run: sudo countly task dist-all @@ -63,11 +63,11 @@ jobs: - name: Output API Logs if: ${{ always() }} run: cat log/countly-api.log - + - name: Output Dashboard Logs if: ${{ always() }} run: cat log/countly-dashboard.log - + - name: Output MongoDB Logs if: ${{ always() }} run: sudo cat /var/log/mongodb/mongod.log @@ -75,7 +75,7 @@ jobs: - name: Output Nginx Logs if: ${{ always() }} run: sudo cat /var/log/nginx/error.log - + - name: Send slack notification id: slack if: always() diff --git a/bin/countly.install.sh b/bin/countly.install.sh index 49d0d0f6056..536a486dce8 100755 --- a/bin/countly.install.sh +++ b/bin/countly.install.sh @@ -3,13 +3,15 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DATE=$(date +%Y-%m-%d:%H:%M:%S) totalm=$(free -m | awk '/^Mem:/{print $2}') -if [[ "$DIR" = '/root'* ]]; then - echo "You cannot install Countly under /root. Suggested paths: /opt or /usr." - exit 1 -elif [[ "$DIR" = '/home'* ]]; then - if ! [[ "$DIR" = '/home/countly'* ]]; then - echo "You cannot install Countly under home directory of any other user. Suggested paths: /opt or /usr." +if ! [[ "$1" = 'gh' ]]; then + if [[ "$DIR" = '/root'* ]]; then + echo "You cannot install Countly under /root. Suggested paths: /opt or /usr." exit 1 + elif [[ "$DIR" = '/home'* ]]; then + if ! [[ "$DIR" = '/home/countly'* ]]; then + echo "You cannot install Countly under home directory of any other user. Suggested paths: /opt or /usr." + exit 1 + fi fi fi From 5ffb68b5e34c4c4f1d093ff845b072373d6963df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20K=C3=B6lk=C3=B6y?= Date: Tue, 21 Feb 2023 23:49:20 +0300 Subject: [PATCH 10/17] fix bash parameter pass to if block --- bin/countly.install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/countly.install.sh b/bin/countly.install.sh index 536a486dce8..6289e7f5ad9 100755 --- a/bin/countly.install.sh +++ b/bin/countly.install.sh @@ -3,7 +3,8 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DATE=$(date +%Y-%m-%d:%H:%M:%S) totalm=$(free -m | awk '/^Mem:/{print $2}') -if ! [[ "$1" = 'gh' ]]; then +GH_ACTIONS_TRIGGER=$1 +if ! [[ "$GH_ACTIONS_TRIGGER" = 'gh' ]]; then if [[ "$DIR" = '/root'* ]]; then echo "You cannot install Countly under /root. Suggested paths: /opt or /usr." exit 1 From 5d9b59c266031f52d8078412bf5fd165998cd117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20K=C3=B6lk=C3=B6y?= Date: Wed, 22 Feb 2023 00:13:31 +0300 Subject: [PATCH 11/17] fix owner of service as countly --- bin/config/supervisord.example.conf | 2 +- bin/config/supervisord.ldaps.conf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/config/supervisord.example.conf b/bin/config/supervisord.example.conf index 28dd4571feb..05d035dc193 100644 --- a/bin/config/supervisord.example.conf +++ b/bin/config/supervisord.example.conf @@ -10,7 +10,7 @@ pidfile=/var/log/supervisord.pid nodaemon=false minfds=1024 minprocs=200 -user=root +user=countly childlogdir=/var/log/ [rpcinterface:supervisor] diff --git a/bin/config/supervisord.ldaps.conf b/bin/config/supervisord.ldaps.conf index d99c1a427cc..0e34c0a6e83 100644 --- a/bin/config/supervisord.ldaps.conf +++ b/bin/config/supervisord.ldaps.conf @@ -10,7 +10,7 @@ pidfile=/var/log/supervisord.pid nodaemon=false minfds=1024 minprocs=200 -user=root +user=countly childlogdir=/var/log/ [rpcinterface:supervisor] From d6d7090a983631ba9c73ee20fc043beb4678180a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20K=C3=B6lk=C3=B6y?= Date: Wed, 22 Feb 2023 01:50:53 +0300 Subject: [PATCH 12/17] fix run supervisord service by countly user --- bin/config/supervisord.example.conf | 6 +++--- bin/config/supervisord.ldaps.conf | 6 +++--- log/supervisord/supervisord.log | 0 3 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 log/supervisord/supervisord.log diff --git a/bin/config/supervisord.example.conf b/bin/config/supervisord.example.conf index 05d035dc193..a0b80b382fd 100644 --- a/bin/config/supervisord.example.conf +++ b/bin/config/supervisord.example.conf @@ -2,16 +2,16 @@ file=/tmp/supervisor.sock [supervisord] -logfile=/var/log/supervisord.log +logfile=%(here)s/../../log/supervisord/supervisord.log logfile_maxbytes=50MB logfile_backups=10 loglevel=warn -pidfile=/var/log/supervisord.pid +pidfile=%(here)s/../../log/supervisord/supervisord.pid nodaemon=false minfds=1024 minprocs=200 user=countly -childlogdir=/var/log/ +childlogdir=%(here)s/../../log/supervisord/ [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface diff --git a/bin/config/supervisord.ldaps.conf b/bin/config/supervisord.ldaps.conf index 0e34c0a6e83..f58973e5df1 100644 --- a/bin/config/supervisord.ldaps.conf +++ b/bin/config/supervisord.ldaps.conf @@ -2,16 +2,16 @@ file=/tmp/supervisor.sock [supervisord] -logfile=/var/log/supervisord.log +logfile=%(here)s/../../log/supervisord/supervisord.log logfile_maxbytes=50MB logfile_backups=10 loglevel=warn -pidfile=/var/log/supervisord.pid +pidfile=%(here)s/../../log/supervisord/supervisord.pid nodaemon=false minfds=1024 minprocs=200 user=countly -childlogdir=/var/log/ +childlogdir=%(here)s/../../log/supervisord/ [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface diff --git a/log/supervisord/supervisord.log b/log/supervisord/supervisord.log new file mode 100644 index 00000000000..e69de29bb2d From c9fc5b14191d7ff4a2563dbd0551add89a22a83a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20K=C3=B6lk=C3=B6y?= Date: Wed, 22 Feb 2023 02:59:42 +0300 Subject: [PATCH 13/17] fix MongoDB installation for Ubuntu 22 --- bin/scripts/mongodb.install.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bin/scripts/mongodb.install.sh b/bin/scripts/mongodb.install.sh index 24ce7351f87..fc23bb67106 100644 --- a/bin/scripts/mongodb.install.sh +++ b/bin/scripts/mongodb.install.sh @@ -385,8 +385,19 @@ gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc" > /etc/yum.repos.d/mon exit 1 fi + #mongodb 4.4 is not supported officially on Ubuntu 22 + if [[ "$UBUNTU_YEAR" == "22" ]]; then + #we can install binaries of Ubuntu 20 if we pre-install required libssl + wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb ; + dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb ; + rm -rf libssl1.1_1.1.1f-1ubuntu2_amd64.deb + + UBUNTU_RELEASE="focal" + else + UBUNTU_RELEASE="$(lsb_release -cs)" + fi + wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add - - UBUNTU_RELEASE="$(lsb_release -cs)" echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu ${UBUNTU_RELEASE}/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list ; apt-get update From 16921292701740a3bd0d84f39fa1ffe8b8141315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20K=C3=B6lk=C3=B6y?= Date: Wed, 1 Mar 2023 01:13:14 +0300 Subject: [PATCH 14/17] Check by trying to create a file instead of blocking hardcoded paths --- bin/countly.install.sh | 23 ++++++++----------- bin/scripts/check_countly_user_permissions.sh | 3 +++ 2 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 bin/scripts/check_countly_user_permissions.sh diff --git a/bin/countly.install.sh b/bin/countly.install.sh index 6289e7f5ad9..95b4e03126e 100755 --- a/bin/countly.install.sh +++ b/bin/countly.install.sh @@ -3,19 +3,6 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DATE=$(date +%Y-%m-%d:%H:%M:%S) totalm=$(free -m | awk '/^Mem:/{print $2}') -GH_ACTIONS_TRIGGER=$1 -if ! [[ "$GH_ACTIONS_TRIGGER" = 'gh' ]]; then - if [[ "$DIR" = '/root'* ]]; then - echo "You cannot install Countly under /root. Suggested paths: /opt or /usr." - exit 1 - elif [[ "$DIR" = '/home'* ]]; then - if ! [[ "$DIR" = '/home/countly'* ]]; then - echo "You cannot install Countly under home directory of any other user. Suggested paths: /opt or /usr." - exit 1 - fi - fi -fi - if [ "$INSIDE_DOCKER" == "1" ]; then if [ -f /etc/lsb-release ]; then apt install sudo -y @@ -25,6 +12,16 @@ if [ "$INSIDE_DOCKER" == "1" ]; then fi sudo bash "$DIR/scripts/init_countly_user.sh" +cd "$DIR/../" +sudo su countly -c "/bin/bash $DIR/scripts/check_countly_user_permissions.sh > /dev/null 2>&1" + +if [ ! -f ./permission_test_file.txt ]; then + PARENT_DIR=$(cd ./../ && pwd) + echo "Permission error, you cannot install Countly under ${PARENT_DIR}." +else + rm -f ./permission_test_file.txt +fi + if [ "$totalm" -lt "1800" ]; then echo "Countly requires at least 2Gb of RAM" diff --git a/bin/scripts/check_countly_user_permissions.sh b/bin/scripts/check_countly_user_permissions.sh new file mode 100644 index 00000000000..1e2ce3bb4b3 --- /dev/null +++ b/bin/scripts/check_countly_user_permissions.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +touch permission_test_file.txt \ No newline at end of file From 50e0d8863daefc697985cb4e31f58d927525b194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20K=C3=B6lk=C3=B6y?= Date: Wed, 1 Mar 2023 01:19:30 +0300 Subject: [PATCH 15/17] facepalm here --- bin/countly.install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/countly.install.sh b/bin/countly.install.sh index 95b4e03126e..5a73405cbd9 100755 --- a/bin/countly.install.sh +++ b/bin/countly.install.sh @@ -19,7 +19,7 @@ if [ ! -f ./permission_test_file.txt ]; then PARENT_DIR=$(cd ./../ && pwd) echo "Permission error, you cannot install Countly under ${PARENT_DIR}." else - rm -f ./permission_test_file.txt + sudo rm -f ./permission_test_file.txt fi From 27764129cece580bc600f70695a1e7866da8b381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20K=C3=B6lk=C3=B6y?= Date: Wed, 1 Mar 2023 01:21:39 +0300 Subject: [PATCH 16/17] whats matter if you do not exit from the script... --- bin/countly.install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/countly.install.sh b/bin/countly.install.sh index 5a73405cbd9..aeac665b9ea 100755 --- a/bin/countly.install.sh +++ b/bin/countly.install.sh @@ -18,6 +18,7 @@ sudo su countly -c "/bin/bash $DIR/scripts/check_countly_user_permissions.sh > / if [ ! -f ./permission_test_file.txt ]; then PARENT_DIR=$(cd ./../ && pwd) echo "Permission error, you cannot install Countly under ${PARENT_DIR}." + exit 1 else sudo rm -f ./permission_test_file.txt fi From 083ebcb27cfc914b6084f54a6777b488b3718e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20K=C3=B6lk=C3=B6y?= Date: Wed, 1 Mar 2023 01:26:36 +0300 Subject: [PATCH 17/17] we do not bypass anything for github actions --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 498df32cdd6..e431f69100a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,7 +30,7 @@ jobs: - name: Installing Countly shell: bash - run: sudo bash ./bin/countly.install.sh gh + run: sudo bash ./bin/countly.install.sh - name: NodeJS version shell: bash