Setup environment using script in Visual Studio Code - linux

I use remote development in Visual Studio Code for a C++/CMake project. However I need to setup a proper build environment before running cmake.
I know I can setup the environment manually by adding each variable to settings.json, but this is not really viable for me since there are a lot of variables that change frequently.
Is there a way I can have Visual Studio Code source a script before running CMake or automate this in any other way?

curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'

Related

Elastic Enterprise/App search installation problem on ubuntu

I'm running a vagrant box which runs ubuntu inside a vm (using Laravel Homestead box)
I'm trying to install the Elastic App-search product.
The first requirement is to install Elastic search, which i have done multiple times. I did the following steps:
https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
sudo apt-get install apt-transport-https
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
sudo apt-get update && sudo apt-get install elasticsearch
I'm using the systemd configuration:
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
I'm running curl localhost:9200 and everything is working.
Next I try to install elastic app search.
https://www.elastic.co/guide/en/app-search/current/installation.html#installation-self-managed.
Which doesn't have instructions for debian systems. But it does have a .deb install file. I downloaded the file and put it in my project route.
I ran dpkg -i on the file and it seems to have installed. When I run the command to check the file location it shows this:
dpkg -L enterprise-search
/.
/etc
/etc/init.d
/etc/init.d/enterprise-search
/var
/var/log
/var/log/enterprise-search
/usr
/usr/share
/usr/share/enterprise-search
/usr/share/enterprise-search/README.md
/usr/share/enterprise-search/bin
/usr/share/enterprise-search/bin/vendor
/usr/share/enterprise-search/bin/vendor/filebeat
/usr/share/enterprise-search/bin/vendor/filebeat/filebeat-linux-x86_64
/usr/share/enterprise-search/bin/enterprise-search
/usr/share/enterprise-search/filebeat
/usr/share/enterprise-search/filebeat/ecs-template.json
/usr/share/enterprise-search/filebeat/filebeat-ecs.yml
/usr/share/enterprise-search/lib
/usr/share/enterprise-search/lib/require_java_version.sh
/usr/share/enterprise-search/lib/enterprise-search.war
/usr/share/enterprise-search/jetty
/usr/share/enterprise-search/jetty/webserver-ssl.xml
/usr/share/enterprise-search/jetty/webserver-ssl-with-redirect.xml
/usr/share/enterprise-search/jetty/webserver.xml
/usr/share/enterprise-search/LICENSE
/usr/share/enterprise-search/config
/usr/share/enterprise-search/config/env.sh
/usr/share/enterprise-search/config/enterprise-search.yml
/usr/share/enterprise-search/NOTICE.txt
/usr/share/doc
/usr/share/doc/enterprise-search
/usr/share/doc/enterprise-search/changelog.gz
/usr/lib
/usr/lib/systemd
/usr/lib/systemd/system
/usr/lib/systemd/system/enterprise-search.service
I'm not really sure if this is the correct location? I want it to live in the same place as my elasticsearch install, but I'm actually not sure. I did all the next steps for the install process and ran:
./usr/share/enterprise-search/bin/elasticsearch
But this gives me the error:
Could not find java in PATH
I'm very confused by this since the main elasticsearch installation works and that also needs java? Also i want it also to run with systemd auto-enable and i want it to be available with enterprise-search start / stop. Not sure how to handle that.
Looks like it's Debian package, so it's installable on ubuntu, but some things may differ.
I would say you can:
Just switch to using debian VM for this (here you can get vagrant for one: https://app.vagrantup.com/debian/boxes/stretch64 )
Debug. From what I see that package runs elasticsearch-env before it runs itself. Java is looked for like this:
if [ ! -z "$JAVA_HOME" ]; then
JAVA="$JAVA_HOME/bin/java"
JAVA_TYPE="JAVA_HOME"
else
if [ "$(uname -s)" = "Darwin" ]; then
# macOS has a different structure
JAVA="$ES_HOME/jdk.app/Contents/Home/bin/java"
else
JAVA="$ES_HOME/jdk/bin/java"
fi
JAVA_TYPE="bundled jdk"
fi
if [ ! -x "$JAVA" ]; then
echo "could not find java in $JAVA_TYPE at $JAVA" >&2
exit 1
fi
So I would advise to set JAVA_HOME in start script (or before running the binary), and see if that helps.
I solved it by adding another version of Java, Elastichsearch has a java install build-in and not separate, so the app-search install can't reach that version. Feels very dirty but got it working!

Cannot use '--build-native-deps' along with '--build' flag

I'm getting the above error from an Azure DevOps pipeline while deploying python code to Azure functions. The pipeline was previously running without errors (last run 12 days ago). The task code is as follows;
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-$(lsb_release -cs)-prod $(lsb_release -cs) main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-get update
sudo apt-get install azure-functions-core-tools
func azure functionapp publish <app-name> --python --build-native-deps
The last line is throwing the error, but there is no "--build" flag specified, which is is confusing me. Any suggestions?
So seems there is a behavior change on the function core tools after version 2.7.1585-1. The deployment works by removing the "--build-native-deps" flag.

.net-core: Equivalent of ILDASM / ILASM

Is there the equivalent of ILDASM / ILASM for the .net-core?
Specifically, I'm looking for something that runs on Linux (Hence why the .net-core).
Both the ildasm and ilasm tools are built with CoreCLR from this repo: https://github.com/dotnet/coreclr. They include similar functionality as the versions shipped with Windows (sans GUI, etc.).
There are nuget packages shipped that include them as well (https://www.nuget.org/packages?q=ildasm), but they are platform-specific and also require a matching version of CoreCLR to use, so they are not straightforward to consume via nuget. The easiest way to run these on your platform is to just build them from source from the coreclr repo.
It does not appear there is a native Microsoft tool that serves these functions on Linux and it is not currently built into the dot-net-core.
However, Mono allows the assembly and disassembly of IL code:
Installation Instructions can be found here.
What you are looking for is:
ilasm - For assembling
monodis - For disassembling
These are found in the package mono-utils:
e.g. On Debian 8 I did the following:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/debian jessie" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
sudo apt-get update
apt-get install mono-devel mono-utils
However, FYI, for those trying to create exports, Mono does not appear to handle the x64 export syntax.
Let's 'install' ildasm tool using related nuget-package:
define RID (Runtime Identifier)
dotnet --info
# execution result
..
Runtime Environment:
OS Name: ubuntu
OS Version: 18.04
OS Platform: Linux
RID: ubuntu.18.04-x64 # <----
..
download the package runtime.{RID}.Microsoft.NETCore.ILDAsm. For my case it is: runtime.ubuntu.18.04-x64.Microsoft.NETCore.ILDAsm
unarchive it and extract executable file '/runtimes/{RID}/native/ildasm'
grant it execution permission and copy to .NET runtime folder (call dotnet --list-runtimes to list runtimes)
chmod +x ildasm
sudo mv ildasm /usr/share/dotnet/shared/Microsoft.NETCore.App/{version}/
create symlink
ln -s /usr/share/dotnet/shared/Microsoft.NETCore.App/{version}/ildasm ildasm
run ildasm
./ildasm {path}/project.dll >> {path}/project.il
The same steps are applicable for ilasm.
As an alternate way consider using dotnet-ildasm tool:
# install .net core runtime if required
# sudo apt-get update; \
# sudo apt-get install -y apt-transport-https && \
# sudo apt-get update && \
# sudo apt-get install -y dotnet-runtime-3.0
# find required tool
dotnet tool search ildasm
# output:
# Package ID Latest Version Authors Downloads Verified
# ---------------------------------------------------------------------------
# dotnet-ildasm 0.12.2 pjbgf 100154
# dotasm 1.0.1 DotAsm 434
# install tool
dotnet tool install -g dotnet-ildasm
Output IL to file:
# go to project folder
cd ../project/bin/Debug/netx.x
dotnet ildasm program.dll -o program.il

Can I use Homebrew on Ubuntu?

I just tried to use Homebrew and Linuxbrew to install packages on my Ubuntu Server but both failed. This is how I tried to install them:
sudo apt-get install build-essential curl git m4 ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"
I got the following warning:
Warning: /home/tong/.linuxbrew/bin is not in your PATH.
I vi my bash.bashrc in home/etc and add this:
export PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"
Then I tried brew doctor but got No command 'brew' found. How am I able to use Homebrew on Ubuntu?
As of February 2018, installing brew on Ubuntu (mine is 17.10) machine is as simple as:
sudo apt install linuxbrew-wrapper
Then, on first brew execution (just type brew --help) you will be asked for two installation options:
me#computer:~/$ brew --help
==> Select the Linuxbrew installation directory
- Enter your password to install to /home/linuxbrew/.linuxbrew (recommended)
- Press Control-D to install to /home/me/.linuxbrew
- Press Control-C to cancel installation
[sudo] password for me:
For recommended option type your password (if your current user is in sudo group), or, if you prefer installing all the dependencies in your own home folder, hit Ctrl+D. Enjoy.
I just tried installing it using the ruby command but somehow the dependencies are not resolved hence brew does not completely install. But, try installing by cloning:
git clone https://github.com/Homebrew/linuxbrew.git ~/.linuxbrew
and then add the following to your .bash_profile:
export PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"
It should work..
as of august 2020 (works for kali linux as well)
sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
export brew=/home/linuxbrew/.linuxbrew/bin
test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)
test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile // for ubuntu and debian
The following steps worked for me:
Clone it from github
git clone https://github.com/Homebrew/linuxbrew.git ~/.linuxbrew
Open your .bash_profile file using vi ~/.bash_profile
Add these lines
export PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"
Then type the following lines in your terminal
export PATH=$HOME/.linuxbrew/bin:$PATH
hash -r
Yes, it is done. Type brew in your terminal to check its existence.
You can just follow instructions from the Homebrew on Linux docs, but I think it is better to understand what the instructions are trying to achieve.
Understanding the installation steps can save some time
Step 1: Choose location
First of all, it is important to understand that linuxbrew will be installed on the /home directory and not inside /home/your-user (the ~ directory).
(See the reason for that at the end of answer).
Keep this in mind when you run the other steps below.
Step 2: Add linuxbrew binaries to /home :
The installation script will do it for us:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 3: Check that /linuxbrew was added to the relevant location
This can be done by simply navigating to /home.
Notice that the docs are showing it as a one-liner by adding test -d <linuxbrew location> before each command.
(Read more about the test command in here).
Step 4: Export relevant environment variables to terminal
We need to add linuxbrew to PATH and add some more environment variables to the current terminal.
We can just add the following exports to terminal (wait don't do it..):
export PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin${PATH+:$PATH}";
export HOMEBREW_PREFIX="/home/linuxbrew/.linuxbrew";
export HOMEBREW_CELLAR="/home/linuxbrew/.linuxbrew/Cellar";
export HOMEBREW_REPOSITORY="/home/linuxbrew/.linuxbrew/Homebrew";
export MANPATH="/home/linuxbrew/.linuxbrew/share/man${MANPATH+:$MANPATH}:";
export INFOPATH="/home/linuxbrew/.linuxbrew/share/info:${INFOPATH:-}";
Or simply run (If your linuxbrew folder is on other location then /home - change the path):
eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
(*) Because brew command is not yet identified by the current terminal (this is what we're solving right now) we'll have to specify the full path to the brew binary: /home/linuxbrew/.linuxbrew/bin/brew shellenv
Test this step by:
1 ) Run brew from current terminal to see if it identifies the command.
2 ) Run printenv and check if all environment variables were exported and that you see /home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin on PATH.
Step 5: Ensure step 4 is running on each terminal
We need to add step 4 to ~/.profile (in case of Debian/Ubuntu):
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >> ~/.profile
For CentOS/Fedora/Red Hat - replace ~/.profile with ~/.bash_profile.
Step 6: Ensure that ~/.profile or ~/.bash_profile are being executed when new terminal is opened
If you executed step 5 and failed to run brew from new terminal - add a test command like echo "Hi!" to ~/.profile or ~/.bash_profile.
If you don't see Hi! when you open a new terminal - go to the terminal preferences and ensure that the attribute of 'run command as login shell' is set.
Read more in here.
Why the installation script installs Homebrew to /home/linuxbrew/.linuxbrew - from here:
The installation script installs Homebrew to
/home/linuxbrew/.linuxbrew using sudo if possible and in your home
directory at ~/.linuxbrew otherwise. Homebrew does not use sudo
after installation. Using /home/linuxbrew/.linuxbrew allows the
use of more binary packages (bottles) than installing in your personal
home directory.
The prefix /home/linuxbrew/.linuxbrew was chosen so that users
without admin access can ask an admin to create a linuxbrew role
account and still benefit from precompiled binaries.
If you do not yourself have admin privileges, consider asking your
admin staff to create a linuxbrew role account for you with home
directory /home/linuxbrew.
Linux is now officially supported in brew - see the Homebrew 2.0.0 blog post. As shown on https://brew.sh, just copy/paste this into a command prompt:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Because all previous answers doesn't work for me for ubuntu 14.04
here what I did, if any one get the same problem:
git clone https://github.com/Linuxbrew/brew.git ~/.linuxbrew
PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$(brew --prefix)/share/man:$MANPATH"
export INFOPATH="$(brew --prefix)/share/info:$INFOPATH"
then
sudo apt-get install gawk
sudo yum install gawk
brew install hello
you can follow this link for more information.
October 2019 - Ubuntu 18.04 on WSL with oh-my-zsh;
the instructions here worked perfectly -
(first, install pre-requisites using sudo apt-get install build-essential curl file git)
finally create a ~/.zprofile with the following contents:
emulate sh -c '. ~/.profile'
Whta to do
cd /home/linuxbrew/.linuxbrew/bin
./brew doctor
You will get what path to export
echo 'export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"' >> ~/.zshrc

How to install Visual Studio Code on Linux?

I have just downloaded VSCode-linux-x64 from the Microsoft website. It's a zip file called VSCode-linux-x64.zip. How can I install it on my Linux system?
From a few pages deeper into the setup docs in the link you offered...
Linux
Download Visual Studio Code for Linux
Make a new folder and extract VSCode-linux-x64.zip inside that folder
Double click on Code to run Visual Studio Code
Tip: If you want to run VSCode from the terminal, create the following
link substituting /path/to/vscode/Code with the absolute path to the
Code executable
sudo ln -s /path/to/vscode/Code /usr/local/bin/code in any folder to start editing files in that
folder.
Now, you can simply type code . in any folder to start editing files
in that folder.
I found the answer to my question and posting the answer so it can help others.
To download and install Visual Studio Code on Ubuntu . follow the steps below
Download Visual Studio Code for Linux
Extract the zip file VSCode-linux-x64.zip
Go inside the folder VSCode-linux-x64
double click and Run code executable to open Visual Studio Code .
You can right click on Visual Studio Code on toolbar (or launcher)
and select Lock to Launcher. this way you can launch the editor by
clicking it on launcher.
If you are using terminal follow the terminal commands
mkdir your_folder_name && cd your_folder_name unzip
../Downloads/VSCode-linux-x64.zip
./Code
This video will help you to download and install and use Visual Studio Code on Ubuntu if you still have some doubts
After 18.04 version, the following one-line terminal code works well.
sudo snap install code --classic
Installing with apt-get:
Step 1 – Enable Package Repository
Run the following command to enable Visual studio code repository to your system:
echo "deb [arch=amd64] http://packages.microsoft.com/repos/vscode stable main" | sudo \ tee /etc/apt/sources.list.d/vs-code.list
Step 2 – Install Visual Studio Code Editor
Now, Import the package signing gpg key on your system using the following command:
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
Install Visual Studio Code on your Debian based system (like Ubuntu):
sudo apt-get update
sudo apt-get install code
Step 3 – Launch Visual Studio Code and enable its extensions:
Now You can launch the Visual Studio Code editor on your system using the graphical menu.
There are a large number of extensions available for Visual Studio Code like PHP, Python, JavaScript etc. Install the required extensions to enhance your working experience with Visual Studio Code.
Source: https://tecadmin.net/install-visual-studio-code-editor-ubuntu/
Simplest way to install Visual Studio Code in Linux
I hope it useful.
Installing Visual Studio Code in Kali Linux - 4 simple steps
Update your system and install the below package.
sudo apt update
sudo apt install curl gpg software-properties-common apt-transport-https
Importing Microsoft GPG key to Kali Linux
curl -sSL https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
Adding APT repository for VS Code to Kali Linux
echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" | sudo tee /etc/apt/sources.list.d/vscode.list
Installing VS Code
sudo apt update
sudo apt install code
For reference:
https://youtu.be/ycIjQf0rOJI

Resources