Question

I need to write a shell script to be scheduled to run daily to backup a directory using mercurial. I have got most of the use cases done except I can figure out a way to do automated login while the script is running.

for REPOSITORY in $@ 
do
    cd $REPOSITORY

    # commit the changes
    hg commit -A -m "Commit changes `date`"

    # push the changes to the remote repository
    if hg push 
    then
        logger hg push success
    else
        logger hg push failure
    fi
done

the login prompt is displayed after the hg push command is issued.

Was it helpful?

Solution

Mercurial allows you to put the username and password in the Repository URL:

hg push http://username:password@hg.myco.com/repo

If you don't want to put the URL on the command line you can edit the hgrc file for the local repository and put the username and password in the default-push URL:

default-push = http://username:password@hg.myco.com/repo

This means any hg push will use the username specified in the hgrc file.

OTHER TIPS

I agree that you should configure your backup script for non-interactive logins. One way is to use SSH keys and a simpler solution is to include the password directly in the URL.

Mercurial 1.3 makes it much easier to include HTTP passwords in your configuration files. I now have a

[auth]
bb.prefix = https://bitbucket.org/mg/
bb.username = mg
bb.password = pw

section in my configuration file. This means that you can avoid storing your passwords in multiple files and only concentrate on securing one file.

In fact, I am using another new feature in order to avoid putting the password in ~/.hgrc, since I might want to show that file to others. Instead I have

%include .hgauth

in ~/.hgrc and ~/.hgauth has the above [auth] section and is readable by me alone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top