I have small script in bash which automates installation of a few packages. It installs a few packages using apt-get and the rest from sources. I have all the sources I need tarred into a single tar file. The sample script looks as follows:
#!/bin/bash
apt-get install wget gcc g++ ruby php5 php5-dev xz-utils bzip2 -y
cd /usr/local/bin/
wget my-sources.tar.gz
tar zxvf my-sources.tar.gz
cd my-sources
tar zxvf package1.tar.gz
cd package1
./configure && make && make install
cd /usr/local/src/my-sources
tar zxvf package2.tar.gz
cd package2
./configure && make && make install
cd /usr/local/src/my-sources
tar zxvf package3.tar.gz
cd package3
./configure && make && make install
echo -e "\nFinished\n"
This script is then encoded using zlib in python 2.7:
import tempfile
import subprocess
import zlib
with open("/usr/local/src/sample.sh") as inputfile:
teststr = zlib.compress(inputfile.read()).encode('base64')
print teststr
This is then passed to a python script which executes it as follows:
thisstr = "Gu11nX1eVdeGlaMoouIyJtOV/cPBWrp1b7OeY7P7GXtzb
x7HETWRhTHC6NzM3k0nH6dw8uFs+qRtkJWiPrBGs1mlXWJjt7ZSUHe0
ZougLFsrAmxs3b+l+q9UKFrL1aAt0glTEo8bUuSO7Gjfe3JaYpedEgt
qkbZtz825OWUlyiz+pMPmkOdlhYu2ia+at+ZJIGZRkFzsBIqJKNhAQ4
LlBdMzdGu593UzCBtsspZiVntsFlzbyefpjCBk+PDKbyefOZMPy9Xd/
wL3ieojA=="
str=zlib.decompress(thisstr.decode('base64'))
with tempfile.NamedTemporaryFile() as scriptfile:
scriptfile.write(str)
scriptfile.flush()
subprocess.call(['/bin/bash', scriptfile.name])
What happens here is, while apt-get is being executed, in-between, the wget is attempted. Since wget isn't installed yet, the wget command fails and then the execution moves to the compiling and building steps (which throw errors as the files aren't available). All the while, the apt-get is still being executed.
I tried 2 steps to avoid this:
- Added
sleep 5at the end of theapt-getcommand. This did not help. - Put
apt-getin another function and called the function just
before thewgetcommand.
this too did not help.
Of course, when I run it the second time, the packages get installed (because all the packages to be installed using apt-get are already there).
This was tested and is for Debian 6/Debian 7
How can I correct this error?
waitafter theapt-get?waitso that I can try it out?wait. Just type it on the line afterapt-get. Have a look atman waitfor reference.