Why postinst not running after installation? - linux

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

Related

My script file stopped executing when there change in user in script what should i do

My code file looks as follows
Cd testR
Mkdir bin
chmod -R 755 bin
Sudo su - inst1
cp inst1/installable/files/testR.p
...
...
So after sudo su the execution get paused please let me know what should i do
If there is no problem that your commands are executing as root, you can execute your script like this:
sudo ./yourscript
So, you don't have to switch within your shell script.

Directory creating in wrong home

#!/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?

Problems running first shellscript

I'm trying to create my first shell script in bash. I've created the code and I've managed to save the script in my home directory but it wont run. At first I try running it from the home directory with: ./testscript.sh with "permission denied" as a response, i then tried sudo ./testscript.sh and then the "command was not found".
This is my script:
#!/bin/bash
mkdir -p/home/filer
touch /home/filer/fil1
touch /home/filer/fil2
touch /home/filer/fil3
tar-zcvf file.tar.gz /home/filer
So I've tried creating a script that will create a directory called "filer" in my home directory, using touch to create 3 separate files within the "filer" directory and then creating a tar.archive out of the whole "filer" directory. I think the script is correct, I could just use a hand running the script.
Other than a couple of typos (mkdir -p/path -> mkdir -p /path, tar-zcvf ... -> tar -zcvf ...), you should refer to your home directory using $HOME environment variable. /home/filer is an absolute directory path, which I am assuming, is not your actual home directory.
#!/bin/bash
mkdir -p $HOME/filer
touch $HOME/filer/fil1
touch $HOME/filer/fil2
touch $HOME/filer/fil3
tar -zcvf file.tar.gz $HOME/filer
You can execute the script, ./testscript.sh as bash testscript.sh or ./testscript.sh.
In the second case, the script need to have proper executable permissions. chmod +x ./testscript.sh gives it full executable permissions.

Remove ".bash_aliases" with bash script

In my .bashrc I'm using .sh script for easily configuring newly installed Debian. But while trying to
rm -f ~/.bash_aliases
wget https://raw.githubusercontent.com/.../.bash_aliases
rm -f ~/.bashrc
wget https://raw.githubusercontent.com/.../.bashrc
it's just omitting those line?
File is with permission chmod +x ./script.sh and run by sudo ./script.sh
What could possibly be wrong?
(In final code there is full link, files are being downloaded as .bashrc.1 and .bash_aliases.1)
Don't use sudo unless you have a good reason.
When you run sudo ./script.sh it runs as root, so ~ refers to root's home directory /root instead of your user's home directory.
Just run ./script.sh instead, so that it runs as you and modifies your own home directory.

Jenkins on ISPConfig

I'm usin ISPConfig to have multiple domains for my clients. Now, I have Jenkins to deploy an specific project.
Jenkins has assigned the working directory on /var/www/myproject/web which it is the VirtualHost on ISPConfig.
Manually I have to:
chown -R jenkins:nogroup /var/www/myproject/web
> Build Jenkins project
chown -R web38:client17 /var/www/myproject/web
Questions:
Is ok if I grant sudo permissions to Jenkins?
Instead of that, should I create a bash script with sudo permissions?
Is any permission role that I didn't notice to do this properly?
Thx
This is the solution I've found.
Install "Batch tasks" module on Jenkins.
Create an script as follows with root:root permissions on /var/www/your_domain.com/jenkins-post-build.sh
#!/bin/bash
SOURCE=$1
TARGET=$2
echo Moving $SOURCE to $TARGET
rm -rf $TARGET
cp -R $SOURCE $TARGET
ln -s $TARGET/build $TARGET/public/build
chown -R web39:client11 $TARGET
Add a Post Build action using the "Invoke batch tastsk"
sudo /var/www/your_domain.com/jenkins-post-build.sh ${WORKSPACE} /var/www/your_domain.com/web
Add this script right sudo permissions
Cmnd_Alias HIPER_DEV = /var/www/your_domain.com/jenkins-post-build.sh
jenkins ALL=(ALL) NOPASSWD:HIPER_DEV

Resources