cpack restrict OS version package can be installed on - centos

I create packages for several OS versions including RHEL7 & RHEL8 (or mostly equally CentOS7 & 8).
It is possible to install a package built for .el7. on .el8. but it will typically not work (for example due to undefined symbols etc).
Ideally I would like to make the installation fail with an error message like "this package is only intend for RHEL7/CentOS7".
How can I do this?
More specifically how can I do this with CPack/CMake?
Bonus points if you can also given an explanation suitable for Debian versions.
Here are some ideas I have so far:
Use dist tags somehow, see:
https://serverfault.com/questions/283330/rpm-spec-conditional-require-based-of-distro-version
Check uname -r at install time in a pre-install script
Part of that answer is here:
How to check os version in rpmbuild spec file
https://unix.stackexchange.com/questions/9296/how-can-i-specify-os-conditional-build-requirements-in-an-rpm-spec-file
I'm not quite sure how to do that using cpack. I do not want to generate a custom spec file as the build machinery is already complex enough.
Another option would be to add a %requires on a package that only exists on RHEL7 but not RHEL8 or visa versa. That package would need to also exist on CentOS and not change in a way that would make the installation fail if it is upgraded. Does anyone know a suitable package to depend on?
For example:
>rpm -q --whatprovides /etc/redhat-release
centos-release-8.2-2.2004.0.1.el8.x86_64
This looks like a good candidate but if I add a dependency on centos-release-8.2 and they later upgrade to centos-release-8.3 or use RedHat instead this will not work.

I did this before by having a stanza in %pre that stopped it:
if [ -n "%{dist}" ]; then
PKG_VER=`echo %{dist} | perl -ne '/el(\d)/ && print $1'`
THIS_VER=`perl -ne '/release (\d)/ && print $1' /etc/redhat-release`
if [ -n "${PKG_VER}" -a -n "${THIS_VER}" ]; then
if [ ${PKG_VER} -ne ${THIS_VER} ]; then
for i in `seq 20`; do echo ""; done
echo "WARNING: This RPM is for CentOS${PKG_VER}, but you seem to be running CentOS${THIS_VER}" >&2
echo "You might want to uninstall these RPMs immediately and get the CentOS${THIS_VER} version." >&2
for i in `seq 5`; do echo "" >&2; done
fi
fi
fi
Remember - you cannot have any user interaction in RPM installation. You could have it fail instead of warn tho; that's up to you.

Related

how to parse package.json version for github "gh release" tag?

I want to create a single command that would do following:
increase the package.json version (I could do this by running npm version patch)
create Github release with that version as tag (not sure how to achieve this step?)
Brownie points if I could supply patch/minor/major flag while running the command so that npm version _flag_ runs instead of always patching.
I'm using gh package https://cli.github.com/manual/gh_release_create
To get the version node -pe "require('./package.json').version"
A script with optional argument as asked, if no args this will do a patch.
Then launch interactive release creation with the new version
#!/bin/sh
if [ $# -eq 0 ]
then
action="patch"
else
case $1 in
minor | major | patch)
action=$1
;;
*)
echo "Unknow $1 command"
return -1
;;
esac
fi
npm version $action
version=`node -pe "require('./package.json').version"`
echo "new version $version"
gh release create $version

tcsh autocompletion for modulefiles

I found this piece of code, which does auto-completion for module files in tcsh at
https://opensource.apple.com/source/tcsh/tcsh-66/tcsh/complete.tcsh.
Could somebody help me understand how the 'alias Compl_module' works?
#from Dan Nicolaescu <dann#ics.uci.edu>
if ( $?MODULESHOME ) then
alias Compl_module 'find ${MODULEPATH:as/:/ /} -name .version -o -name .modulea\* -prune -o -print | sed `echo "-e s#${MODULEPATH:as%:%/\*##g -e s#%}/\*##g"`'
complete module 'p%1%(add load unload switch display avail use unuse update purge list clear help initadd initrm initswitch initlist initclear)%' \
'n%{unl*,sw*,inits*}%`echo "$LOADEDMODULES:as/:/ /"`%' \
'n%{lo*,di*,he*,inita*,initr*}%`eval Compl_module`%' \
'N%{sw*,initsw*}%`eval Compl_module`%' 'C%-%(-append)%' 'n%{use,unu*,av*}%d%' 'n%-append%d%' \
'C%[^-]*%`eval Compl_module`%'
endif
Thanks a lot.
Not sure this Compl_module alias is performing well as it tries to determine all existing modulefiles in modulepaths by just looking at existing files. Modulefiles can also be aliases, symbolic versions and virtual (in newer Modules versions >=4.1), so the Compl_module alias will miss that.
You will find a full completion script for the module command in the source repository of the Modules project.
This completion script calls module avail to correctly get all existing modulefiles in enabled modulepaths.
TCSH completion script is automatically enabled starting Modules version 4.0.

Including some SFTP commands in a Makefile

I use a Makefile to create pdfs of papers I'm working on. I'd also like to use make to upload the latest version to my website, which requires sftp. I though I could do something like this (which words on the command line) but it seems that in make, the EOF is getting ignored i.e., this
website:
sftp -oPort=2222 me#mywebsite.com << EOF
cd papers
put research_paper.pdf
EOF
generates an error message
cd papers
/bin/sh: line 0: cd: papers: No such file or directory
which I think is saying "papers" doesn't exist on your local machine i.e., the 'cd' is being executed locally, not remotely.
Couple of ideas:
use ncftp which every Linux distro as well as brew should have: it remembers 'state' so the cd becomes unnecessary
use scp instead of sftp if possible
write a trivial shell script doing the EOF business and call that
For what it is worth, here is my script to push tarballs to the CRAN winbuilder -- and takes target directory and script as arguments to ncftpput.
#!/bin/bash
function errorexit () {
echo "Error: $1"
exit 1
}
if [ "$#" -lt 1 ]; then
errorexit "Need to specify argument file"
fi
if [ ! -f ${1} ]; then
errorexit "File ${1} not found, aborting."
fi
ncftpput win-builder.r-project.org /R-release ${1}
ncftpput win-builder.r-project.org /R-devel ${1}
I then just do wbput.sh foo_1.2-3.tar.gz and off it goes...
You cannot (normally) put a single command on multiple lines in a Make recipe, so here documents are a no-go. Try this instead:
website: research_paper.pdf
printf 'cd papers\nput $<\n' \
| sftp -oPort=2222 me#mywebsite.com
The target obviously depends on the PDF, so I made it an explicit dependency, as well.

Ctools do not show up in pentaho UI

I am using Pentaho CE 5 on windows. I would like to use CTools but I can't make them show up in the File -> New menu to use them.
Being behind a proxy, I can not use the Marketplace plugin, so I have tried a manual installation.
First, I tried to use the ctools-installer.sh. I have run the following command line in cygwin (wget and unzip are installed):
./ctools-installer.sh -s /cygdrive/d/Users/[user]/Mes\ Programmes/pentaho/biserver-ce/pentaho-solutions/ -w /cygdrive/d/Users/[user]/Mes\ programmes/pentaho/biserver-ce/tomcat/webapps/pentaho/
The script starts, asks me what module I want to install, and begins the downloads.
For each module, I get an output like (set -x added to the script) :
echo -n 'Downloading CDF...' Downloading CDF...+ wget -q --no-check-certificate 'http://ci.analytical-labs.com/job/Webdetails-CDF-5-Release/lastSuccessfulBuild/artifact/bi-platform-v2-plugin/dist/zip/dist.zip'
-O .tmp/cdf/dist.zip SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc syswgetrc = C:\Program Files (x86)\GnuWin32/etc/wgetrc
'[' '!' -z '' ']'
rm -f .tmp/dist/marketplace.xml
unzip -o .tmp/cdf/dist.zip -d .tmp End-of-central-directory signature not found. Either this file is not a zipfile, or it
constitutes one disk of a multi-part archive. In the latter case
the central directory and zipfile comment will be found on the last
disk(s) of this archive. unzip: cannot find zipfile directory in
.tmp/cdf/dist.zip,
and cannot find .tmp/cdf/dist.zip.zip, period.
chmod -R u+rwx .tmp
echo Done Done
Then the script ends. I have seen on this page (pentaho-bi-suite) that it is the normal output. Nevertheless, it seems a bit strange to me and when I start my pentaho server (login: admin/password), I cannot see any new tools in the menus.
After a look to a few other tutorials and the script itself, I have downloaded the .zip snapshots for every tool and unzipped them in the system directory of my pentaho server. Same result.
I would like to make the .sh works, what can I try or adjust ?
Thanks
EDIT 05/06/2014
I checked the dist.zip files dowloaded by the script and they are all empty. It seems that wget cannot fetch the zip files, and therefore the installation fails.
When I try to get any webpage through wget, it fails. I think it is because of the proxy.
Here is my .wgetrc file, located in my user's cygwin home folder:
use_proxy=on
http_proxy=http://[url]:[port]
https_proxy=http://[url]:[port]
proxy_user=[user]
proxy_password=[password]
How could I make this work?
EDIT 10/06/2014
In the end, I have changed my network connection settings to bypass the proxy. It seems that there is an offline mode for the installer, so one can download all needed files on a proxy-free environment and then run the script offline.
I guess this is related with the -r option.
I consider this post solved, since it not a CTools issue anymore.
Difficult to identify the issue in the above procedure..
but you can refer this blog he is key member of pentaho itself..
In the end, I have changed my network connection settings to bypass the proxy. It seems that there is an offline mode for the installer, so one can download all needed files on a proxy-free environment and then run the script offline. I guess this is related with the -r option.
I consider this post solved, since it is not a CTools issue anymore.
You can manually install the components from http://www.webdetails.pt/ctools/ or if you have pentaho 5.1 or above, you add the following parameters to CATALINA_OPTS option (in start-pentaho.bat or start-pentaho.sh):
-Dhttp.proxyHost= -Dhttp.proxyPort= -Dhttp.nonProxyHosts="localhost|127.0.0.1|10...*"
http://docs.treasuredata.com/articles/pentaho-dataintegration#tips-how-can-i-use-pentaho-through-a-proxy

Delete App (.apk) in emulator?

I know of two ways of deleting an app under development from the emulator:
Using the emulator GUI: Settings >
Applications > Manage Applications >
Uninstall
Using ADB: adb uninstall
I may have discovered a third way, using 'adb shell':
rm /data/app/<package>.apk
It seems, however, that this isn't really a good way to delete apps because there may be additional information associated with it (registration?).
What is that information and where can it be found?
It's interesting you mention this. I ran a quick home made test to shed some light onto your question.
Generally, when you install a .apk file, Android creates an internal storage area for it located at /data/data/< package name of launching activity>. This is mainly used as an internal caching area that cant be accessed by other apps or the phone user. You can read up about that in a little bit more detail in the Internal storage chapter of Androids data storage section. It is an area exclusively used by your app and you can write private data there.
Once you uninstall an app theoretically, this internal storage area is also deleted. The first 2 ways which you outlined indeed does that: the .apk file in /data/app/ is deleted aswell as the internal storage area in /data/data/.
However if you used adb shell and run the rm command, all that is removed is the .apk file in /data/app/. The internal storage area in in /data/data/ is not deleted. So in essence you are correct that additional information with the app is not necessarily deleted. But on the flip side, if you reinstall the app after running the command, then the existing internal storage area gets overwritten as a fresh copy of it is being installed.
adb uninstall com.example.test
com.example.test may vary acording to your app.
I was having a problem with this too. I have Link2SD on my phone, but the ext4 partition on my SD card corrupted, so I reformatted, but all of the linked files were still in the /data/app folder. So I created a script to delete all broken links, and ran into the same problem as you, the app manager said they were still installed! so I made another script to fix that, using the pm program on your phone.
heres my code to remove broken links from the app folder:
fixln.sh
#!/system/bin/sh
#follow and fix symlinks
appfolder="/data/app/"
files=`ls ${appfolder}*`
fix=$1
badstring="No such file or directory"
for i in $files
do
if [ -h $i ]
then
if [ -a `readlink $i` ]
then
echo -e "\e[32m$i is good\033[0m";
else
if [ $fix == "fix" ]
then
`rm $i`
echo -e "\e[31m$i is bad, and was removed\033[0m";
else
echo -e "\e[31m$i is bad\033[0m";
if
fi
else
echo -e "\e[36m$i is not a symlink\033[0m";
fi
done
and heres my code to uninstall apps that have no apk:
fixmissing.sh
#!/system/bin/sh
#searches through a list of installed apps, and removes the ones that have no apk file
appfolder="/data/app/"
fix=$1
installed=`pm list packages -f -u`
for i in $installed
do
usefull=${i#*:}
filename=${usefull%=*}
package=${usefull#*=}
if [ -a $filename ]
then
echo -e "\e[32m$package ($filename) is good\033[0m"
else
if [ "$fix" == "fix" ]
then
uninstall=`pm uninstall $package`
if [ "$uninstall" == "Success" ]
then
echo -e "\e[31m$package ($filename) is bad, and was removed\033[0m"
else
echo -e "\e[31m$package ($filename) is bad, and COULD NOT BE REMOVED\033[0m"
fi
else
echo -e "\e[31m$package ($filename) is bad\033[0m"
fi
fi
done
copy these files to your phone, and run them with no arguments to see what they find, or add fix onto the end (fixmissing.sh fix) to make them fix what they find. Run at your own risk, and back up your files. I am not responsible if this code in any way wrecks anything.
If anyone wants to update/merge these scripts together, thats fine. these were just made to fix my problem, and they have done so, just thought I'd share them.
I believe any files the app has created on the sdcard would not be deleted.
There is another way - using the emulator like a real device -
locate the app in the emulator and drag it up to uninstall it.