Installing heroku-toolbelt in vrtual env - virtualenv

I need to install heroku-toolbelt without sudo. I am trying to install it in virtual env.
I modified install.sh file (changed paths)
> #!/bin/bash {
> HEROKU_CLIENT_URL="https://s3.amazonaws.com/assets.heroku.com/heroku-client/heroku-client.tgz"
>
> echo "This script requires superuser access to install software."
> echo "You will be prompted for your password by sudo."
>
> # clear any previous sudo permission
> #sudo -k
>
> # run inside sudo
> #sudo sh <<SCRIPT
>
> # download and extract the client tarball rm -rf
> /users/user/Documents/mypy/usr/local/heroku mkdir -p
> /users/user/Documents/mypy/usr/local/heroku cd
> /users/user/Documents/mypy/usr/local/heroku
>
> if [[ -z "$(which wget)" ]]; then
> curl -s $HEROKU_CLIENT_URL | tar xz else
> wget -qO- $HEROKU_CLIENT_URL | tar xz fi
>
> mv heroku-client/* . rmdir heroku-client
>
> SCRIPT
>
> # remind the user to add to $PATH
> if [[ ":$PATH:" != *":/users/user/Documents/mypy/usr/local/heroku/bin:"* ]]; then echo "Add the Heroku CLI to your PATH using:" echo "$ echo
> 'PATH=\"/users/user/Documents/mypy/usr/local/heroku/bin:\$PATH\"' >>
> ~/.profile"
> fi
>
> echo "Installation complete" }
But the script is not working.

I had a similar issue when installing the tool belt in a unbuntu vitural env using PuTTY as the SSH. Before I installed I used the command sudo -k to clear permissions before pasting the link. I know that should not be an issue since it is int he script but it worked. I hope it helps.

Related

How to make Code Runner run in external terminal (Command Prompt)?

So, basically the Code Runner in Visual Studio Code can run in the integrated terminal. How can I make it to run in external terminal, which is command prompt because I need to present my program's output to my classmates, so it's not convenient to display it through the integrated one.
I know there's a software like Dev-C++ that can run in external terminal, but I love to use this VS Code because of its clean UI, and the Code Runner plugin is pretty good doing its job. How can I do it just with one-click? Is there any configuration?
Supposing that you are using Windows, All you need to do is to put the "start" command before the .exe file you want to run in the code-runner.executorMap option. Here is an example:
"code-runner.executorMap": {
"cpp": "g++ $fullFileName -o $fileNameWithoutExt.exe && start $fileNameWithoutExt.exe"
}
If anybody wondering how to edit "code-runner.executorMap"":{} nether of above answers provide a way to get into settings.json. So I'm writing this answer just to clarify how you can get into the code runner settings.
go to the File -> Preferences -> Settings and search for 'executorMap' in search tab -> then click Code-runner:Executor Map and edit the code as follows for C,
"code-runner.executorMap": {
"c": "g++ $fullFileName -o $fileNameWithoutExt.exe && start $fileNameWithoutExt.exe"
}
For C++ edit the code as follows,
"code-runner.executorMap": {
"cpp": "g++ $fullFileName -o $fileNameWithoutExt.exe && start $fileNameWithoutExt.exe"
}
Note: This solution is for windows environments
On Windows, when Default Shell, in VSCode, is set to PowerShell 7 (pwsh.exe) I use:
"code-runner.executorMap": {
"c": "cd $dir && gcc -Wall -Wextra -pedantic -std=c18 $fileName -o $fileNameWithoutExt.exe && Start-Process -FilePath pwsh -ArgumentList \"-Command &{.\\$fileNameWithoutExt.exe; pause}\"",
}
When Default Shell, in VSCode, is set to Command Prompt (cmd.exe) I use
"code-runner.executorMap": {
"c": "cd $dir && gcc -Wall -Wextra -pedantic -std=c18 $fileName -o $fileNameWithoutExt.exe && Start pwsh -Command \"& {.\\$fileNameWithoutExt.exe; pause}\"",
}
In both cases "pause" will keep the external PowerShell 7 terminal open after the code is executed.
For Linux :
If you are running linux then you can paste this in
code-runner.executorMap
If you want to execute your code with gnome terminal:
"code-runner.executorMap": {
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && gnome-terminal -- bash -c './$fileNameWithoutExt ; read line'",
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && gnome-terminal -- bash -c './$fileNameWithoutExt ; read line'",
}
use this if you are running ubuntu or if you have gnome terminal. 'read line' is used to keep the window open untill any key is pressed after the code is executed
If you want to execute your code with Xterm:
"code-runner.executorMap": {
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && xterm -hold ./$fileNameWithoutExt",
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && xterm -hold ./$fileNameWithoutExt"
}
you can use this if you have xterm. -hold flag is used to keep the window open after the code is executed
If you're using Code Runner you can add this to your settings.json:
"code-runner.executorMap":{
"cpp": "cd $dir && g++ -O2 -std=c++17 $fileName -o $fileNameWithoutExt && start cmd \"/k ; $fileNameWithoutExt\""
},
This will keep the cmd after the execution of program.
I don't know why konsole -- bash -c "command" command is now working for kde konsole So, if you use kde then install gnome-terminal first
If you want to run an external terminal then add this to settings.json vscode
"code-runner.runInTerminal": true,
"code-runner.preserveFocus": false,
"code-runner.executorMap": {
"c": "cd $dir && echo $PWD > /tmp/vsDir && echo $fileName > /tmp/vsFile && gnome-terminal -- bash -c 'dir=\"$(cat /tmp/vsDir)\" && cd $dir;File=\"$(cat /tmp/vsFile)\" && gcc $File -lm;./a.out;echo Hit Enter to EXIT;read lines;rm *.out' && exit",
"cpp": "cd $dir && echo $PWD > /tmp/vsDir && echo $fileName > /tmp/vsFile && gnome-terminal -- bash -c 'dir=\"$(cat /tmp/vsDir)\" && cd $dir;File=\"$(cat /tmp/vsFile)\" && g++ $File -lm;./a.out;echo Hit Enter to EXIT;read lines;rm *.out' && exit",
"java": "cd $dir && echo $PWD > /tmp/vsDir && echo $fileName > /tmp/vsFile && echo $fileNameWithoutExt > /tmp/javaRun && gnome-terminal -- bash -c 'dir=\"$(cat /tmp/vsDir)\" && cd $dir;File=\"$(cat /tmp/vsFile)\" && javac $File;binary=\"$(cat /tmp/javaRun)\";java $binary;echo Hit Enter to EXIT;read lines;rm *.class' && exit",
"python": "cd $dir && echo $PWD > /tmp/vsDir && echo $fileName > /tmp/vsFile && gnome-terminal -- bash -c 'cd;source /home/$USER/anaconda3/bin/activate; conda activate MyPy38;dir=\"$(cat /tmp/vsDir)\" && cd $dir;File=\"$(cat /tmp/vsFile)\" && python -u $File;echo Hit Enter to EXIT;read lines' && exit",
},
"terminal.integrated.inheritEnv": false
If you don't want to remove the binary or exe or class file then remove rm *.out or rm *.outor similar commands from it.
For Anaconda Python source /home/$USER/anaconda3/bin/activate; is for activate base anaconda env and then active my env name MyPy38 at conda activate MyPy38;. If you run python from the default python3 and pip libreary then replace the command with
"python": "cd $dir && echo $PWD > /tmp/vsDir && echo $fileName > /tmp/vsFile && gnome-terminal -- bash -c 'cd;dir=\"$(cat /tmp/vsDir)\" && cd $dir;File=\"$(cat /tmp/vsFile)\" && python3 -u $File;echo Hit Enter to EXIT;read lines' && exit",
or, You can use project base python envs "Like suppose python interpreter directory is /From/Base/To/Python/Binary/ directory " so, It will be
"python": "cd $dir && echo $PWD > /tmp/vsDir && echo $fileName > /tmp/vsFile && gnome-terminal -- bash -c 'cd;dir=\"$(cat /tmp/vsDir)\" && cd $dir;File=\"$(cat /tmp/vsFile)\" && /From/Base/To/Python/Binary//python -u $File;echo Hit Enter to EXIT;read lines' && exit",
For those using Xfce terminal on Linux:
This will also pause the terminal after execution, requiring you to press any key to exit. Your program name and path can contain spaces as well.
You can change it to any other language with slight modifications.
"code-runner.executorMap": {
"cpp" : "cd $dir && g++ \"$fileName\" -o \"$fileNameWithoutExt\" && xfce4-terminal -e \"bash -c '\\\"./$fileNameWithoutExt\\\";echo;read -n 1 -s -r -p \\\"Press any key to exit...\\\"'\"",
}

Fetch the latest pkg from github

I use this script to install swiftlint on travis:
set -e
SWIFTLINT_PKG_PATH="/tmp/SwiftLint.pkg"
SWIFTLINT_PKG_URL="https://github.com/realm/SwiftLint/releases/download/0.25.1/SwiftLint.pkg"
wget --output-document=$SWIFTLINT_PKG_PATH $SWIFTLINT_PKG_URL
if [ -f $SWIFTLINT_PKG_PATH ]; then
echo "SwiftLint package exists! Installing it..."
sudo installer -pkg $SWIFTLINT_PKG_PATH -target /
else
echo "SwiftLint package doesn't exist. Compiling from source..." &&
git clone https://github.com/realm/SwiftLint.git /tmp/SwiftLint &&
cd /tmp/SwiftLint &&
git submodule update --init --recursive &&
sudo make install
fi
It's not the best way to always update it if needed in this script - is it possible to point to always the latest released pkg?
You can get info about last release from API: https://api.github.com/repos/realm/SwiftLint/releases/latest
To get tag name:
curl --silent "https://api.github.com/repos/realm/SwiftLint/releases/latest" |
grep -Po '"tag_name": "\K.*?(?=")'
To get download URL for pkg file:
curl --silent "https://api.github.com/repos/realm/SwiftLint/releases/latest" |
grep -Po '"browser_download_url": "\K.*?.pkg(?=")'
Source of one-liners.

Install MongoDB on Debian Buster

How to install the latest MongoDB 3.4 or even 3.6?
They support with Ubuntu, but my server is Debian Buster and I am stuck with MongoDB 3.2.
I don't know if this is a good idea yet, but I just installed it by adding the sid repos and installing using the mongodb-server package. For me this installs version 3.4.18.
I created /etc/apt/sources.list.d/sid.list with:
deb http://deb.debian.org/debian/ sid main
deb-src http://deb.debian.org/debian/ sid main
then did
apt update
apt install mongodb-server
and verified that it's working by connecting with mongo.
I have found the solution for a build script, the description is found here:
https://github.com/patrikx3/docker-debian-testing-mongodb-stable
The description:
Debian Stretch / Buster / Bullseye / Testing MongoDB and MongoDB Tools build stable builder script, what it does as exactly:
It is basically a built for the latest MongoDB for Debian.
The current varsion is the r4.0.x build (release).
Warning It will remove all mongodb* apt packages in ./scripts/build-server.sh and /etc/systemd/system/mongodb-server.service is replaced.
It install the required apt dependencies and generates the SystemD service and makes it enabled.
Check if the build works (building is below). It runs all tests, so if it works, then it really does, actually. If there is an error, of course, you will not deploy on your server. So, if building and testing works, then it puts the binaries as it follow and you are sure and done.
The build as follows build-server.sh:
#!/usr/bin/env bash
# based on https://github.com/mongodb/mongo/wiki/Build-Mongodb-From-Source
# the current directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# if an error exit right away, don't continue the build
set -e
# some info
echo
#echo "Works like command, use a tag: sudo ./scripts/build-server.sh r4.2.0"
echo "Works like command, use a tag: sudo ./scripts/build-server.sh r4.0.12"
echo
# check if we are root
if [[ $EUID -ne 0 ]]; then
echo "This script must be ran via root 'sudo' command or using in 'sudo -i'."
exit 1
fi
# require mongo branch
#if [ -z "${1}" ]; then
# echo "First argument must be the MONGODB_BRANCH for example 'v4.1'"
# exit 1
#fi
#MONGODB_BRANCH="${1}"
# require mongo release
#if [ -z "${2}" ]; then
# echo "The second argument must be the MONGODB_RELEASE for example 'r4.1.0'"
# exit 1
#fi
#MONGODB_RELEASE="${2}"
# require mongo release
if [ -z "${1}" ]; then
echo "The first argument must be the MONGODB_RELEASE for example 'r4.0.12'"
exit 1
fi
MONGODB_RELEASE="${1}"
# delete all mongo other programs, we self compile
apt remove --purge mongo*
# the required packages for debian
apt -y install libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-thread-dev build-essential gcc python scons git glibc-source libssl-dev python-pip libffi-dev python-dev libcurl4-openssl-dev #libcurl-dev
pip install -U pip pyyaml typing
# generate build directory variable
BUILD=$DIR/../build
# delete previous build directory
rm -rf $BUILD/mongo
# generate new build directory
mkdir -p $BUILD
# the mongodb.conf and systemd services files in a directory variable
ROOT_FS=$DIR/../artifacts/root-filesystem
# find out how many cores we have and we use that many
if [ -z "$CORES" ]; then
CORES=$(grep -c ^processor /proc/cpuinfo)
fi
echo Using $CORES cores
# go to the build directory
pushd $BUILD
# clone the mongo by branch
#git clone -b ${MONGODB_BRANCH} https://github.com/mongodb/mongo.git
# clone the mongo by branch
git clone https://github.com/mongodb/mongo.git
# the mongo directory is a variables
MONGO=$BUILD/mongo
# go to the mongo directory
pushd $MONGO
# checkout the mongo release
git checkout tags/${MONGODB_RELEASE}
# hack to old version python pip cryptography from 1.7.2 to use the latest
sed -i 's#cryptography == 1.7.2#\#cryptography == 1.7.2#g' buildscripts/requirements.txt
# this is only because 4.0.12 uses 1.7.2 and
# https://github.com/pyca/cryptography/issues/4193#issuecomment-381236459
# support minimum latest (2.2)
pip install cryptography
# install the python requirements
#pip install -r etc/pip/dev-requirements.txt
pip install -r buildscripts/requirements.txt
# somewhere in the build it says if we install this, it is faster to build
pip2 install --user regex
# build everything
scons all --disable-warnings-as-errors -j $CORES --ssl
# install the mongo programs all
scons install --disable-warnings-as-errors -j $CORES --prefix /usr
# create a copy of the old config
#TIMESTAMP=$(($(date +%s%N)/1000000))
#cp /etc/mongodb.conf /etc/mongodb.conf.$TIMESTAMP.save
# copy the mongodb.conf configured and the systemd service file
# dangerous!!! removed
# cp -avr $ROOT_FS/. /
MONGODB_SERVICE=etc/systemd/system/mongodb-server.service
cp $ROOT_FS/$MONGODB_SERVICE /$MONGODB_SERVICE
chown root:root /$MONGODB_SERVICE
chmod o-rwx /$MONGODB_SERVICE
# generate mongodb user and group
useradd mongodb -d /var/lib/mongodb -s /bin/false || true
# create the required mongodb database directory and add safety
mkdir -p /var/lib/mongodb
chmod o-rwx -R /var/lib/mongodb
chown -R mongodb:mongodb /var/lib/mongodb
# create the required mongodb log directory and add safety
mkdir -p /var/log/mongodb
chmod o-rwx -R /var/log/mongodb
chown -R mongodb:mongodb /var/log/mongodb
# create the required run socket directory and add safety
mkdir -p /run/mongodb
chmod o-rwx -R /run/mongodb
chown -R mongodb:mongodb /run/mongodb
# add safety to the mongodb config file
chmod o-rwx /etc/mongodb.conf || true
chown mongodb:mongodb /etc/mongodb.conf || true
# reload systemd services
systemctl daemon-reload
# enable the mongodb-server
systemctl enable mongodb-server
# start the mongodb-server
#service mongodb-server start
# exit of the mongo directory
popd
# exit the build directory
popd
# delete current build directory
rm -rf $BUILD/mongo
The build as follows build-tools.sh:
#!/usr/bin/env bash
# based on https://github.com/mongodb/mongo-tools
# the current directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# if an error exit right away, don't continue the build
set -e
# some info
echo
echo "Works like command: sudo ./scripts/build-tools.sh r4.0.12"
echo
# check if we are root
if [[ $EUID -ne 0 ]]; then
echo "This script must be ran via root 'sudo' command or using in 'sudo -i'."
exit 1
fi
# require mongo release
if [ -z "${1}" ]; then
echo "The first argument must be the MONGODB_RELEASE for example 'r4.0.12'"
exit 1
fi
MONGODB_RELEASE="${1}"
## delete all mongo other programs, we self compile
##apt remove --purge mongo*
## the required packages for debian
##apt -y install gcc python scons git glibc-source libssl-dev python-pip
apt -y install golang libpcap-dev
export GOROOT=$(go env GOROOT)
# generate build directory variable
BUILD=$DIR/../build/src/github.com/mongodb/
# delete previous build directory
rm -rf $BUILD/mongo-tools
# generate new build directory
mkdir -p $BUILD
# find out how many cores we have and we use that many
CORES=$(grep -c ^processor /proc/cpuinfo)
# go to the build directory
pushd $BUILD
# clone the mongo by branch
git clone https://github.com/mongodb/mongo-tools
# the mongo directory is a variables
MONGO_TOOLS=$BUILD/mongo-tools
# go to the mongo directory
pushd $MONGO_TOOLS
# checkout the mongo release
git checkout tags/${MONGODB_RELEASE}
bash ./build.sh
chown root:adm -R ./bin
chmod o-rwx -R ./bin
chmod ug+rx ./bin/*
cp -r ./bin/. /usr/bin
# for PROGRAM in bsondump mongodump mongoexport mongofiles mongoimport mongoreplay mongorestore mongostat mongotop
# do
# go build -o bin/${PROGRAM} -tags "ssl sasl" ${PROGRAM}/main/${PROGRAM}.go
# done
# exit of the mongo directory
popd
# exit the build directory
popd
# delete current build directory
rm -rf $BUILD/mongo-tools
popd
# delete current build directory
rm -rf $BUILD/mongo-tools

Codenvy add postgresql to the project error

I am new at Codenvy so my question can be very stupid, by the way this is my problem:
I created my project then to add the DB (postgresql) i created a new docker file and i pasted in it the code in this file: https://github.com/codenvy/dockerfiles/blob/master/base/jdk7_postgresql/Dockerfile
I saved it then i ran the project with the runner just created, but i have this error:
[DOCKER] Setting up dh-python (1.20141111-2) ...
[DOCKER] Processing triggers for systemd (215-17+deb8u2) ...
[DOCKER] Processing triggers for libc-bin (2.19-18+deb8u1) ...
[DOCKER] Processing triggers for dbus (1.8.20-0+deb8u1) ...
[DOCKER] Starting PostgreSQL 9.3 database server:
[DOCKER] main
[DOCKER] .
[DOCKER] CREATE ROLE
[DOCKER] ---> 77b708d3360b
[DOCKER] Removing intermediate container cdd908fb498e
[DOCKER] Step 4 : ADD startup.sh /home/user/startup.sh
[DOCKER][ERROR] startup.sh: no such file or directory
[ERROR] We are having trouble starting the runner and deploying application. Either necessary files are missing or a fundamental configuration has changed.
Docker image build failed
Any idea to how can i solve the problem?
thanks in advance!
This PostgresSQL image uses startup.sh script to start postgresql service. You can find it at https://github.com/codenvy/dockerfiles/blob/master/base/jdk7_postgresql/startup.sh
To solve this problem you can either create a new file startup.sh with an identical content in the root of your project, add it as a source (e.g. ADD $src$/startup.sh /home/user/startup.sh). You will also need to inject project sources to make it work as expected, so as a result your Dockerfile may look like this:
FROM codenvy/jdk7
ENV DEBIAN_FRONTEND noninteractive
RUN sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 && \
echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list && \
sudo apt-get update && \
sudo -E bash -c "apt-get install -y python-software-properties software-properties-common postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3 pwgen" && \
sudo service postgresql start && \
CODENVY_POSTGRESQL_PASSWORD=$(pwgen -N 1) && echo "export CODENVY_POSTGRESQL_PASSWORD=$CODENVY_POSTGRESQL_PASSWORD" >> /home/user/.postgresrc && \
CODENVY_POSTGRESQL_DB=testdb_$(pwgen -N 1) && echo "export CODENVY_POSTGRESQL_DB=$CODENVY_POSTGRESQL_DB" >> /home/user/.postgresrc && \
CODENVY_POSTGRESQL_USER=codenvy && echo "export CODENVY_POSTGRESQL_USER=$CODENVY_POSTGRESQL_USER" >> /home/user/.postgresrc && \
sudo -u postgres psql --command "CREATE USER $CODENVY_POSTGRESQL_USER WITH SUPERUSER PASSWORD '$CODENVY_POSTGRESQL_PASSWORD';" && \
sudo -u postgres createdb -O $CODENVY_POSTGRESQL_USER $CODENVY_POSTGRESQL_DB
#Inject project sources
ADD $app$ /home/user/$app$
RUN unzip -q /home/user/$app$ -d /home/user
ENV ARGUMENTS $args$
#Add file to the container
ADD $src$/startup.sh /home/user/startup.sh
RUN sudo chmod +x /home/user/startup.sh
#EXPOSE 5432
CMD sudo /home/user/startup.sh
Or you can simply use Codenvy default PostgreSQL 9.3 + Java 7 runner, which you will find on the Runners panel > Configs tab.

Jenkins build passes when ssh deploy fails

I'm using a here tag in a Jenkins build step to send my deploy commands over ssh, and unfortunately the build is passing even when the commands inside the here tag don't finish successfully:
ssh user#host <<EOF
cd /path/to/app
git pull
bower install
npm install
grunt build
cp -r /path/to/app/dist/* /path/to/dist/
forever restartall
exit
EOF
Is there a better way to approach this problem?
You are not catching any error codes inside your "here document".
Last command is exit and without an exit code, it will default to 0 which is success.
Since the last command of your ssh is a success, the whole command is treated as success, and build is a success.
Easiest way to fix that: chain all commands with && like so:
cd /path/to/app && git pull && bower install && npm install && grunt build && cp -r /path/to/app/dist/* /path/to/dist/ && forever restartall && exit
Best way to fix that: write a proper shell script, with error handling, and execute that. If you are too lazy to error handle every line, you can start the script with set -e which will fail the shell script on any individual error
Edit:
#!/bin/bash
appPath="/path/to/app"
distPath"/path/to/dist"
echo "My great deployment script"
echo "Deploying ${appPath} to ${distPath}
if [[ ! -w "${appPath}" ]]; then
echo "${appPath} is not writable, quitting"
exit 1
else
cd ${appPath} && git pull || { echo "Failed on 'git pull'"; exit 2; }
bower install || { echo "Failed on 'bower install'"; exit 3; }
npm install || { echo "Failed on 'npm install'"; exit 4; }
grunt build || { echo "Failed on 'grunt build'"; exit 5; }
if [[ -w "${distPath}" ]]; then
cp -r ${appPath}/dist/* ${distPath}/ || { echo "Failed on 'copy'"; exit 1 }
forever restartall || { echo "Failed on 'forever restartall'"; exit 6 }
echo "Deployment successful"
exit 0
fi
fi
You then execute it with: ssh user#host 'bash -s' < myfile.sh (if the file is local)
Or if you place the file remotely, then just: ssh user#host '/path/to/remote/myfile.sh'