[opensuse] .bashrc tip for managing multiple boxes, multiple user configs
Guys, This is nothing special, but it was a clever approach to managing your .bashrc over multiple boxes with different user configs for root, you, and other users. The basic approach is just to make use of includes with a couple of conditional checks on $UID or $USER to set the environment accordingly. Here is what I did (no doubt there are much better ways): The .bashrc skeleton: test -s ~/.alias && . ~/.alias || true ## functions & general aliases . /home/admin/cnf/bashrc-gen.inc ## exports . /home/admin/cnf/bashrc-exp.inc ## aliases for builtins . /home/admin/cnf/bashrc-bins.inc ## general aliases . /home/admin/cnf/bashrc-gen.inc ## Application Aliases . /home/admin/cnf/bashrc-apps.inc ## Directory Aliases . /home/admin/cnf/bashrc-dirs.inc ## zypper Aliases . /home/admin/cnf/bashrc-zyp.inc <snip> The directory holding the include files: 11:06 phoenix:~> l1 /home/admin/cnf bashrc-apps.inc bashrc-bins.inc bashrc-dirs.inc bashrc-exp.inc bashrc-gen.inc bashrc-zyp.inc bashrc-ssh.inc Then the contents of the various files (just 2 examples): 11:08 phoenix:~> cat /home/admin/cnf/bashrc-exp.inc ## exports [[ $UID -eq 0 ]] && { # root prompt export PS1="\[\e[1;34m\][\[\e[1;31m\]\A \[\e[1;34m\]\h\[\e[0;31m\]:\w\[\e[1;34m\]] # \[\e[0m\]" } || { # user prompt export PS1="\[\e[0;37m\]\A\[\e[1;34m\] \[\e[1;34m\]\h:\w> \[\e[0m\]" } export PATH=$PATH:/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin export HISTFILESIZE=15000 export HISTSIZE=15000 11:09 phoenix:~> cat /home/admin/cnf/bashrc-gen.inc ## general alias functions wgnc() { if [[ -z $1 ]]; then echo -e "\n Usage: wg <filename>\t\t(runs wget --no-check-certificate --progress=bar)\n" else wget --no-check-certificate --progress=bar $1 fi } showhist() { [[ -z $1 ]] && { echo -e "\nUsage: hist <search term>\n"; return 1; } history | grep $1 return 0 } mkdircd() { [[ -z $1 ]] && { echo -e "\nUsage: mdcd <newdir>\n"; return 1; } mkdir -p $1 && cd $1 || { echo -e "\n Failed to make or change to directory: $1\n"; return 1; } return 0 } perledinln() { if [[ ! -f $2 ]]; then echo -e "\n Usage ${0##*/} REGEX filename\n\n Will edit the file in-place based on REGEX using perl\n" else REGEX=$1 INFILE=$2 perl -p -i -e $REGEX $INFILE fi } ## user specific aliases [[ $UID -eq 0 ]] && { alias tmsg='tail -n150 /var/log/messages' alias tmsgf='tailf /var/log/messages' #<snip> } [[ $USER == david ]] && { alias tmsg='sudo tail -n150 /var/log/messages' alias tmsgf='sudo tailf /var/log/messages' #<snip> } ## general aliases alias difscl='diff -y --suppress-common-lines' alias hist='showhist' alias mdcd='mkdircd' alias ppie='perledinln' alias wg='wgnc' #requires 1 input Basically, the setup allows the use of 1 .bashrc file among all boxes and users and all you have to remember to do is rsync the /home/admin/cnf dir between boxes (or where ever you would put that kind of stuff on your box) Then when changes are needed, you simply edit a singe ../cnf/bashrc-xxx.inc file and rsync the change to hosts and not have to edit 50 individual bashrc files. I'm open if there are other ways or setup tweaks that would make this easier. Also, let me know if you see any red flags. (I'm not concerned about users being able to 'see' what the root bashrc includes - the users I have couldn't even read the thing) Enjoy. -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 12/30/2010 11:21 AM, David C. Rankin wrote:
Basically, the setup allows the use of 1 .bashrc file among all boxes and users and all you have to remember to do is rsync the /home/admin/cnf dir between boxes (or where ever you would put that kind of stuff on your box) Then when changes are needed, you simply edit a singe ../cnf/bashrc-xxx.inc file and rsync the change to hosts and not have to edit 50 individual bashrc files.
You can also handle multiple distributions fairly easily by looking at the /etc/xxxx-release file. Here is an example of a couple of aliases for log file name handling between Arch and openSuSE: [[ -e /etc/arch-release ]] && { alias tmsg='tail -n150 /var/log/everything.log' alias tmsgf='tailf /var/log/everything.log' # <snip> } [[ -e /etc/SuSE-release ]] && { alias tmsg='tail -n150 /var/log/messages' alias tmsgf='tailf /var/log/messages' # <snip> } If you do anything from a host specific standpoint, then hostname conditionals also work fine: [[ $HOSTNAME == nirvana ]] || [[ $HOSTNAME == archangel ]] && alias sdns='cat /var/named/dyn/3111skyline.com' (** cheezy 'show dns' forward zone dump) ...and for those wondering "why all the effort to set your favorite aliases?" Answer: once you have your top 20 or so tasks reduced to 3 or 4 char aliases, you will really see what people mean when they talk about the power and efficiency of the command line. There is no limit to what you can do... Combined with the tabbed interfaces in konsole or gnome-terminal, you can cover a great deal of ground in a very short time. -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (1)
-
David C. Rankin