parse qmake output from bash script - bash

How can I extract the Qt version from a bash script using
qmake -v?
[newton#plex .home] qmake -v
Qmake version: 1.07a (Qt 3.3.6)
Qmake is free software from Trolltech AS.
[newton#plex .home]
edit
sorry, i'm looking for 2.3.6

qmake -v | grep -m1 -o -P "\(Qt [^\)]+" | cut -d" " -f2

Related

How to install GNU grep on Mac OS?

I need to install GNU grep on my Mac but I'm finding some difficulties.
I tried doing this:
brew install grep --with-default-names
But this is no longer an option since Homebrew removed --with-default-names.
Can anyone provide a solution for this?
Yes, --with-default-names was removed.
But some formulas, like grep, provided a workaround for this:
$ brew info grep
...
==> Caveats
All commands have been installed with the prefix "g".
If you need to use these commands with their normal names, you
can add a "gnubin" directory to your PATH from your bashrc like:
PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"
...
First, to install, just do install without --with-default-names.
$ brew install grep
...
==> Summary
🍺 /usr/local/Cellar/grep/3.3: 21 files, 880.7KB
You should also see that same "Caveats" info I mentioned at the start. Now, by default, the Homebrew grep would be prefixed by a "g", so it's accessible as ggrep.
$ ggrep -V
ggrep (GNU grep) 3.3
Packaged by Homebrew
Copyright (C) 2018 Free Software Foundation, Inc.
...
This prevents it from shadowing the built-in grep that comes with Mac.
$ grep -V
grep (BSD grep) 2.5.1-FreeBSD
If you really need to use grep and not ggrep, just follow the instructions and put /usr/local/opt/grep/libexec/gnubin at the start of your PATH. You have to do this in your .bashrc or .bash_profile (whichever one you use).
$ echo 'export PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile
$ grep -V
grep: warning: GREP_OPTIONS is deprecated; please use an alias or script
grep (GNU grep) 3.3
Packaged by Homebrew
...

Installing latest docker compose on Ubuntu

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

How to set up OSX dev machines to install clean at a specific time

Does anyone know an easy way to set up OSX dev machines to install xcode and set up a clean dev environment every morning at 5am?
I was looking at using something like boxen, but the problem I was facing is they all need Xcode installed to work.
You can actually automate a lot of the pre-requites for Boxen with scripts, such as automating the Xcode installation step with a script something like this:
#!/bin/sh
# Get and install Xcode CLI tools
OSX_VERS=$(sw_vers -productVersion | awk -F "." '{print $2}')
# on 10.9+, we can leverage SUS to get the latest CLI tools
if [ "$OSX_VERS" -ge 9 ]; then
# create the placeholder file that's checked by CLI updates' .dist code
# in Apple's SUS catalog
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
# find the CLI Tools update
PROD=$(softwareupdate -l | grep "\*.*Command Line" | head -n 1 | awk -F"*" '{print $2}' | sed -e 's/^ *//' | tr -d '\n')
# install it
softwareupdate -i "$PROD" -v
# on 10.7/10.8, we instead download from public download URLs, which can be found in
# the dvtdownloadableindex:
# https://devimages.apple.com.edgekey.net/downloads/xcode/simulators/index-3905972D-B609-49CE-8D06-51ADC78E07BC.dvtdownloadableindex
else
[ "$OSX_VERS" -eq 7 ] && DMGURL=http://devimages.apple.com/downloads/xcode/command_line_tools_for_xcode_os_x_lion_april_2013.dmg
[ "$OSX_VERS" -eq 8 ] && DMGURL=http://devimages.apple.com/downloads/xcode/command_line_tools_for_osx_mountain_lion_april_2014.dmg
TOOLS=clitools.dmg
curl "$DMGURL" -o "$TOOLS"
TMPMOUNT=`/usr/bin/mktemp -d /tmp/clitools.XXXX`
hdiutil attach "$TOOLS" -mountpoint "$TMPMOUNT"
installer -pkg "$(find $TMPMOUNT -name '*.mpkg')" -target /
hdiutil detach "$TMPMOUNT"
rm -rf "$TMPMOUNT"
rm "$TOOLS"
exit
fi

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

Installing eclim on osx 10.8.5 fails - no acceptable grep found

Im trying to install eclim on OSX 10.8.5 and the installer fails because it does not like the grep I have installed.
[ANT][exec]configure: error: no acceptable grep could be found
[ANT][exec] checking for grep that handles long lines and -e...
My grep has -e
SYNOPSIS
grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]
What is going on here?
I ended up fixing this by using macports to install gcc grep. Apparently OSX now uses bsd grep by default and there are differences between the two that gcc was choking on. The part of this that a little ridiculous is that I installed gcc through XCode.

Resources