deployment problem with permission denied while selecting node version - azure-web-app-service

From the beginning, I've always had problem using kudu deployment for my node 12 web app.
This time I have select node version failed in pipeline logs, but a Not setting execute permissions for bash when I access the log details from the link. The worst is that nothing has changed in the code or the pipeline, one day you woke up, and your app doesn't work any more. This is the third time it happens, every time a new version of node is available in the list of available versions. Can someone please point me out THE solution that will work for more than one month please ? I used the default script for node web apps from kudu documentation, just replaced npm with yarn. And using the environment variables WEBSITE_NODE_DEFAULT_VERSION and WEBSITE_NPM_DEFAULT_VERSION in the app configuration. I tried every combination of node version var with or without the npm one, ... nothing works. I really need a long term solution to finally solve this problem, otherwise I think I will move to more stable alternatives. Any help is much appreciated.
An issue that can be related https://github.com/projectkudu/kudu/issues/2870#issuecomment-443464291
EDIT
this is my .deployment file
[config]
command = bash ./scripts/bash/deploy.sh
this is my shell file in scripts/bash/deploy.sh, as you can see the only difference with the default custom deployment script retrived with the command kuduscript -y --node, is yarn instead of npm
#!/bin/bash
# ----------------------
# KUDU Deployment Script
# Version: 1.0.17
# ----------------------
# Helpers
# -------
exitWithMessageOnError() {
if [ ! $? -eq 0 ]; then
echo "An error has occurred during web site deployment."
echo $1
exit 1
fi
}
# Prerequisites
# -------------
# Verify node.js installed
hash node 2>/dev/null
exitWithMessageOnError "Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment."
# Setup
# -----
SCRIPT_DIR="${BASH_SOURCE[0]%\\*}"
SCRIPT_DIR="${SCRIPT_DIR%/*}"
ARTIFACTS=$SCRIPT_DIR/../artifacts
KUDU_SYNC_CMD=${KUDU_SYNC_CMD//\"/}
if [[ ! -n "$DEPLOYMENT_SOURCE" ]]; then
DEPLOYMENT_SOURCE=$SCRIPT_DIR
fi
if [[ ! -n "$NEXT_MANIFEST_PATH" ]]; then
NEXT_MANIFEST_PATH=$ARTIFACTS/manifest
if [[ ! -n "$PREVIOUS_MANIFEST_PATH" ]]; then
PREVIOUS_MANIFEST_PATH=$NEXT_MANIFEST_PATH
fi
fi
if [[ ! -n "$DEPLOYMENT_TARGET" ]]; then
DEPLOYMENT_TARGET=$ARTIFACTS/wwwroot
else
KUDU_SERVICE=true
fi
if [[ ! -n "$KUDU_SYNC_CMD" ]]; then
# Install kudu sync
echo Installing Kudu Sync
npm install kudusync -g --silent
exitWithMessageOnError "npm failed"
if [[ ! -n "$KUDU_SERVICE" ]]; then
# In case we are running locally this is the correct location of kuduSync
KUDU_SYNC_CMD=kuduSync
else
# In case we are running on kudu service this is the correct location of kuduSync
KUDU_SYNC_CMD=$APPDATA/npm/node_modules/kuduSync/bin/kuduSync
fi
fi
# Node Helpers
# ------------
selectNodeVersion() {
if [[ -n "$KUDU_SELECT_NODE_VERSION_CMD" ]]; then
SELECT_NODE_VERSION="$KUDU_SELECT_NODE_VERSION_CMD \"$DEPLOYMENT_SOURCE\" \"$DEPLOYMENT_TARGET\" \"$DEPLOYMENT_TEMP\""
eval $SELECT_NODE_VERSION
exitWithMessageOnError "select node version failed"
if [[ -e "$DEPLOYMENT_TEMP/__nodeVersion.tmp" ]]; then
NODE_EXE=$(cat "$DEPLOYMENT_TEMP/__nodeVersion.tmp")
exitWithMessageOnError "getting node version failed"
fi
if [[ -e "$DEPLOYMENT_TEMP/__npmVersion.tmp" ]]; then
NPM_JS_PATH=$(cat "$DEPLOYMENT_TEMP/__npmVersion.tmp")
exitWithMessageOnError "getting npm version failed"
fi
if [[ ! -n "$NODE_EXE" ]]; then
NODE_EXE=node
fi
NPM_CMD="\"$NODE_EXE\" \"$NPM_JS_PATH\""
else
NPM_CMD=npm
NODE_EXE=node
fi
}
##################################################################################################################################
# Deployment
# ----------
echo Handling node.js deployment.
# 1. KuduSync
if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then
"$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh"
exitWithMessageOnError "Kudu Sync failed"
fi
# 2. Select node version
selectNodeVersion
# 3. Install yarn packages
if [ -e "$DEPLOYMENT_TARGET/package.json" ]; then
cd "$DEPLOYMENT_TARGET"
echo "Running yarn install"
eval yarn install --production=false --network-timeout 1000000
echo "building dist"
eval yarn build
echo "Running migrations"
eval yarn typeorm:migration:run
exitWithMessageOnError "yarn failed"
cd - >/dev/null
fi
##################################################################################################################################
echo "Finished successfully."
I set (this time, but I already tried multiple combinations) only the variable WEBSITE_NODE_DEFAULT_VERSION to 12.18.2, and I didn't set the WEBSITE_NPM_DEFAULT_VERSION variable. This is the output when I try to deploy using git local method, with the command git push azure master:master:
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 391 bytes | 391.00 KiB/s, done.
Total 5 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Deploy Async
remote: Updating branch 'master'.
remote: Updating submodules.
remote: Preparing deployment for commit id '79f0842a60'.
remote: Running custom deployment command...
remote: Not setting execute permissions for bash ./scripts/bash/deploy.sh
remote: Running deployment command...
remote: Handling node.js deployment.
remote: Kudu sync from: '/home/site/repository' to: '/home/site/wwwroot'
remote: Ignoring: .deployment
remote: Ignoring: .git
remote: Ignoring: scripts/bash/deploy.sh
remote: Detecting node version spec...
remote: Using appsetting WEBSITE_NODE_DEFAULT_VERSION value: 12.18.2
remote: Node.js versions available on the platform are: 8.0.0, 8.1.4, 8.2.1, 8.8.1, 8.9.4, 8.11.4, 8.12.0, 8.15.1, 8.17.0, 9.4.0, 10.1.0, 10.10.0, 10.14.2, 10.21.0, 10.23.0, 12.18.2, 12.19.0, 14.15.0.
remote: ENOENT: no such file or directory, open '/opt/nodejs/12.18.2/npm.txt'
remote: Resolved to version 12.18.2
remote: Detecting npm version spec...
remote: An error has occurred during web site deployment.
remote: select node version failed
remote: Deployment Logs : 'https://***.scm.azurewebsites.net/newui/jsonviewer?view_url=/api/deployments/79f0842a60c7fe25af603fe673868789272923e3/log'
To https://***.scm.azurewebsites.net:443/kiwi-prod-appservice.git
cdc1c91..79f0842 master -> master
When I click on the link to see log details:
[
"0" :
{
"details_url" : null,
"id" : "660d4119-1437-494a-a97b-5af7244afd58",
"log_time" : "2020-12-22T04:58:51.7786621Z",
"message" : "Updating branch 'master'.",
"type" : 0
}
,
"1" :
{
"details_url" : null,
"id" : "bca90e55-fc4c-40c4-91bd-337a0e3df515",
"log_time" : "2020-12-22T04:58:53.3322101Z",
"message" : "Updating submodules.",
"type" : 0
}
,
"2" :
{
"details_url" : null,
"id" : "bfc59c6f-e3ad-4bbd-afb5-bda11bec9771",
"log_time" : "2020-12-22T04:58:53.3779506Z",
"message" : "Preparing deployment for commit id '79f0842a60'.",
"type" : 0
}
,
"3" :
{
"details_url" : null,
"id" : "92219cc6-d58f-4988-9ec5-c1fd109c0986",
"log_time" : "2020-12-22T04:58:53.4866308Z",
"message" : "Running custom deployment command...",
"type" : 0
}
,
"4" :
{
"details_url" : null,
"id" : "f61aa2f5-8d77-4d3b-b328-3ab1fc69bf33",
"log_time" : "2020-12-22T04:58:53.51928Z",
"message" : "Not setting execute permissions for bash ./scripts/bash/deploy.sh",
"type" : 0
}
,
"5" :
{
"details_url" : "https://***.scm.azurewebsites.net/api/deployments/79f0842a60c7fe25af603fe673868789272923e3/log/3ed28b72-4514-4c87-8d6a-006c09150754",
"id" : "3ed28b72-4514-4c87-8d6a-006c09150754",
"log_time" : "2020-12-22T04:58:53.5555321Z",
"message" : "Running deployment command...",
"type" : 2
}
]

solved (for now) after commenting the SELECT_NODE_VERSION command
# SELECT_NODE_VERSION="$KUDU_SELECT_NODE_VERSION_CMD \"$DEPLOYMENT_SOURCE\" \"$DEPLOYMENT_TARGET\" \"$DEPLOYMENT_TEMP\""
# eval $SELECT_NODE_VERSION
# exitWithMessageOnError "select node version failed"
because the error was always triggered. I also had to use npm instead of yarn, because the node version used by yarn wasn't the correct one

Related

Job getting succeeded even when there is an error in gitlab-ci

I have a pipeline which pushes the packages to a server. In the logs of that script, I can see that even when it has some errors into it(and when I check into that server, the file doesn't appear there, which means there is definetly an error), the job still gets succeeded.
Below is the part of the logs:
ECHO sudo aptly repo add stable abc.deb
Loading packages...
[!] Unable to process abc.deb: stat abc.deb: no such file or directory
[!] Some files were skipped due to errors:
abc.deb
ECHO sudo aptly snapshot create abc-stable_2023.01.02-09.23.36 from repo stable
Snapshot abc-stable_2023.01.02-09.23.36 successfully created.
You can run 'aptly publish snapshot abc-stable_2023.01.02-09.23.36' to publish snapshot as Debian repository.
ECHO sudo aptly publish -passphrase=12345 switch xenial abc-stable_2023.01.02-09.23.36
ERROR: some files failed to be added
Loading packages...
Generating metadata files and linking package files...
Finalizing metadata files...
gpg: WARNING: unsafe permissions on configuration file `/home/.gnupg/gpg.conf'
gpg: WARNING: unsafe enclosing directory permissions on configuration file `/home/.gnupg/gpg.conf'
Signing file 'Release' with gpg, please enter your passphrase when prompted:
Clearsigning file 'Release' with gpg, please enter your passphrase when prompted:
gpg: WARNING: unsafe permissions on configuration file `/home/.gnupg/gpg.conf'
gpg: WARNING: unsafe enclosing directory permissions on configuration file `/home/.gnupg/gpg.conf'
Cleaning up prefix "." components main...
Publish for snapshot ./xenial [amd64] publishes {main: [abc-stable_2023.01.02-09.23.36]: Snapshot from local repo [stable]: Repository} has been successfully switched to new snapshot.
Cleaning up project directory and file based variables
00:00
Job succeeded
Any idea how to fix this? Like it should fail if there is an error! Can anyone also please explain why it has this behaviour whereas it's the default thing that gitlab pipeline shows error whenever one job fails.
Edit 1:
here is the job which is causing the issue
deploy-on:
stage: deploy
image: ubuntu:20.04
before_script:
- apt-get update
- apt-get install sshpass -y
- apt-get install aptly -y
- apt-get install sudo -y
script:
- pOSOP=publisher
- unstableOrStable=stable
- chmod +x ./pushToServer.sh
- ./publishToServer.sh
here is the pushToServer.sh
#!/bin/bash
cat build.env
DebFileNameW=$(cat build.env | grep DebFileNameW | cut -d = -f2)
echo "DebFileNameW=" $DebFileNameW
sshpass -p pass ssh -oStrictHostKeyChecking=no $pOSOP '
echo "ECHO mkdir -p /home/packages/"
mkdir -p /home/packages/
exit
'
sshpass -p pass scp -oStrictHostKeyChecking=no build/$DebFileNameW.deb $pOSOP:/home/packages/
echo "making time"
file_name=$DebFileNameW
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
sshpass -p pass ssh -t -oStrictHostKeyChecking=no $pOSOP '
echo "doing cd"
cd /home/packages
echo "ECHO sudo aptly repo add '$unstableOrStable' '$file_name'.deb"
sudo aptly repo add '$unstableOrStable' '$file_name'.deb
'
Edit 2:
At the second last line in pushToServer.sh file, i.e., after line sudo aptly repo add '$unstableOrStable' '$file_name'.deb and before last line which is ', I added these two ways get this done, but still it is not working:
Way 1:
if [[ ! $? -eq 0 ]]; then
print_error "The last operation failed."
exit 1
fi
Ways 2:
retVal=$?
echo "ECHOO exit status" $retVal
if [ $retVal -ne 0 ]; then
echo "<meaningful message>"
exit $retVal
fi
With both the ways it is not working. And the same error.
Output:
ECHO sudo aptly repo add stable abc.deb
Loading packages...
[!] Unable to process abc.deb: stat abc.deb: no such file or directory
ERROR: some files failed to be added
[!] Some files were skipped due to errors:
abc.deb
ECHO sudo aptly snapshot create abc-stable_2023.01.05-05.59.44 from repo stable
Snapshot abc-stable_2023.01.05-05.59.44 successfully created.
You can run 'aptly publish snapshot abc-stable_2023.01.05-05.59.44' to publish snapshot as Debian repository.
ECHO sudo aptly publish -passphrase=12345 switch xenial abc-stable_2023.01.05-05.59.44
Loading packages...
Generating metadata files and linking package files...
Finalizing metadata files...
Signing file 'Release' with gpg, please enter your passphrase when prompted:
gpg: WARNING: unsafe permissions on configuration file `/home/publisher/.gnupg/gpg.conf'
gpg: WARNING: unsafe enclosing directory permissions on configuration file `/home/publisher/.gnupg/gpg.conf'
gpg: WARNING: unsafe permissions on configuration file `/home/publisher/.gnupg/gpg.conf'
gpg: WARNING: unsafe enclosing directory permissions on configuration file `/home/publisher/.gnupg/gpg.conf'
Clearsigning file 'Release' with gpg, please enter your passphrase when prompted:
Cleaning up prefix "." components main...
Publish for snapshot ./xenial [amd64] publishes {main: [abc-stable_2023.01.05-05.59.44]: Snapshot from local repo [stable]: Repository} has been successfully switched to new snapshot.
ECHOO exit status 0
Cleaning up project directory and file based variables
00:00
Job succeeded
Please note: I have done echo "ECHOO exit status" $retVal statement, and it shows exit status 0, which means $? doesn't have the right value itself. I have expecting $retVal which is '$?', to be 1 or something other than 0(Success) to get it worked.
Any Pointers?
So I have been trying with multiple different ways mentioned in comment replies and my Edits. Nothing worked. So I was able to solve it this way as mentioned here.
I just put these lines at the starting of my script after #!/bin/bash
#!/bin/bash
set -e
set -o pipefail

/bin/sh: 1: fabric: Permission denied when commit some changes to local repo

Today when I commit some git changes to local repo like this in GitHub Codespaces terminal:
git commit -m "feat: enable the editor pick button"
shows error like this:
#jiangxiaoqiang ➜ /workspaces/react-admin (umi) $ git commit -m "feat: enable the editor pick button"
.git/hooks/pre-commit: 9: [: pre-commit: unexpected operator
.git/hooks/prepare-commit-msg: 9: [: prepare-commit-msg: unexpected operator
.git/hooks/commit-msg: 9: [: commit-msg: unexpected operator
> running commit-msg hook: fabric verify-commit
/bin/sh: 1: fabric: Permission denied
commit-msg hook failed (add --no-verify to bypass)
why did this happen? what should I do to avoid this problem? this is hte commit-msg hooks:
#jiangxiaoqiang ➜ /workspaces/react-admin/.git/hooks (umi) $ cat commit-msg
#!/bin/sh
#yorkie 2.0.5
command_exists () {
command -v "$1" >/dev/null 2>&1
}
has_hook_script () {
if [ $1 == 'pre-commit' ];then
return 0
fi
[ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:"
}
# OS X and Linux only
load_nvm () {
# If nvm is not loaded, load it
command_exists nvm || {
export NVM_DIR="$1"
[ -s "$1/nvm.sh" ] && . "$1/nvm.sh"
}
}
# OS X and Linux only
run_nvm () {
# If nvm has been loaded correctly, use project .nvmrc
command_exists nvm && [ -f .nvmrc ] && nvm use
}
cd "."
# Check if commit-msg is defined, skip if not
has_hook_script commit-msg || exit 0
# Add common path where Node can be found
# Brew standard installation path /usr/local/bin
# Node standard installation path /usr/local
export PATH="$PATH:/usr/local/bin:/usr/local"
# Try to load nvm using path of standard installation
load_nvm /home/codespace/.nvm
run_nvm
# Export Git hook params
export GIT_PARAMS="$*"
# Run hook
node "./node_modules/#umijs/yorkie/src/runner.js" commit-msg || {
echo
echo "commit-msg hook failed (add --no-verify to bypass)"
exit 1
}

How to copy a couchdb in dokku

I want to take a snapshot of one database running in app www and put it into app staging. When I do that with clone or create/import none of the data is available.
How am I meant to do it?
matt#server:~$ dokku run www curl http://www:password#dokku-couchdb-www:5555/www
{"db_name":"www","doc_count":4966,"doc_del_count":232,"update_seq":46475,"purge_seq":0,"compact_running":false,"disk_size":3071180923,"data_size":334987077,"instance_start_time":"1500006610823893","disk_format_version":6,"committed_update_seq":46475}
So from that you can see there are 4966 documents.
matt#server:~$ dokku couchdb:clone www staging_www
-----> Starting container
Waiting for container to be ready
=====> CouchDB container created: staging_www
DSN: http://staging_www:password#dokku-couchdb-staging-www:5555/staging_www
-----> Copying data from www to staging_www
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1110M 0 1110M 0 0 30.4M 0 --:--:-- 0:00:36 --:--:-- 31.9M
-----> Done
So there are no errors in the clone. Then I run
dokku couchdb:link staging_www staging
dokku couchdb:promote staging_www staging
And there are no errors, but if I check the DB:
matt#server:~$ dokku run staging curl http://staging_www:password#dokku-couchdb-staging-www:5555/staging_www
{"db_name":"staging_www","doc_count":1,"doc_del_count":0,"update_seq":1,"purge_seq":0,"compact_running":false,"disk_size":4188,"data_size":342,"instance_start_time":"1509536857606369","disk_format_version":6,"committed_update_seq":1}
The doc count is 1 and I can't access any of the data in the staging app.
Equally I have tried
dokku couchdb:export www > www.couch
dokku couchdb:create staging_www
dokku couchdb:import staging_www < www.couch
dokku couchdb:link staging_www staging
dokku couchdb:promote staging_www staging
There are no errors, but again I end up with 1 doc in the database.
What am I meant to do?
With dokku 0.9.4 and 'dokku couchdb service plugin' 1.0.0
Solution is quite simple. After the first attempt
root#dokku01:~# dokku couchdb:clone www staging_www
and fail to clone db. You need to destroy staging_www
root#dokku01:~# dokku couchdb:destroy staging_www
and do cloning again.
root#dokku01:~# dokku couchdb:clone www staging_www
Now it will works as expected. You can check new db with
root#dokku01:~# curl -X GET 'http://staging_www:password#dokku-couchdb-staging-www:5555/staging_www/_all_docs?include_docs=true&attachments=true'
Exporting from www and then importing a dump in newly created staging_www also works.
It's a bug in CouchDB plugin and it will be quite fun to find what is the root cause of it.
UPDATE
The root cause of this bug is bash script for backup and restore 'couchdb-backup'. In some cases a 'curl calls' inside the script fail to reach the db and consequently a restore operation doesn't work.
Cloning db is: create new instance, export (backup) old data and then import (restore) that backup in the new db.
Script below is updated 'clone' script from couchdb service plugin. It's made more resilient to 'couchdb-backup' import quirks.
#!/usr/bin/env bash
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
service-clone-cmd() {
#E you can clone an existing service to a new one
#E dokku $PLUGIN_COMMAND_PREFIX:clone lolipop lolipop-2
#A service, service to run command against
#A new-service, name of new service
declare desc="create container <new-name> then copy data from <name> into <new-name>"
local cmd="$PLUGIN_COMMAND_PREFIX:clone" argv=("$#"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1" NEW_SERVICE="$2" CLONE_FLAGS_LIST="${#:3}"
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
[[ -z "$NEW_SERVICE" ]] && dokku_log_fail "Please specify a name for the new service"
verify_service_name "$SERVICE"
PLUGIN_IMAGE=$(service_version "$SERVICE" | grep -o "^.*:" | sed -r "s/://g")
PLUGIN_IMAGE_VERSION=$(service_version "$SERVICE" | grep -o ":.*$" | sed -r "s/://g")
service_create "$NEW_SERVICE" "${#:3}"
dokku_log_info1 "Copying data from $SERVICE to $NEW_SERVICE"
attempts=5
attemptcount=0
R=2
succ_str=' Successfully.'
until [[ $R = 0 || $R = 1 ]]; do
attemptcount=$((attemptcount+1))
STDOUT1=$(service_export "$SERVICE" | service_import "$NEW_SERVICE" 2>&1) || true
if [[ ! "$STDOUT1" = *"${succ_str}" ]]; then
if [ $attemptcount = $attempts ]; then
R=1
echo -e "\nERROR: CouchDB Import failed - Stopping\n"
else
echo -e "\nWARN: CouchDB Import Reported an error - Attempt ${attemptcount}/${attempts} - Retrying...\n"
sleep 1
fi
else
R=0
fi
done
dokku_log_info1 "Done"
exit $R
}
service-clone-cmd "$#"
Old version at /var/lib/dokku/plugins/available/couchdb/subcommands/clone should be replaced with this new one.
I usually just use the couchdb dokku plugin found here
Curl can have a tendency to timeout with multiple files, so I use the plugin to stage. Easy peasy

Installing and running .sh file in linux mint

I'm using Linux mint and I want to install COMSOL. The problem is that, when I run below code in terminal, there is an error which doesn't make sense. Could anyone solve the problem?
The code I wrote:
./COMSOL_Server_Workaround.sh
the error is:
COMSOL Server Installer Work-around Script
2016 TeAM SolidSQUAD-SSQ
./COMSOL_Server_Workaround.sh: 14: [: Linux: unexpected operator
./COMSOL_Server_Workaround.sh: 15: [: Linux: unexpected operator
-e ERROR: This script should be executed
from the COMSOL Server installation directory
(where comsolsetup.log resides)
picture of files
COMSOL_Server_Workaround.sh contains:
#!/bin/sh
echo
echo COMSOL Server Installer Work-around Script
echo 2016 TeAM SolidSQUAD-SSQ
echo
# assume working dir is COMSOL installation root
COMSOLROOT="$PWD"
# check architecture
[ "`uname`" == "Linux" ] && COMSOL_TARS="fl fl_setup_glnxa64 fl_setup_maclnx fl_jvm_glnxa64 fl_glnxa64 mph_maclnx mph_glnxa64"
[ "`uname`" == "Darwin" ] && COMSOL_TARS="fl fl_setup_maclnx fl_maclnx fl_jvm_maci64 fl_maci64 mph_maclnx mph_maci64"
# tell user he has to run the script from COMSOL Server folder
[ ! -e "$COMSOLROOT/comsolsetup.log" ] && echo -e "ERROR: This script should be executed\n from the COMSOL Server installation directory\n (where comsolsetup.log resides)" && exit 1
# check if we can write to folder
[ ! -w "$COMSOLROOT/comsolsetup.log" ] && echo -e "ERROR: Cannot write to folder \"$COMSOLROOT\".\n If COMSOL Server was installed as root, run this script as root too\n otherwise run it as user which made the installation of COMSOL Server!" && exit 2
# let us extract the source location and check if it accessible
COMSOLDVD="`grep "^cs.installroot" "$COMSOLROOT/comsolsetup.log" | awk '{print $3}'`"
echo "COMSOL SERVER Installation Path = $COMSOLROOT"
echo "COMSOL Server Installation Source Path = $COMSOLDVD"
# check if source is accessible
[ ! -r "$COMSOLDVD/setupconfig.ini" ] && echo "The installaton source \"$COMSOLDVD\" id not accessible! Make sure the DVD is mounted" && exit 3
# now start untaring FL archives
for COMSOL_TAR in $COMSOL_TARS
do
tar -xf "$COMSOLDVD/archives/$COMSOL_TAR.isa" -C "$COMSOLROOT"
done
# Null the bin\tomcat\conf\login.properties
echo > "$COMSOLROOT/bin/tomcat/conf/login.properties"
# Mission complete
echo
echo All done! Enjoy!
echo
exit 0

Shell script to verify docker installation on Linux

I want to write a shell script which verifies whether docker is installed or not.
If docker is installed:
$ docker -v
Docker version 1.7.0, build 0baf609
$ echo $?
0
If docker is not installed:
$ docker -v
The program 'docker' is currently not installed. You can install it by typing:
apt-get install docker
$ echo $?
127
Here is my script:
#!/bin/bash
docker -v
if echo $? = 128 ; then
echo "The program 'docker' is currently not installed."
else
echo "Continuing with dockerized way"
fi
here for testing purpose, I ran it on the machine where docker is not installed, I kept 127 = 128, condition is wrong, so it should go in else, but still it prints The program 'docker' is currently not installed. I would like to know what I am missing here.
The correct syntax is:
if [ $? -eq 128 ]; then
...
To make it even more robust, you might want to check:
if [ $? -ne 0 ]; then
...

Resources