How to get the deb package located directory in preinst - deb

I am creating a .deb package that would run a shell script as preinst.
The shell script needs some input files, which would be available at where I have the .deb package, as below.
Package_located_directory $ >
mydebpackage.deb
inputfile1
inputfile2
I would just transfer all the files to the different machine at any location and install it with dpkg -i mydebpackage.deb
I tried using pwd in the preinst to get the current deb file located directory.
So, I can get the path of the inputfiles from the preinst script.
But if I run pwd from preinst , it is giving me / instead of the package located directory.
Also I tried passing pwd from the PIPE to achieve this, as below,
pwd | dpkg -i mydebpackage.deb
But I do not want to depend on the user input for the path.
Please guide me for getting the current deb package located directory path from inside of preinst script.

it's better to use postinst and modify the file on your system.
for example : Modify the file /etc/test/test.txt in postinst file

Related

Why changing LD_LIBRARY_PATH has no effect in Ubuntu?

I was trying to deploy my application on Ubuntu 16.04. So i made a package with the following hierarchy -
Package
|
----bin
|
-----application
-----application.sh
-----Qt
|
-----necessary qt libraries
-----platforms
Here is the application.sh file -
#!/bin/sh
export LD_LIBRARY_PATH=`pwd`/Qt
./application
When i execute the application.sh file, it shows me that it cant find the libQt5MultimediaWidgets.so.5 file. But its in the Qt folder. Also when i print the ldd application from the application.sh file after exporting LD_LIBRARY_PATH it gives me following output -
Please check the marked parts. Can anyone please explain why the libraries from the Qt folder are not found even after exporting the LD_LIBARRY_PATH?
Edit:
So as suggested by #Zang, i have checked the debug log and here it is -
Please check the marked parts.
It seems like its actually trying the actual libQt5MultimediaWidgets.so and then report that its unable to find it. Can anyone please help me understand whats happening here?
Edit-2: As per suggestion from #Tarun, i have ran ls -al on my Qt folder. Here is the output -
All files in Your Qt directory are actually simlinks to non-existing files in the same directory, therefore they cannot be found.
If you look at the output of your ls -al
These are soft links that you have. Your softlink libQt5MultimediaWidgets.so.5 points to libQt5MultimediaWidgets.so.5.9.2 in the same directory and the file is not there at all. So you need to either set the correct softlink path or have the file in same directory
First
Could it be that the pwd is not where you assume it is?
You could try adding
# Figure out where the application.sh script is located
scriptpath="$( cd "$(dirname "$0")" ; pwd -P )"
# Make sure our pwd is that location
cd "$scriptpath"
in the top of your script (assumes bash shell, from here)
By doing this all relative paths to Qt folder will be valid.
Second
Maybe you should considder exporting your new LD_LIBRARY_PATH, like so (from here):
LD_LIBRARY_PATH=whatever
export LD_LIBRARY_PATH
Third
It may be useful to run ldconfig command for ld to update after changing the variable (from here):
sudo ldconfig
The file libQt5MultimediaWidgets.so is not present in /Desktop/package/bin/Qt according to the screenshots shown.

How to extract a .tar.gz file on UNIX

I have a file (reviews_dataset.tar.gz) that contains many files which contains data. I am required to extract the files in this archive and then perform some basic commands on the file. So far I have created a directory named (CW) and found a command tar zxvf fileNameHere.tgz but when I run this it of course cannot find my file as I have not "downloaded it" into my directory yet? How do I get this file into my directory so that I can then extract it? Sorry if this is poorly worded I am extremely new to this.
You must either run the command from the directory your file exists in, or provide a relative or absolute path to the file. Let's do the latter:
cd /home/jsmith
mkdir cw
cd cw
tar zxvf /home/jsmith/Downloads/fileNameHere.tgz
You should use the command with the options preceded by dash like this:
tar -zxvf filename.tar.gz
If you want to specify the directory to save all the files use -C:
tar -zxf filename.tar.gz -C /root/Desktop/folder

How can I save the path to a frequently used directory in UNIX?

Is there a way to save the path to a frequently used directory in UNIX, so instead of having to manually cd /path/to/directory I can just enter a shortcut cd myFavoritePath ??
Define your favorite directories in CDPATH environment variable. It's a colon-separated list of search paths available to the cd command. You should specify not a directory you want to switch but parent directory.
Here is brief info about it: http://docstore.mik.ua/orelly/unix/upt/ch14_05.htm
For example you have three directories you work with frequently:
/home/user/scripts/favorite/
/var/log/
/var/lib/
add to your ~/.bash_profile (or another shell profile file you use) the next line:
export CDPATH=.:/home/user/scripts:/var
In the example below I just redefine CDPATH in shell for the current session
[user#server lib]$ CDPATH=.:/var:/home/user/scripts
[user#server lib]$ cd log
/var/log
[user#server log]$ cd lib
/var/lib
[user#server lib]$ cd favorite
/home/user/scripts/favorite
If you want use tab while execute cd you can install bash-completion http://bash-completion.alioth.debian.org/ but it's optional
Also do not forget cd - command for quick switching to previous working dir
You can always add the directory path in ~/.bashrc
vi ~/.bashrc
export FAV_DIR1=''
The variables in .bashrc load into the environment on new session. So make sure to reboot.
Then you can visit the directory by something like:
cd $FAV_DIR1

How do I install GHC 7.8.1 and assign it a different command?

I would like to install GHC 7.8.1, but would like to assign it different commands, so as not to clash with 7.6.3. For example:
runghc with runghc7.8.1
ghci with ghci7.8.1
etc...
Or similar. (ghci would be most important, for typed holes.)
Basically, I want to be able to use GHC 7.8 and 7.6, so if there is a more direct way to do this tell me (A-B problem.)
Note: Ubuntu 13.10
Because you are on a unix-like system (Ubuntu) you can do the following:
Choose a folder you like for installing ghc (e.g. in a subfolder of your home directory like $HOME/ghc7.8.1 or in a subfolder of /opt like /opt/ghc7.8.1 – I would prefer the later one if you are the only user of your computer and the first one if this isn't the case). See this wikipedia article for explanations about the unix directory structure.
Download the source code into that folder and follow the installation instructions:
See also https://ghc.haskell.org/trac/ghc/wiki/Building/Using#Runtheconfigurescript
In configure setp its important, that you set the --prefix to the folder you have chosen above (if you don't do this, ghc will be installed in /usr/local/ which you do not want)! For example:
./configure --prefix=/opt/ghc7.8.1
After the installations look for the folder with the created binaries (it will be called bin if you did not use another name for bindir). Lets imagine this folder is /opt/ghc7.8.1/bin.
Now you have two possibilities:
Solution with creating symlinks: Create symlinks in a folder which is in your $PATH pointing to the created binaries (for example /usr/local/bin or $HOME/bin – I would use the first one, if you are the only user on your computer and the second if, if you are not). Therefore you have to use the command line tool ln. For example:
sudo ln -s -T /opt/ghc7.8.1/bin/runghc /usr/local/bin/runghc7.8.1
After this command there is a file /usr/local/bin/runghc7.8.1 pointing to the binary /opt/ghc7.8.1/bin/runghc. Executing /usr/local/bin/runghc7.8.1 via typing runghc7.8.1 will now execute the runghc binary created in /opt (Note: sudo is not necessary if you create your symlink in $HOME/bin – it is just needed because root can create files under /usr)
Solution with bash aliases: Write in your $HOME/.bash_aliases (#Others: you can alternatively choose $HOME/.bashrc or $HOME/.profile depending of your system/preference) the following line:
alias runghc7.8.1='/opt/ghc7.8.1/bin/runghc'
Now typing runghc7.8.1 in your terminal is an shortcut (alias) for typing /opt/ghc7.8.1/bin/runghc and will execute this binary.
Note, that with this solution typing runghc7.8.1 will just work, when you typed it into your terminal. There are cases, when it does not work (for example calling runghc7.8.1 in a script).

Can I access an external file when testing an R package?

I am using the testthat package to test an R package that is within a larger repository. I would like to test the contents of a file outside of the R package.
Can I reference a file that is located outside of an R package while testing?
What I have tried
A reproducible example can be downloaded as MyRepo.tar.gz
My repository is called "myRepo", and it includes an R package, "myRpkg" and a folder full of miscellaneous scripts
~/MyRepo/
~/MyRepo/MyRpkg
~/MyRepo/Scripts
The tests in "MyRpkg" are in the /tests/ folder
~/myRepo/myRpkg/tests/test.myscript.R
And I want to be able to test a file in the Scripts folder:
~/MyRepo/Scripts/myscript.sh
I would like to read the script to test the contents of the first line doing something like this:
check.script <- readLines("../../../Scripts/myscript.sh")[1]
expect_true(grepl("echo", check.script))
This works fine if I start from the MyRepo directory:
cd ~/MyRepo
R CMD check MyRpkg
But if I move to another directory, it fails:
cd
R CMD check MyRepo/MyRpkg
As it says in R-exts
The directory tests is copied to the check area, and the tests are run with the copy as the working directory and with R_LIBS set to ensure that the copy of the package installed during testing will be found by library(pkg_name).
By default, the check directory is created in the current directory. Thus when running R CMD check from ~/MyRepo, the tests directory is copied to ~/MyRepo/MyRpkg.Rcheck/tests and hence
check.script <- readLines("../../../Scripts/myscript.sh")[1]
is interpreted as
check.script <- readLines("~/MyRepo/Scripts/myscript.sh")[1]
as required. However starting from ~/ would imply
check.script <- readLines("~/Scripts/myscript.sh")[1]
which isn't what you want. A work-around is to specify the directory in which the check directory is created, i.e.
R CMD check -o MyRepo MyRepo/MyRpkg
so that the copied tests directory has the same "grandparent" as the original tests directory.
Still, I wonder why the file must be external to the package. If you want to use the file in the package tests, it would make sense to include the file in the package. You could create an inst directory and put the Scripts directory in there, so that the Scripts directory will be copied to the package directory on installation and then
check.script <- readLines("../foo/Scripts/myscript.sh")[1]
could be used inside the test script, since the package is installed in MyRpkg.Rcheck/foo during R CMD check. Alternatively you could create an exec directory and put the script file in there, then
check.script <- readLines("../foo/exec/myscript.sh")[1]
would work. As both of these solutions only need to find the package installed during testing it wouldn't matter where you ran R CMD check from. See Package subdirectories and Non-R scripts in packages for more info.

Resources