Powershell script to install app via choclatey but also check for choclatey is installed if not then it will install it - scripting

I have a script that partially works it will install the app for chocolatey but the ELSE command seems to fail I'm new to scripting so possibly missing something here.
$localprograms1 = choco list --localonly
$program1 = "3cx"
If(Test-Path -Path "$env:ProgramData\Chocolatey")
{
if ($localprograms1 -like "*$program1*")
{
choco upgrade $program1
}
else
{
choco install $program1 -y
}
}
Else
{
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
{
if ($localprograms1 -like "*$program1*")
{
choco upgrade $program1
}
else
{
choco install $program1 -y
}
}
}
it seems to fail at the detection phase

There are a few things I'd suggest
Just from a personal perspective, I would suggest re-ordering this to make it run more seamlessly (and to be a little less repetitive!).
param(
$Program = "3cx"
)
# First, make sure Chocolatey is available - if not, we install it!
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) {
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
# Refresh the environment variables, to make sure choco is available
Import-Module $env:ProgramData\chocolatey\helpers\chocolateyProfile.psm1
Update-SessionEnvironment
}
# Having ensured Chocolatey is available, we can get our list of applications
# Using --limit-output (-r) and converting it from delimited format
$LocalPrograms = choco list --local-only --limit-output | ConvertFrom-Csv -Delimiter '|' -Header Name, Version
# We can now check if the package is present, and can install / upgrade if not
if ($Program -in $LocalPrograms.Name) {
choco upgrade $program1
} else {
choco install $program1 --confirm
}
Having said that, choco upgrade will install or upgrade a program depending on it's presence, so you could replace everything after the installation of Chocolatey with choco upgrade $program1 --confirm.

Related

Yocto include cmake project with custom steps

I am trying to include this simple cmake-based project to my image: https://github.com/MatrixOrbital/HTT-Utility
The steps to build in Linux are:
mkdir build
cd build
cmake ..
make
I am trying to reproduce these steps within my Yocto recipe. The generated binary (./build/htt_util) should be installed in /usr/bin.
So far with the help of devtool and some manual tuning I ended up with this recipe:
LICENSE = "MIT & Unknown"
LIC_FILES_CHKSUM = "file://LICENSE;md5=ff75ee274f4c77abeee3db089083fec7 \
file://hidapi/LICENSE.txt;md5=7c3949a631240cb6c31c50f3eb696077"
SRC_URI = "git://github.com/MatrixOrbital/HTT-Utility.git;protocol=https"
SRC_URI += "file://0001-Adding-ctype.patch;"
PATCHTOOL = "git"
# Modify these as desired
PV = "1.0+git${SRCPV}"
SRCREV = "2045d5eacc67b89a02dafe41edfd032179333aee"
S = "${WORKDIR}/git"
inherit cmake
# Specify any options you want to pass to cmake using EXTRA_OECMAKE:
EXTRA_OECMAKE = ""
DEPENDS += "udev"
What should I add to my recipe to achieve the goal of generating a binary and installing into /usr/bin?
I have been trying to play with:
do_configure() {
...
}
do_compile() {
...
}
do_install() {
...
}
But so far I did not manage to do anything useful.
Any help would be appreciated.
do_install() {
install -m 0644 mybinary ${D}${bindir}
}
FILES_${PN} = " \
${bindir} \
"

how do I echo a message to the terminal at the end of npm install?

I've created a repo I want to be cloned
after cloning, you run npm install
How do I echo a log message to the terminal that will show up at the end of the installation?
In your case, you can add a post-install script, that outputs, for example, a string to the console if you mark a version as alpha.
package.json
{
"version": "1.2.3-alpha.2",
"scripts": {
"postinstall": "node postinstall.js"
}
}
postinstall.js
const package = require('./package.json')
console.log('End of installation');
//Example using properties from package.json
if (package.version.includes('alpha')) {
console.log('Warning: Alpha version!')
}
BONUS
Append this to the command --loglevel verbose and all logs will be saved to npm-debug.log in current working directory.
It will show the logs in realtime + saves the log to directory its running.
You can just edit npm config npm config edit and add loglevel=verbose

npm run <command> not working

With a package.json file like:
{
"scripts": {
"hello": "touch hello && echo hello"
}
}
Running npm run hello creates no file and outputs nothing to stdout. I was expecting both to happen.
npm -v # 4.4.0
ignore-scripts=true was set in .npmrc
https://github.com/npm/npm/issues/10675

Running Nightwatch test inside docker - Selenium server doesn't start

I'm trying to integrate my e2e test in our CI pipeline.
We are using Jenkins as CI and we build a docker image and all the tests are running from the docker.
When trying to run the e2e tests I receive an error stating: "Connection refused! Is selenium server started?"
After building the image and installing all the npm packages I use this command in the Jenkins file:
run_in_stage('End2End test', {
image.inside("-u root") {
sh '''
npm run build:dev
http-server ./dist -p 3001 -s &
xvfb-run --server-args="-screen 0 1600x1200x24" npm run test:e2e:smoke
'''
}
})
In the docker file I set up Chrome with xvfb.
RUN \
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list && \
apt-get update && \
apt-get install -y xvfb google-chrome-stable
This is how I set up the selenium in the nightwatch.conf.js file:
const seleniumServer = require('selenium-server-standalone-jar');
const chromeDriver = require('chromedriver');
selenium: {
start_process: true,
server_path: seleniumServer.path,
host: '127.0.0.1',
port: 4444,
cli_args: {
'webdriver.chrome.driver': chromeDriver.path
}
},

Is that possible to use "Invoke-SqlCmd" as a part of Visual Studio Online build step?

We try to get our DB updated as part of the Visual Studio Online build as dedicated build step, but the PowerShell script that we locally using fails to work on the hosted build controller with following error.
2015-07-28T20:35:26.8546681Z ##[error]import-module : The specified module 'sqlps' was not loaded because no valid module file was found in any module
2015-07-28T20:35:26.8546681Z ##[error]directory.
Is there any way to use "Invoke-SqlCmd" in VSO hosted build controller?
Got it working with those lines!
Add-PSSnapin SqlServerCmdletSnapin100 -ErrorAction SilentlyContinue
Add-PSSnapin SqlServerProviderSnapin100 -ErrorAction SilentlyContinue
Here how I do it:
$moduleName = "SqlServer"
if (Get-Module $moduleName -ListAvailable) {
Write-Host "Module '$moduleName' is available"
} else {
Write-Host "Module '$moduleName' does not exist"
try {
Install-Module -Name $moduleName -Force -AllowClobber
Write-Host "Module '$moduleName' successfully installed"
} catch {
Throw "Installation of module '$moduleName' failed: $($_.Exception)"
}
}