GNU Make removes downloaded zip files for no apparent reason - linux

I have this makefile tha sthould download and build openssh (along with other things):
ROOT_DIR=$(PWD)
DATA_DIR=$(ROOT_DIR)/data
SOURCES_DIR=$(ROOT_DIR)/sources
RESOURCES_DIR=$(ROOT_DIR)/resources
DRAFTS_DIR=$(ROOT_DIR)/drafts
$(SOURCES_DIR):
mkdir $(SOURCES_DIR)
$(RESOURCES_DIR):
mkdir $(RESOURCES_DIR)
$(DRAFTS_DIR):
mkdir $(DRAFTS_DIR)
openssh-tar-url="ftp://ftp.cc.uoc.gr/mirrors/OpenBSD/OpenSSH/portable/openssh-6.2p2.tar.gz"
TAR_PROJECTS += openssh
openssh:
echo "Building $#"
openssh-clean: openssh-archive-clean
.SECONDEXPANSION :
$(TAR_PROJECTS) : $(SOURCES_DIR) $(SOURCES_DIR)/$$#-archive
$(DRAFTS_DIR)/%.tar.gz: $(DRAFTS_DIR)
echo "Pulling $*."
wget $($*-tar-url) -O $(DRAFTS_DIR)/$*.tar.gz
.SECONDEXPANSION :
$(SOURCES_DIR)/%-archive : | $(DRAFTS_DIR)/$$*.tar.gz
mkdir $#
cd $# && tar xvzf $(DRAFTS_DIR)/$*.tar.gz
%-archive-clean:
rm -rf $(SOURCES_DIR)/$*-archive $(DRAFTS_DIR)/$*.tar.gz
When i run make openssh it runs correctly but at the end it removes the archive it downloaded. This is very strange to me:
$ make openssh --just-print
echo "Pulling openssh."
wget "ftp://ftp.cc.uoc.gr/mirrors/OpenBSD/OpenSSH/portable/openssh-6.2p2.tar.gz" -O /home/fakedrake/Projects/ThinkSilicon/xilinx-zynq-bootstrap/drafts/openssh.tar.gz
mkdir /home/fakedrake/Projects/ThinkSilicon/xilinx-zynq-bootstrap/sources/openssh-archive
cd /home/fakedrake/Projects/ThinkSilicon/xilinx-zynq-bootstrap/sources/openssh-archive && tar xvzf /home/fakedrake/Projects/ThinkSilicon/xilinx-zynq-bootstrap/drafts/openssh.tar.gz
echo "Building openssh"
rm /home/fakedrake/Projects/ThinkSilicon/xilinx-zynq-bootstrap/drafts/openssh.tar.gz

Pretty sure you can list targets (and intermediates) as .PRECIOUS to avoid them being deleted for you. I'm afraid you'll need to RTFM for more details - I'm in visual studio rather than make these days, so my make skills are a bit rusty...

Related

how to automate the build system where it needs sudo privileges in Makefile without typing password

I've simple makefile target, that fetch the tar file, unpack it in /opt dir in Linux. In order to move files and unpack at /opt dir I need sudo privileges.
my makefile target,
TOOLCHAIN:=/opt/toolchains
bake-prep:
#if [ ! -d $(TOOLCHAIN) ]; \
then echo "Installing the ARM toolchain at /opt dir"; \
mkdir -p $(TOOLCHAIN); \
cp -r $(TOOLCHAIN_GIT)/. $(TOOLCHAIN) && echo "Copied the toolchain to host"; \
echo "Unpacking the toolchain.."; \
tar -xzf $(TOOLCHAIN)/$(TOOLCHAIN_ARCHIVE) -C $(TOOLCHAIN); \
cd -; \
else \
echo "Toolchain is already installed"; \
fi
I'm fine to use the target like sudo bake-prep in my host and I can type the password.
I want to run this in Jenkins. I don't want the build to stuck at sudo enter the password. Is it possible to make Jenkins have root privileges or is it possible to do something in makefile?

can't translate my program via debian package but with autotools can

i use autotools as build system also i use gettext in my code for Translations.
I have few .po files (de.po, es.po and th.po ) and with autotools no problem to get them working. After:
./configure,
make
sudo make install
the program and the Translations .mo files get installed.
To testing that i open a terminal and change the locale e.g :
$ export LANG=de_DE.UTF-8
$ ./myprogram
and the translations works!.
I do with the same source code a debian deb package.
During the deb installation in a .posinst script i deploy the translations mo files to the locale destination (docklight is the program name):
#!/bin/bash
set -e
# check for locale dir (LIVE SYSTEMS don't have it)
if [ -d "/usr/local/share/locale" ]; then
podir="/usr/lib/docklight/docklight.data/po"
if [ -d ${podir} ]; then
cd ${podir}
PO_LINGUAS=$( if test -r LINGUAS; then grep -v "^\#" LINGUAS; fi)
linguas=$PO_LINGUAS
for lang in $linguas; do
dir=/usr/local/share/locale/$lang/LC_MESSAGES;
# check for locale dir (LIVE SYSTEMS don't have it)
if [ ! -d $dir ]; then
continue;
fi
# check for po file
if [ ! -f "$lang.po" ]; then
continue;
fi
file=`echo $lang | sed 's,.*/,,'`.gmo \
&& rm -f $file && /usr/local/bin/msgfmt -o $file "$lang.po"
/bin/bash install-sh -d $dir; \
if test -r $lang.gmo; then \
/usr/bin/install -c -m 644 $lang.gmo $dir/docklight.mo; \
echo "installing $lang.gmo as $dir/docklight.mo"; \
else \
/usr/bin/install -c -m 644 ./$lang.gmo $dir/docklight.mo; \
echo "installing ./$lang.gmo as" \
"$dir/docklight.mo"; \
fi
done
fi
fi
the generated Translations .mo files are correct and get installed on the locale folder for the language:
dir=/usr/local/share/locale/$lang/LC_MESSAGES;
exact the same like the build process with autotools.
After testing the languages:
$ export LANG=de_DE.UTF-8
$ ./myprogram
my program does not have any translation.
I don't know where the problem is. The deb installation works correct!
is something more that i need to care for the creation of a debian deb package?
As far as I understood, when you get myprogramm.mo files in place you should get the program translated.
Any ideas about that?
Thanks in advance for any help.
if find the solution:
I just need to set the PROGRAMNAME_LOCALEDIR path where the mo file are.
The gettext initialization can find the mo files and then everything gets translate. Works!
bindtextdomain(GETTEXT_PACKAGE, PROGRAMNAME_LOCALEDIR);
%s\n",domain,GETTEXT_PACKAGE,PROGRAMNAME_LOCALEDIR);
bind_textdomain_codeset - set encoding of message transā€lations
btdcodeset = bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
Thank you all.

Installing a custom RPM hangs when trying to run a post-install script

I'm building an RPM with my own code and am running into an issue where the RPM is hanging when I install it with yum if I try to launch something as part of the post-install script. For some background, this is a virtual appliance where we've replaced the shell with a program with minimal configuration options. Previously, I couldn't get the program to load via the post-install options in my spec file; it causes the 'installing' line during a yum install to hang. I put a bandaid on it by having a reboot occur. I need this menu to load after installation, but everything I've tried results in yum hanging on the 'installing' line. My latest attempt; using the trap command, causes the same hang. Does anyone have any other ideas?
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}
%description
Installs the program.
%prep
%setup -q
%install
rsync -ar /home/makerpm/rpmbuild/BUILD/%{name}-%{version}/ /home/makerpm/rpmbuild/BUILDROOT/%{name}-%{version}-%{release}.x86_64
find $RPM_BUILD_ROOT -not -type d -printf "%%%attr(%%m,root,root) %%p\n" | sed -e "s|$RPM_BUILD_ROOT||g" > %{_tmppath}/%{name}_contents.txt
%clean
rm -rf ${RPM_BUILD_ROOT}
rm -rf %{_tmppath}/*
rm -rf ${RPM_BUILD_DIR}/*
%changelog
* Sun Jan 25 2014 - %{version} - Modified menu with trap ability so the first reboot isn't required.
%post
function finish {
/bin/launcher
}
chmod 755 /bin/launcher
cat /etc/shells | grep "/bin/launcher"
if [ $? -eq 1 ]
then
echo "/bin/bash" >> /etc/shells
fi
chsh -s /bin/launcher root
trap finish EXIT
#List of all files to be extracted
%files -f %{_tmppath}/%{name}_contents.txt

How to update a bash script with the old version of this script?

I have a linux bash script, which has a parameter to update the script self. My problem is, that the script can't update itself, while it's used. Well.. Does someone have a solution?
Currently I try to update the script as following:
# Download latest version
wget -q https://github.com/TS3Tools/TS3UpdateScript/archive/master.zip
# Unzip latest version
unzip master.zip TS3UpdateScript-master/* -x TS3UpdateScript-master/configs/ && mv -f TS3UpdateScript-master/* . && rmdir TS3UpdateScript-master/
But I receive the following error by the script:
replace TS3UpdateScript-master/LICENSE_GNU_GPL.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
ateScript-master/configs
caution: excluded filename not matched: TS3UpdateScript-master/configs/
# many arguments
I hope, someone can help me. Thanks in advance!
It seems that your error comes from file name wildcard without quotes. Bash does globbing first and replaces * with lots of filenames and then runs unzip with this parameters. Try master.zip 'TS3UpdateScript-master/*' -x 'TS3UpdateScript-master/configs/' .
Then there will be a problem with running a new version of script instead of old one running. I think it should be done like that:
#!/bin/bash
version=4
if [ "$UPDATED" != "$0" ]; then
cp self_update.new.sh self_update.sh
exec env UPDATED="$0" "$0" "$#"
fi
echo "This script's version is $version"
Thanks for your help and ideas! I've "outsourced" the code to another script, which contains following code:
#!/usr/bin/env bash
sleep 5s
# Download latest version
wget -q https://github.com/TS3Tools/TS3UpdateScript/archive/master.zip
# Unzip latest version
if [[ $(unzip master.zip TS3UpdateScript-master/* -x TS3UpdateScript-master/configs/*) ]]; then
if [ $(cp -Rf TS3UpdateScript-master/* . && rm -rf TS3UpdateScript-master/) ]; then
rm -rf master.zip
exit 1;
fi
else
rm -rf master.zip
exit 0;
fi

Why isn't mkdir -p working right in a script called by checkinstall?

I'm trying to compile Quarter and package it using checkinstall.
If I do the standard ./configure && make && sudo make install, things go fine.
$ wget http://ftp.coin3d.org/coin/src/all/Quarter-1.0.0.tar.gz
$ tar xzf Quarter-1.0.0.tar.gz
$ cd Quarter-1.0.0
$ ./configure
$ make
$ sudo make install
But when I use checkinstall, it fails on a mkdir -p that should work perfectly fine. The way it fails is exactly how it would as if the -p option weren't given. This is the checkinstall command line I'm using:
$ checkinstall -D -y --install=no --pkgname=libquarter --pkgversion=1.0.0 \
--arch=i386 --pkglicense=GPL --maintainer=me#example.com --reset-uids=yes
This is the failure:
....
/bin/bash ../../../cfg/mkinstalldirs /usr/local/include/Quarter/devices
mkdir -p -- /usr/local/include/Quarter/devices
mkdir: cannot create directory `/usr/local/include/Quarter': No such file or directory
make[4]: *** [install-libdevicesincHEADERS] Error 1
....
This is the relevant part of the script:
$ cat cfg/mkinstalldirs
....
case $dirmode in
'')
if mkdir -p -- . 2>/dev/null; then
echo "mkdir -p -- $*"
exec mkdir -p -- "$#"
fi
;;
....
I don't understand why that exec is there -- doesn't that guarantee that the remainder of the script (after the esac) will never execute? (If the if test passes, then the script assumes mkdir -p works correctly, so once it does the real mkdir -p it can quit; otherwise the remainder of the script implements proper mkdir -p behavior.) I also don't understand why it uses "$*" in the echo and "$#" in the next line, but it doesn't seem to matter -- they're both the same thing since this script is being called with just one argument. (Tom explained in comment.)
If I add two lines between echo and exec that does mkdir -p -- "$#" and then echo "Now doing the exec mkdir..." then it works like this -- better, but still bewildering:
/bin/bash ../../../cfg/mkinstalldirs /usr/local/include/Quarter/devices
mkdir -p -- /usr/local/include/Quarter/devices
mkdir: cannot create directory `/usr/local/include/Quarter': No such file or directory
Now doing the exec mkdir...
/usr/bin/install -c -m 644 InputDevice.h /usr/local/include/Quarter/devices/InputDevice.h
.... finishes successfully!
Now, the fact that doing the mkdir line twice made it work tells me it's not a permissions issue (beside, that would generate a different diagnostic from mkdir, and this is being run as sudo, and it's actually working in /var/tmp/... not the real /usr/local/...). I think what's happening is that the first mkdir invocation (the one I added) is actually creating just the Quarter directory and bailing out, and then when the second mkdir runs, it's able to create the devices subdirectory, because the Quarter directory is already there. But why would mkdir work that way???
My workaround is to patch that mkinstalldirs script somehow, but I'm really curious why this is breaking!
This is a Ubuntu 10.10 guest running in VirtualBox on Win7, checkinstall version 1.6.2 installed thru apt-get.
EDIT:
I did some testing to see what works and what fails in this environment...
mkdir -p /foo works correctly
mkdir -p /foo && mkdir -p /foo/bar works correctly
mkdir -p foo/bar works correctly
mkdir /foo/bar failed as expected (correct)
mkdir foo/bar failed as expected (correct)
mkdir -p /foo/bar fails
Weird that -p works for relative pathnames but not for absolute pathnames. Or maybe the correct distinction is that -p works outside of the "chroot" tree (if it's even really using chroot) but not within it.
I also verified that despite the failure, it is able to create the first directory level.
Still a mystery.
Using
checkinstall --fstrans=no
should fix this.
Or
Set "TRANSLATE=0"
in /etc/checkinstallrc and try again.
mkdir -p isn't working like it should because it's a checkinstall version of mkdir, not the "true" mkdir. Must be some bug in checkinstall that makes it work a bit differently.
This patch works around the bug:
./configure
sed -i 's/if mkdir .*-p --.*; then/if false; then ## &/' cfg/mkinstalldirs
....
sed -i -e 's/TRANSLATE=1/TRANSLATE=0/g' /etc/checkinstallrc

Resources