Linux SVN post-commit doesn't work? - linux

I read and try alot of Blog an Post entries from stackoverflow and other pages, but there was no solution.
SVN Version : 1.6.11
Linux Version : Linux 2.6.32-358.23.2.el6.x86_64 x86_64
I've created a script, which should be execute after a svn commit.
I've renamed the file post-commit.tmpl to post-commit.
I use absolut paths and all files (the script, post-commit, log..) are in mode 777.
In the script and in the post-commit the PATH is set.
When I commit something in my Project, my debug.log is working .
echo "START">>/svn/test/debug.log
sudo echo /svn/test/hookScripts/generateDocumentation.sh "$1" "$2">>./svn/test/error.log
echo "END">>/svn/test/debug.log
There are the START and END entries in the debug.log File, but the script won't be executed.
I tried some from this link, but it doesn't work.

The Problem was: I try to run /svn/test/hookScripts/generateDocumentation.sh in a script. To execute this I've to write it in $(...)

Related

Issues setting $PATH on Bash on Ubuntu on Windows (Linux Subsystem)

I am using the "Bash on Ubuntu on Windows" (Linux Subsystem) and want to add Terraform to my $PATH. Since Terraform can't be installed via apt-get, I did the following steps:
Navigated to this directory, where I wanted to install Terraform:
cd /usr/local
In the above path, I used wget to download Terraform:
wget
https://releases.hashicorp.com/terraform/0.9.8/terraform_0.9.8_linux_amd64.zip
Terraform successfully unzips! When I open the file in VIM it is all good:
unzip terraform_0.9.8_linux_amd64.zip
I then enter this command to check to see if the Terraform binary is accessible from the command line:
terraform -version
However the following message gets returned:
terraform: command not found
This tells me that the Terraform downloaded location needs to be added to my $PATH.
Already being logged in as the root user ("sudo su") I enter the following command to access ".profile":
vim ~/.profile
The following is already in this file, which I leave untouched:
# ~/.profile: executed by Bourne-compatible login shells.
if [ "$BASH" ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi
mesg n
Immediately below this text, I add the following, and successfully save the file using :wq!:
export PATH=/usr/local/bin:$PATH
export PATH=$PATH:/usr/local/terraform
6.
I then again enter the following command to check to see if terraform is detected
terraform -version
Still the same "terraform: command not found" message is returned. I even tried closing out and starting a new command line session and even restarting my computer. Still no change.
Anyone have any ideas on how to resolve this? Again, note that I am using "Bash on Ubuntu on Windows" (Linux Subsystem). Any input would be appreciated!
The direct answer to your problem is at the end.
But I think it will make more sense if you keep reading from here.
Before trying to add to PATH,
I recommend to test a program first.
In your case I would do like this:
wget https://releases.hashicorp.com/terraform/0.9.8/terraform_0.9.8_linux_amd64.zip
unzip terraform_0.9.8_linux_amd64.zip
./terraform
Notice the last line ./terraform.
The zip file contains a single file, terraform,
which now should be in the current directory,
so I can run it with ./terraform.
If it's executable.
If it's not executable then confirm it:
ls -l terraform
And make it executable if needed:
chmod +x terraform
Now let's add it to PATH.
But first,
let's decide where to put this executable.
/usr/local/bin seems a reasonable location.
So let's move the terraform executable into that directory.
Usually /usr/local/bin is already on PATH,
so you might not need to change anything.
Now you can try your check, and there's a good chance it already works:
terraform -version
If it doesn't, then /usr/local/bin is not on the PATH.
To add it, add this line in ~/.profile:
export PATH=$PATH:/usr/local/bin
Two things looked fundamentally wrong with your approach:
Adding /usr/local/terraform to PATH. This is fishy, because the entries on PATH must be directories, and in your post nothing indicates that you created a directory at /usr/local/terraform.
You cd into /usr/local, and then unzip the zip file of terraform. The linked zip contains a single file named terraform, so /usr/local/terraform in your example should be a file.
If it is a file, then you could make it executable as terraform by adding to add to PATH its base directory. But adding /usr/local to PATH would not be a good idea. It's conventional to put binaries into /usr/local/bin, not directly into /usr/local
You did not mention how you reloaded ~/.profile. After editing this file, the new commands you added do not get automatically executed in your current shell. They will get executed when you open a new shell. Or you could manually execute the added commands in the current shell.
Hit below command
export PATH=$PATH:/usr/local/bin

Alias Multiple Commands in Linux

I am managing a website using git. One of the requirements for the git repository is that bare = true. It uses a post-receive hook to manage pushes from my local computer. The problem is that sometimes I would like to make changes to a WordPress directory on my website using the wp-admin view online. So then I would just ssh into the directory and run git --work-tree="BLAH" add . and git --work-tree="BLAH" commit -m "BLAH". Is there a way to set up an alias, like alias git="git --work-tree=\"BLAH\"" and have that work for all git commands?
There are times when alias are a great tool. Then there are times when things start getting too complicated where a shell script is better.
To create a single command that executes other commands just create a file (maybe call it git-add-all) then type the following:
#! /bin/bash
git --work-tree="BLAH" add .
git --work-tree="BLAH" commit -m "BLAH"
Then you can run the script by simply doing:
bash git-add-all
Even better, make the script executable:
chmod +x git-add-all
Then you can use it like any command:
./git-add-all
Advanced tips:
To be able to run the script from any git directory you can copy/move the file to one of the directories in your $PATH. For example /usr/loca/bin. Then you can simply run git-add-all instead of ./git-add-all.
Even better is to create your own personal scripts directory and include it in $PATH. I personally use ~/bin. To add the directory to $PATH you just need to add the following to .bashrc or .profile:
export PATH=/home/username/bin:$PATH
or if you're doing this for the root user:
export PATH=/root/bin:$PATH
In case anyone is curious how I solved it (thanks to shellter's comment), I wrote a bash script then prompted the user for input like so:
#!/bin/bash
function fix {
git --work-tree="PATH_TO_WORKING_TREE" $1
}
echo -n "git "
read -e INPUT
until [ "$INPUT" = "quit" ]; do
fix $INPUT
echo -n "git "
read -e INPUT
done
Running it:
user#server [repo.git] $ git-fix
git status
# On branch master
nothing to commit (working directory clean)
git quit
There is a .bashrc file in Linux. You can edit it for creating alias for your favorite and frequently used commands.
To create an alias permanently add the alias to your .bashrc file
gedit ~/.bashrc
The alias should look like:
alias al='cmd'
You can read more about it over here.

Why isn't git reading the added file?

I was reading an article that told me to add a file and place it in my path. Not knowing what the author meant by path, i simply put it in my root directory.
Trying to run 'git diffall', git says diffall is not a command, any ideas? Thanks in advance.
The article snippet for more information:
Write the following code to a file called git-diffall and place in your path (I put it in >…/my-git-install-dir/cmd/ )
#!/bin/sh
git diff --name-only "$#" | while read filename; do
git difftool "$#" --no-prompt "$filename" &
done
And run it in git (with usual diff input parameters), for example:
git diffall
git diffall HEAD
your 'path' is the collection of directories where the system looks for executables. To see it, simply execute echo $PATH at the commandline. Then put your script in one of those directories.

shell script cd fails even though the path is correct

I need to do a script to extract a tar at a specified location.
I did something simple like:
cp test.tar /var/www/html
cd /var/www/html
tar xvf test.tar
If I execute the commands by hand everything is OK. If I save them in a .sh then use #bash script.sh, I get the following error ": Not a directory cd: /var/www/html". Any ideea why?
Ty for your time.
Notes: I tried the script version on a virtual machine (CentOS 5.5) and the script worked fine, the problem occurs on the real machine where I want to use it (I used same OS disk image, same configurations as on the virtual machine... this makes it really really odd for me).
Added: Also I try invoking something like service mysqld start... this also fails saying that a dir doesn't exist (still if I run by hand it works.).
I solved the problem - it is quite interesting).
I created the script on a virtual machine running on windows with a centos os, the enter in windows is "\r\n" while in linux is "\n".
The script worked on the vm because the code for enter was correct, while on the second computer, with native linux it was incorrect. I created exactly the same script on linux and everything went back 2 normal ;).
Note... the mkdir part worked because I used another, simplified script written on linux.
On a related note, I have found that the "~" character does not seem to work in bash, so if you are using that, try replacing it with the full path.
It looks like your cp might be coping test.jar to the file html under the www directory. Make sure that html exists and is a directory before you try to cp.
mkdir -p /var/www/html
cp test.tar /var/www/html
cd /var/www/html
tar xvf test.tar

Where do I put a post-commit hook script?

I've just thrown together the following shell script:
cd /home/firefli/webprojects/project1
svn checkout file:///home/firefli/svn/project1/trunk .
rm -rf /home/firefli/public_html/project1
svn export . /home/firefli/public_html/project1
It does work when I do a commit and then run the script manually but I still have a couple of questions.
Can I run a bash script, or does it have to be C? (I've seen lots of C examples)
Where do I put it to make it execute post-commit?
There is a hooks directory inside your Subversion repository. It should contain a number of templates that you can modify and use.
Your script can happily be a bash script. The provided templates use /bin/sh
Just remove the .tmpl extension and you're good to go.
The Subversion docs provide more info here

Resources