Passing parameters to hg pull command using bat file - windows

I want to create a bat file that allow me to run the hg pull command. When i run hg pull, it get some server information and then ask for "user name" and "password". i want to add user name and password automatically. Could you some one please tell me how to solve this.

Here's how you can pass credentials to command-line invocation of Mercurial:
hg pull http://.../ --config ui.username={username} --config ui.password={password}
And I recommend using environment variables to store username and password:
hg pull --config ui.username=%HG_USERNAME% --config ui.password=%HG_PASSWORD%

I have found a solution for this. What we have to do is modify the URl as follow with user input
hg pull http://UserName:Password#yourserver.com/hg/yourRepo

Related

How can I sudo inside of a bash script?

I have a post-commit hook in my subversion that will export a copy of my repo to a desired location for deployment. That part works fine, but it comes in with apache:apache. I need this to be changed to prod_user:prod_user. If I try to add a chown statement in my script, it will fail. If I try to use sudo, it will ask for a password that I cant give because this happening in a post-commit script. I'd like this to be as automated as possible.
My question is: How can I make this work? I need to export the contents of my repo to the production folder and convert the users/groups to match existing production users/groups.
Is there a way to pass my password as an argument to a sudo command?
Thank you for your help!
Is there a way to pass my password as an argument to a sudo command?
Don't do it, if at all possible. This will leak your password to anyone that can read the script.
But if you can't avoid it, use echo <password> | sudo -S <command> - -S makes sudo read from stdin so you can give it the password from there
Don't do any of sudo, chown, chgrp. It is not the responsibility of the uploader to fix permissions on the remote server.
Have the server administrator properly setup these, so that pushing production files from the repository works straight without messing with sudo permission at the server.
If you are the one same person, then take the time to fix the server side to avoid having a remote user elevate its privileges (even temporarily with sudo) for the sake of fixing uploaded files permissions.
Use crontab -e as root user, then you can change ownership without escalation of privileges.
Or run as prod_user and make it check out the code ...then it is already the owner of the files.
Keeping a file with the last deployment timestamp can be used to compare to HEAD timestamp.

Tag a Repo from a Jenkins Bash Script

I recently read a post called "Tag a Repo from a Jenkins Workflow Script", my question is pretty similar but using a bash script (not a workflow script)
Inside of my script I have
#!/bin/bash
...
git push origin :refs/tags/${NEW_TAG}
git tag -fa $NEW_TAG
git push origin master --tags
but at first "git" command I've got
fatal: could not read Username for 'https://github.com': No such device or address
Thank you for your help !
can you please check origin url by using command git remote -v.
Please change origin url to https://USERNAME:PASSWORD#github.com.... and it will work.
In non interactive mode you need to specify credentials in remote url.

Passing inputs to Commands in Command line for user prompt

Suppose I execute a command which prompts the user for input. Is there a way by which I can pass the input in the command itself, rather than taking the input from the user. Like for example, in cloning a private github repo I type:
!git clone https://github.com/username/repo.git
instead I want to do something like
!echo "username" | git clone https://github.com/username/repo.git.
Instead of echo can I have something which automatically inputs username when prompted, by reading it from a file or specifying it directly in my command?
Thanks for helping!

How to get rid of username confirmation when using Google repo?

I want have a patch run every Monday to get the latest Android source code and have it built. It seems everything goes well except I have to help 'repo' to confirm my username and email when I get the patch run. The patch will be scheduled in midnight so I guess I have no chance to offer my help to confirm it... How could I configure repo to dismiss the step? Otherwise, is there any way to input 'enter' by bash script once the script gets prompt?
repo simply builds on top of git.
To set your name in git,
git config --global user.name "Your Name"
git config --global user.email you#example.com
I solved this problem by 'expect', here is the script looks like
expect - << EOF
exec repo init -u ssh://${USER}#<your_repo_server>/<your_manifest.git>
exepect “Your name \[Your Name\]:"
send "\r"
expect "Your Email" \[Your#email.com\]:"
send “\r"
expect "is this correct \[y/n\]?"
send "y\r"
EOF

handling login in an automated backup script

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.
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.
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.

Resources