#!/usr/bin/env bash
configdir="${XDG_CACHE_HOME:-$HOME/.config}/example"
datadir="${XDG_DATA_HOME:-$HOME/.local/share}/example"
mkdir -m 666 "$configdir"
mkdir -m 666 "$datadir"
This postinst script in deb package is creating directories in /root, instead of creating directories inside /home/usrname. What Am I doing wrong?
Related
I create a .deb package for my app and postinst script is not running after installing .
this is my postinst script under the the path of DEBIAN/myapp.postinst
#!/bin/sh
set -e
echo "start postinst packing"
#fix app process permission
sudo chown root:root /opt/MyApp/myapp
sudo chmod 4755 /opt/MyApp/myapp
echo "finish set permissions"
exit 0
in the DEBIAN/ directory create a file named postinst and copy your script into it, or change the name of myapp.postinst to postinst and you're ready to go
Can I set permissions when I create a file/directory using a single command or do I have to create the file/directory first and then use chmod to set its permissions?
For instance to do something like this
// for directories
mkdir 755 test
// for files
touch 644 test/my_file.php
For files, try using install command:
$ install -m 644 /test/path/ myfile.php
For folders, mkdir with -m param:
$ mkdir -m 755 test
You might have to execute that as sudo.
Man pages are your friend. This is possible with GNU mkdir but not with GNU touch.
mkdir -m 755 test
you can use following command to create directory and give permissions at the same time
mkdir -m755 test
I want to download a list of files using "wget" command of linux in a bash script file. The problem is that when I am trying to change the directory to another subdirectory in my home, it does not work and the wget after the cd command will download the files in my home directory not the desired subdirectory
mkdir -m 777 "dbback2012"
cd "dbback2012"
wget -r [FTP URL]
The problem is that the downloaded files via wget are in the home directory not the "dbback2012" directory.
There's nothing wrong with the code, you either
haven't shown us the real code
the script is executed somewhere else, check the working directory: pwd
the script failed to create the directory mkdir -m 777 "dbback2012" || (echo "ooops"; exit 1)
I have created a symbolic link to a deeply nested directory. Using symbolic link i can move to that directory from my home directory. I want to move one directory back from the target directory but the shell comes back to the home directory.
[root#pe1800xs ~]# pwd
/root
[root#pe1800xs ~]# mkdir -p abc/def/ghi/jkl/mno/pqr
[root#pe1800xs ~]# ln -s abc/def/ghi/jkl/mno/pqr/ xyz
[root#pe1800xs ~]# cd xyz
[root#pe1800xs xyz]# pwd
/root/xyz
[root#pe1800xs xyz]# pwd -P
/root/abc/def/ghi/jkl/mno/pqr
[root#pe1800xs xyz]# cd ..
[root#pe1800xs ~]# pwd
/root
What I want to achieve is that when I do cd.. in pqr directory the shell should come to mno directory.
You must use
cd -P xyz
to enter into that directory to follow the original structure of folders, then you can move as you wish because you have resolved the link to the real path.
You have to pass -P option:
cd -P ..
I have a spec file which is similar to:
BuildRoot: /tmp/build_%{name}-%{version}-%{release}
%prep
...
...
%install
# Directories
install -m 755 -d %{buildroot}/usr/app/mypackage/config
install -m 755 -d %{buildroot}/usr/app/mypackage/src
....
# Bash script
install -m 755 script/script1.sh %{buildroot}/usr/app/mypackage/config/script1.sh
install -m 755 script/script2.sh %{buildroot}/usr/app/mypackage/config/script2.sh
install -m 755 script/myapp-log %{buildroot}/etc/logrotate.d/myapp-log
When I run the rpmbuild I get the error:
install: cannot create regular file `/tmp/build_my_app-1.0-2/etc/logrotate.d/myapp-log'
I can get around this by manually creating the /etc/ and then /etc/logrotate.d directories in the /tmp/build_my_app-1.0-2/ directory.
When I re-reun the rpmbuild it will work.
I guess this is because I am not creating this directory in my install section but as its not directly related to my application I don't want to put that in.
My guess is that there is some clever tag I can use to fix this so that the build will work without any manual intervention.
My Question:
Could someone please suggest a way for me to achieve this (assuming its possible) or whether I need to write a script around the rpmbuild to set this up first.
You are missing the step to create the installation directories in your %install section. Remember that since you can build in "different" roots, you cannot expect certain directories (like ${buildroot}/etc) to be present.
Try adding
mkdir -p ${buildroot}/etc/logrotate.d
just before the install command that copies the file into ${buildroot}/etc/logrotate.d.