Installing latest docker compose on Ubuntu - bash

I use the following to install the most recent docker compose for my ubuntu server:
curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
How to do I make this more version agnostic. For instance, so that I do not have to go in and keep changing the version -which in this case is 1.21.2. How do I change the command so it gets the most latest stable release?

How do I change the command so it gets the most latest stable release?
You could try following:
curl -L https://github.com/docker/compose/releases/download/`curl -Ls -o /dev/null -w %{url_effective} https://github.com/docker/compose/releases/latest | awk -F / '{print $NF}'`/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
This is same as your script only replacing actual version (1.21.2 in your case) with latest tag over several steps:
First we get redirection url for latest stable:
curl -Ls -o /dev/null -w %{url_effective} https://github.com/docker/compose/releases/latest
currently it resolves to https://github.com/docker/compose/releases/tag/1.21.2
Then we get version tag out of redirection url:
| awk -F / '{print $NF}'
currently resolving to 1.21.2
Finally we execute it in place of version number using your original curl statement. Note that this can break if latest tag is not properly redirected and ads some extra complexity, but automates version pulling as requested.

Accepted answer isn't the latest stable version according to https://docs.docker.com/compose/release-notes/ (returns v2 instead of the latest v1 which I was looking for)
This is the monstrosity I went with
rm -Rf /usr/local/bin/docker-compose && version=$(curl -s https://docs.docker.com/compose/release-notes/ | grep "Docker Compose release notes" | grep "Estimated reading time" | sed 's/.*id=//g' | sed 's/<.*$//g' | sed 's/.*>//g') && curl -L https://github.com/docker/compose/releases/download/${version}/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose

Related

GitHub Action with MacOS-latest : Process completed with exit code 1 : with grep and curl command

Introduction
Currently, I'm writing a customized GitHub workflow inside it I use a curl and grep command.
GitHub repo
action.yml
- name: get new tag
id: get_new_tag
shell: bash
run: |
temp_result=$(curl -s https://api.github.com/repos/${{inputs.github_repository}}/tags | grep -h "name" | grep -h "${{inputs.selector}}" | head -1 | grep -ho "${{inputs.regex}}")
echo "new-tag=${temp_result}" >> $GITHUB_OUTPUT
Full code here
test for action.yml
uses: ./
with:
files: tests/test1.txt tests/test2.txt
github_repository: MathieuSoysal/file-updater-for-release
prefix: MathieuSoysal/file-updater-for-release#
Full code are is here
Problem
I don't understand why but my GitHub Actions don't work with MacOS.
The given error:
temp_result=$(curl -s https://api.github.com/repos/MathieuSoysal/file-updater-for-release/tags | grep -h "name" | grep -h "" | head -1 | grep -ho "v\?[0-9.]*")
echo "new-tag=${temp_result}" >> $GITHUB_OUTPUT
shell: /bin/bash --noprofile --norc -e -o pipefail {0}
Error: Process completed with exit code 1.
Full log error is here
Question
Does someone know how we can fix this issue?
Alternatively, you can simply use the jq command line utility for this which is already installed and available on the GitHub runners. See the preinstalled software.
$ export URL='https://api.github.com/repos/MathieuSoysal/file-updater-for-release/tags'
$ curl -s $URL | jq -r .[0].name
v1.0.3
The issue is from this command grep -h "", this command is not supported on MacOS.
The empty string is not supported, the solution is to add something inside it.

Install CURRENT version of Gradle within CI

Gradle describes their installation in their docs:
https://docs.gradle.org/current/userguide/installation.html
However the docs requires using specific version and there is no easy way to say "get the current version".
I would like to do something like:
export GRADLE_VERSION=`curl https://services.gradle.org/current-version`
curl -sSLO https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip \
&& unzip -q -d /opt/gradle gradle-*.zip \
&& echo "PATH=$PATH:/opt/gradle/gradle-${GRADLE_VERSION}/bin" > ~/.bashrc
Obviously there is no such API service like /current-version. How would you achieve this?
I suggest:
curl -s 'https://services.gradle.org/versions/current' | jq -r '.version'
Output:
7.3.1
or
curl -s 'https://services.gradle.org/versions/current' | jq -r '.downloadUrl'
Output:
https://services.gradle.org/distributions/gradle-7.3.1-bin.zip

Command to show latest Drupal 8 version available

I am looking for a way to display the latest Drupal 8 version available for download in a shell command.
I currently have this command which shows the current version available for the site installed:
drush core-status drupal-version | tr -d "Drupal version : "
This returns
'8.6.13'
I am now looking for a way to obtain the latest version number available to date which is
'8.6.15'
You used to be able to use
drush pm-releases drupal
to get this information. This post mentions using a feed to help get this information:
https://drupal.stackexchange.com/questions/133925/find-latest-drupal-version-number
One way of doing it:
curl -w "%{url_effective}\n" -I -L -s -S https://www.drupal.org/8/download -o /dev/null | awk -F'/' '{print $7}'
composer show -l drupal/core | grep ^latest
See documentation at: https://getcomposer.org/doc/03-cli.md#show
Another option is:
composer outdated -a -D|grep ^drupal/core
You can probably get the complete list of available versions with:
drush php:eval '
$ver = array_keys(
( update_get_available(TRUE) )["drupal"]["releases"]
);
asort($ver);
echo implode("\n",$ver),"\n";
'

Get latest stable helm release

Is there a shell command to get the latest stable helm release .
For kubernetes we have something like this
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
Try:
wget -qO- https://github.com/kubernetes/helm/releases | sed -n '/Latest release<\/a>/,$p' | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' |head -1
Result:
v2.8.2
And, for those without wget:
HVER=$(curl -sSL https://github.com/kubernetes/helm/releases | sed -n '/Latest release<\/a>/,$p' | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | head -1)
echo $HVER
Result (currently):
v2.9.1
To download the gz that contains the latest Helm executable:
Linux
curl -LO https://storage.googleapis.com/kubernetes-helm/helm-${HVER}-linux-amd64.tar.gz
OSX
curl -LO https://storage.googleapis.com/kubernetes-helm/helm-${HVER}-darwin-amd64.tar.gz
Windows (bash ell)
curl -LO https://storage.googleapis.com/kubernetes-helm/helm-${HVER}-windows-amd64.tar.gz
if in-case you use Dockerfile & Linux
RUN wget "https://storage.googleapis.com/kubernetes-helm/helm-$(wget -qO- https://github.com/kubernetes/helm/releases | sed -n '/Latest release<\/a>/,$p' | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' |head -1)-linux-amd64.tar.gz"
For Linux, OSX, and Windows targets:
HELM_INSTALL_DIR=[‘desired path’]
USE_SUDO=[‘true’|’false’]
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
Other install options: Helm Install Documentation
Recommend migration away from V2.x as soon as you can.
The way I do it for v2:
curl -L0 "https://storage.googleapis.com/kubernetes-helm/helm-v${HELM_VERSION}-linux-amd64.tar.gz" | tar xzO linux-amd64/helm > /usr/local/bin/helm
And for v3:
curl -L0 "https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz" | tar xzO linux-amd64/helm > /usr/local/bin/helm
Do not forget to chmod +x /usr/local/bin/helm afterwards.

Automatically Download Latest WhatsApp APK using Shell Scripting

I'm trying to create a cron job that downloads the latest version of WhatsApp's APK from their website using a bash script and make it available through my site.
So far, I'm able to obtain the version number from the site using the following (user-agent part omitted):
wget -q -O - "$#" whatsapp.com/android | grep -oP '(?<=Version )([\d.]+)'
And I can download the APK using the following command:
wget http://www.whatsapp.com/android/current/WhatsApp.apk
That part is fine. What I can't figure out is how to download the APK only if it's newer than the existing APK on the server. How should the script be?
Since I'm not a command-line pro, I guess there's a better way to achieve this than my current approach, so if you have any suggestions, I'd appreciate it very much.
Seems like you need to manage the version yourself.
I would store the apk files with a version number in the filename, e.g WhatsApp_<version-number>_.apk. So the script that downloads the newer file can be as following:
# Get the local version
oldVer=$(ls -v1 | grep -v latest | tail -n 1 | awk -F "_" '{print $2}')
# Get the server version
newVer=$(wget -q -O - "$#" whatsapp.com/android | grep -oP '(?<=Version )([\d.]+)')
# Check if the server version is newer
newestVer=$(echo -e "$oldVer\n$newVer" | sort -n | tail -n 1)
#Download the newer versino
[ "$newVer" = "$newestVer" ] && [ "$oldVer" != "$newVer" ] && wget -O WhatsApp_${newVer}_.apk http://www.whatsapp.com/android/current/WhatsApp.apk || echo "The newest version already downloaded"
#Delete all files that not is a new version
find ! -name "*$newVer*" ! -type d -exec rm -f {} \;
# set the link to the latest
ln -sf $(ls -v1 | grep -v latest| tail -n1) latest

Resources