Bash 3.0
When I build bash 3.0 from (abs) source, it hangs after any output to the terminal. But the bash 3.0 downloaded via pacman works fine.
I reinstalled 0.6 and upgraded all packages via pacman, to have a plain vanilla system with no local mods. But still, when I compile bash 3.0 from source, it hangs the terminal when trying something as simple as "ls -al". However, bash 2.05 builds and works without any problem.
Is this due to a difference in packages between the repository build environment and mine? Must be I guess. But I don't really know what to look at. Ncurses? Readline?
Any ideas?
iphitus wrote:Try disabling any extra CFLAGs you might have applied?
To quote myself:
I reinstalled 0.6 and upgraded all packages via pacman, to have a plain vanilla system with no local mods.
Not even CFLAGS.
Similar Messages
-
Using bash as your file manager?
Hello,
My belief is that all file managers suck. There are no exceptions to this. So, for the past few months, I've been sourcing a file with a bunch of tricks I've invented / found through browsing the web to make using just bash as a file manager much more convenient.
Here's what I currently use:
# fm v1.9.1 by Kiah Morante
# A very simple file manager.
# Depends on pycp/pymv, http://github.com/yannicklm/pycp and feh
# 'source' this file in a BASH shell
showHidden=0 # Hidden files not shown
showDetails=0 # ls is replaced with ls -lh if showDetails is 1
shopt -s autocd # cd to a dir just by typing its name
PROMPT_COMMAND='[[ ${__new_wd:=$PWD} != $PWD ]] && list; __new_wd=$PWD' # ls after cding
# Shortcuts
source ~/.config/fm/shortcuts # Call all custom shortcuts
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias h='cd ~'
alias n='cd "$n"'
# Keybindings
bind '"\C-l":"list\C-m"'
bind '"\C-h":"hide\C-m"'
bind '"\C-o":"details\C-m"'
bind '"\C-f":"makedir\C-m"'
bind '"\C-n":"n\C-m"'
bind '"\C-y":"cpwd\C-m"'
bind '"\C-p":"cd "$OLDPWD"\C-m"' # Hint: You could also type '~-'
# FM prompt appearance
if [[ $(whoami) == 'root' ]]; then
# So that the user knows if they have root privileges:
PS1="\[\e[0;32\]mf\[m\e[m\] \[\e[0;31m\]root\[\e[m\] \[\e[0;34m\]\w \[\e[m\]\[\e[0;31m\]> \[\e[m\]"
else
PS1="\[\e[0;32\]mf\[m\e[m\] \[\e[0;34m\]\w \[\e[m\]\[\e[0;31m\]> \[\e[m\]"
fi
# Functions
# Usage
fmhelp () {
echo "hide - toggle hidden (hidden by default)
ls - lists contents of dir(s) passed in args.
lsd - list directories
cd - changed to directory \$1
cp \$@ \$2 - copies file from \$1 to \$2
mv \$@ \$2 - moves file from \$1 to \$2
rm \$@ - deletes \$@
sc \$1 \$2 - make a shortcut called \$1 pointing to \$2. If no \$2 is passed, it is evaluated as \$PWD
cpwd - copy current working directory
.., ..., .... - cd .. etc.
o \$1 - opens \$1 with xdg-open
hm - how many files are in the current directory
details - show file details (ls -lh)
fmhelp - this help menu
n - Intelligent guess of the next dir you wish to cd to. Last $1 in open, list, or makedir; last argument in copy or move; pwd before a cd
~- - BASH shortcut for \$OLDPWD
img - feh frontend with the following usage:
img -t \$2 - views the dirs/images specified in \$2..\$n as clickable thumbnails
img -s \$2 \$3 - views the images specified in \$3..\$n as a slideshow with a slide change speed of \$2 seconds
img \$@ - views the dirs/images specified
Shortkeys:
Ctrl-f - mkdir
Ctrl-h - hide
Ctrl-l - ls
Ctrl-n - cd \$n
Ctrl-o - details
Ctrl-p - cd \$OLDPWD
Ctrl-y - cpwd
Ctrl-u - clear line # urxvt default"
# Toggle display hidden files
# If $showHidden is 1, hidden files are shown
hide () {
showHidden=$(( 1 - $showHidden ))
list
# Toggle display file details
# If $showDetails is 1, file details are shown
details () {
showDetails=$(( 1 - $showDetails ))
list
# ls
listToggle () {
if [[ $showHidden == 1 && $showDetails == 1 ]]; then
ls -C --color -A -lh "$dir"
elif [[ $showHidden == 1 && $showDetails == 0 ]]; then
ls -C --color -A "$dir"
elif [[ $showHidden == 0 && $showDetails == 1 ]]; then
ls -C --color -lh "$dir"
else
ls -C --color "$dir"
fi
list () {
clear # Unclutter the screen
# List pwd if no $1
if [[ $@ == "" ]]; then
set '.'
fi
# List multiple folders:
for dir in "$@"
do
listToggle
done
n="$1" # See 'n' in fmhelp
# use feh to view thumbnails/images/slideshow
img () {
case "$1" in
-t) nohup feh --thumbnails "${@:2}" --thumb-height 120 --thumb-width 120 -S filename -d --cache-thumbnails -B black > /dev/null 2>&1 & ;;
-s) nohup feh "${@:3}" -S filename -d -B black --slideshow-delay "$2" > /dev/null 2>&1 & ;;
*) nohup feh "$@" -S filename -d -B black > /dev/null 2>&1 & ;;
esac
list
# cp
copy () {
if [[ $showHidden == 1 ]]; then
pycp --interactive --all "$@"
else
pycp --interactive "$@"
fi
list
n="${@:(-1)}" # n is the last argument (where stuff is moved to)
# mv
move () {
if [[ $showHidden == 1 ]]; then
pymv --interactive --all "$@"
else
pymv --interactive "$@"
fi
list
n="${@:(-1)}"
makedir () {
if [[ $1 == "" ]]; then
read -e n
set "$n"
fi
if mkdir -- "$1"; then
list # Update pwd to show new dir(s) that have been made.
n="$1"
fi
# rm
remove () {
rm -rfI "$@"
list
# open files
o () {
# To use xdg-open
#nohup xdg-open "$1" > /dev/null 2>&1 &
if [ -f "$1" ] ; then
case "$1" in
*.tar.bz2) tar xjf "$1" ;;
*.tar.gz) tar xzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) rar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xf "$1" ;;
*.tbz2) tar xjf "$1" ;;
*.tgz) tar xzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*.pdf) nohup zathura "$1" > /dev/null 2>&1 & ;;
*.html) nohup luakit "$1" > /dev/null 2>&1 & ;;
*.blend) nohup blender "$1" > /dev/null 2>&1 & ;;
*.avi) nohup mplayer "$1" ;;
*.wmv) nohup mplayer "$1" ;;
*.rmvb) nohup mplayer "$1" ;;
*.mp3) nohup urxvtc -si -sw -sh 30 -e mplayer "$1" > /dev/null 2>&1 & ;;
*.flv) nohup mplayer "$1" ;;
*.mp4) nohup mplayer "$1" ;;
*.ogg) nohup urxvt -si -sw -sh 30 -e mplayer "$1" > /dev/null 2>&1 & ;;
*.wav) nohup audacity "$1" > /dev/null 2>&1 & ;;
*.jpg) img "$1" ;;
*.jpeg) img "$1" ;;
*.JPG) img "$1" ;;
*.png) img "$1" ;;
*.gif) nohup gpicview "$1" > /dev/null 2>&1 & ;;
*) nohup urxvt -si -sw -sh 30 -e vim "$1" > /dev/null 2>&1 & ;;
esac
else
echo "'$1' is not a valid file"
fi
n="$1"
# Add shortcuts
makeShortcut () {
if [[ $2 == "" ]]; then
set $1 .
fi
echo ""$1"=\""$2"\"
alias "$1"='cd \""$2"\"'
" >> ~/.config/fm/shortcuts
source ~/.config/fm/shortcuts
# Copy pwd to clipboard
cpwd () {
echo \"$(pwd)\" | xclip
# List directories
lsd () {
ls -F "$@" | grep \/$
# Command aliases
alias mv="move"
alias sc="makeShortcut"
alias cp="copy"
alias ls="list"
alias rm="remove"
alias mkdir="makedir"
alias hm="ls -l . | egrep -c '^-'"
list # ls when fm starts
Could all of you fellow file manager-haters post your little tricks, whether just a few lines added to ~/.bashrc or fully fledged files that you source like mine?
Last edited by greenmanwitch (2011-02-07 19:58:40)3]) wrote: once you have video files cluttered all throughout your hard drive and folders all over, thats where the 'bash' filemanager system lacks its use in terms of effectiveness.
Actually, I found this to be one of the best advantages of using bash is that it forces a user to think about file organization and making useful naming schemes for files.
For example, instead of having 1000+ media files in one directory I subcategorize theme by genre or whatever, and then probably subcategorize them again.
Then I usually rename the files to something meaningful, like if I have 50 pictures of my kids birthday, just do a for each loop on the directory and rename all the files donovan_birthdayX.jpg where X is an integer incrementation.
essentially. just don't "have files cluttered all throughout you hard drive and folders all over". and your life will be much happier regardless of how you manage your files. -
Best practice for if/else when one outcome results in exit [Bash]
I have a bash script with a lot of if/else constructs in the form of
if <condition>
then
<do stuff>
else
<do other stuff>
exit
fi
This could also be structured as
if ! <condition>
then
<do other stuff>
exit
fi
<do stuff>
The first one seems more structured, because it explicitly associates <do stuff> with the condition. But the second one seems more logical because it avoids explicitly making a choice (then/else) that doesn't really need to be made.
Is one of the two more in line with "best practice" from pure bash or general programming perspectives?I'm not sure if there are 'formal' best practices, but I tend to use the latter form when (and only when) it is some sort of error checking.
Essentially, this would be when <do stuff> was more of the main purpose of the script, or at least that neighborhood of the script, while <do other stuff> was mostly cleaning up before exiting.
I suppose more generally, it could relate to the size of the code blocks. You wouldn't want a long involved <do stuff> section after which a reader would see an "else" and think 'WTF, else what?'. So, perhaps if there is a substantial disparity in the lengths of the two conditional blocks, put the short one first.
But I'm just making this all up from my own preferences and intuition.
When nested this becomes more obvious, and/or a bigger issue. Consider two scripts:
if [[ test1 ]]
then
if [[ test2 ]]
then
echo "All tests passed, continuing..."
else
echo "failed test 2"
exit
fi
else
echo "failed test 1"
fi
if [[ ! test1 ]]
then
echo "failed test 1"
exit
fi
if [[ ! test2 ]]
then
echo "failed test 2"
exit
fi
echo "passed all tests, continuing..."
This just gets far worse with deeper levels of nesting. The second seems much cleaner. In reality though I'd go even further to
[[ ! test1 ]] && echo "failed test 1" && exit
[[ ! test2 ]] && echo "failed test 2" && exit
echo "passed all tests, continuing..."
edit: added test1/test2 examples.
Last edited by Trilby (2012-06-19 02:27:48) -
Sending email using bash script
Hello:
I am working on writing a bash script to notify one or more users by email of certain events. Run from the Terminal command line, and having the script "echo" text of (what would be) a form letter with in-line variable expansion (i.e., ${VARIABLE}), all seems to work as anticipated. Eventually, I want cron to launch this shell script, and send an email to an "on-subnet" user (I have postfix enabled on my Mac, and there are multiple local user accounts).
I found some stuff on the web about sending mail from bash scripts, and so I made a small little test script, that reads like this:
#!/bin/bash
VARIABLE[1]="The 12,345 quick brown foxes "
VARIABLE[2]="jumped over the 67,890 lazy dogs."
mail -s "a test email" jv << EOF
This is a test:
${VARIABLE[1]}
${VARIABLE[2]}
This is the last line of the test message.
EOF
echo "script completed"
It worked... almost... It sent a local email to my postfix mail account that read like this:
This is a test:
The 12,345 quick brown foxes
jumped over the 67,890 lazy dogs.
This is the last line of the test message.
EOF
echo "script completed"
So, I have two questions. First, the easy one (I hope):
How do I delimit the end of the text, that I want to be the message body of the email, from portions of the script that follow said email text?
Next question is a little more involved. You know how, in Mail.app, if you go to Mail Preferences>Accounts>Account Information, you can put multiple email addresses, comma-delimited, in the "Email Address" field? So, if a person entered "[email protected], [email protected], [email protected]" in this field, then, even though (s)he may be at home, and using their home ISP's mail server, (s)he could send an email apparently from either their home, work, or school email address. Of course, the mail headers clearly would show it came from and through their home machine and home ISP, but it would be displayed in the recipient's Mail client viewer as having come from one of [email protected], [email protected], or [email protected].
I'd like to do something similar here, whereby the email (that is being sent to one or more local users' postfix account on my computer) would apparently be sent from "watchdog@localhost" rather than from "jv@localhost" like it seems to do by default. Whatever account the script is run from (or presumbably, whose cron tab is launching the script) is what the "From" address is set to.
I'd rather not create an additional mail account, because I am using Mac OS X built-in accounts for the postfix mailboxes (I don't want to have to maintain a plaintext username:password file in postfix, and I don't want to create an additional user account on the computer).
So, is there a way to specify an alternate "From" username when invoking the mail -s ${SUBJECT} ${RECIPIENT} command in a bash script? Or is there a different, alternate mail command that will let me do so? (please include a description of syntax and how I'd package the above message text for the alternate method).
Thanks in advance, all!Hi j.v.,
The > after EOF is just a typo (or may be added by the Discussion ?) and you must delete it; other > are prompts from the interactive shell. Andy's post shows an interactive use of shell, not a shell script (note the shell prompt % in front of the commands). A typical use of here document may look like
command <<ENDOFDATA
ENDOFDATA
There must be no spaces before and after ENDOFDATA. The word ENDOFDATA can be EOF or any other string which is guaranteed not to appear in the text (the .... in the example above).
You can modify the From: header by using sendmail command (postfix has it as a compatibility interface):
/usr/sbin/sendmail -t <<EndOfMessage
Subject: test mail
To: jv
From: watchdog
This is a test:
${VARIABLE[1]}
${VARIABLE[2]}
This is the last line of the test message.
EndOfMessage
There must be a blank line between the headers and the mail body.
I assume that you send these mails only to users on your local Mac. Please do not send mails to remote users by using the sendmail command unless you know what you are doing completely.
PowerMac G4 Mac OS X (10.4.5) -
[SOLVED] problem with spaces and ls command in bash script
I am going mad with a bash script I am trying to finish. The ls command is driving me mad with spaces in path names. This is the portion of my script that is giving me trouble:
HOMEDIR="/home/panos/Web Site"
for file in $(find "$HOMEDIR" -type f)
do
if [ "$(dateDiff -d $(ls -lh "$file" | awk '{ print $6 }') "$(date +%F)")" -gt 30 ];
then echo -e "File $file is $(dateDiff -d $(ls -lh "$file" | awk '{ print $6 }') "$(date +%F)") old\r" >> /home/panos/scripts/temp;
fi
done
The dateDiff() function is defined earlier and the script works fine when I change the HOMEDIR variable to a path where there are no spaces in directory and file names. I have isolated the problem to the ls command, so a simpler code sample that also doesn't work correctly with path names with spaces is this:
#!/bin/bash
HOMEDIR="/home/panos/test dir"
for file in $(find "$HOMEDIR" -type f)
do
ls -lh "$file"
done
TIA
Last edited by panosk (2009-11-08 21:55:31)oops, brain fart. *flushes with embarrassment*
-- Edit --
BTW, for this kind of thing, I usually do something like:
find "$HOMEDIR" -type f | while read file ; do something with "$file" ; done
Or put those in an array:
IFS=$'\n' ; files=($(find "$HOMEDIR" -type f)) ; unset IFS
for file in "${files[@]}" ; do something with "$file" ; done
The later method is useful when elements of "${files[@]}" will be used multiple times across the script.
Last edited by lolilolicon (2009-11-09 08:13:07) -
I'm having a problem piping the date to dzen2 using the date command in a while loop in bash.
In my startup script I have this line to start the panel and the script to pipe the info:
statusbar | dzen2 -h $PANEL_HEIGHT -dock -ta l -title-name panel -fn $FONT -fg $PANEL_TEXT_LIGHT -bg $PANEL_BG &
and then the statusbar script looks like this:
while true ; do
echo "$(date +%I:%M %p)"
sleep 1
done
That isn't the complete statusbar script, but i've identified the date command as the problem. For whatever reason, when the date command is in the loop, there is no output to the panel, and if I monitor my system resources I can see that my computer's memory is getting used up extremely quickly. It seems like it spawning a bunch of instances of the script. I'm not extremely experienced with linux, and definitely not with bash, so I have absolutely no clue whats going on here.Raynman wrote:
$ echo "$(date +%I:%M %p)"
date: extra operand ‘%p’
Try 'date --help' for more information.
Edit: since you're basically saying you're a newbie (and this also probably fits better in the Newbie Corner), I'll add that you should put the formatting string in (single) quotes to turn it into a single argument.
I'm not saying I'm a newbie at all. The issue occurs even without any parameters to the date command. -
Problem with ssh and bash-completion
I and a co-worker are having a weird problem with ssh and bash-completion. We have a local config in .ssh/config with hosts we connect everyday. An example:
host foo
hostname foo.org
user foobar
host foobar
hostname foobar.org
user foobar
When we try to type
ssh foo<tab><tab>b<tab>
the console just freeze and we can't type anything, everything we type is ignored, but after about 30 seconds the host is completed.
This works a some time ago, so some upgrade make this happen. Anyone can reproduce this?quigybo wrote:
Actually thinking about it, rather than using the semi-dodgy fix posted on the bug tracker, we can just test if the daemon is running since we are not on MacOS X. It is cleaner and 250 ms quicker.
--- bash_completion.orig 2010-09-14 05:33:22.000000000 +0930
+++ bash_completion 2010-09-14 05:45:04.000000000 +0930
@@ -1316,10 +1316,12 @@
# contains ";", it may mistify the result. But on Gentoo (at least),
# -k isn't available (even if mentioned in the manpage), so...
if type avahi-browse >&/dev/null; then
- COMPREPLY=( "${COMPREPLY[@]}" $( \
- compgen -P "$prefix$user" -S "$suffix" -W \
- "$( avahi-browse -cpr _workstation._tcp 2>/dev/null | \
- awk -F';' '/^=/ { print $7 }' | sort -u )" -- "$cur" ) )
+ if [ -n "$(pidof avahi-daemon)" ]; then
+ COMPREPLY=( "${COMPREPLY[@]}" $( \
+ compgen -P "$prefix$user" -S "$suffix" -W \
+ "$( avahi-browse -cpr _workstation._tcp 2>/dev/null | \
+ awk -F';' '/^=/ { print $7 }' | sort -u )" -- "$cur" ) )
+ fi
fi
# Add results of normal hostname completion, unless
This is the same test as was used in bash-completion 1.1.
Thanks quigybo, I use your patch, the issue is gone
Why does so many packages depends on Avahi? Maybe make it optdepends is
enough?
my laptop $ pacman -Qi avahi
Required By : gnome-disk-utility gnome-vfs libcups mpd sane -
[SOLVED] Bash changes consolle's colors by itself
Hi archers,
I've wrote a little script which ask for the result of a given random moltiplication because I was exercising with $RANDOM and something strange's happend.
No matter where I am (Tty, Tmux, Urxvt, Xterm...) Bash changes consolle's colors by itself if I do ^c to stop the script, instead of write a reply.
i.e.'s:
correct behaviour
$ 8 * 9 = ?
$ 72
$ ls
file in red file in yellow file in grey...
Wrong behaviour
$ 8 *9 = ?
$ ^c
$ ls
file in blue file in green file in white...
What the heck?
Bash version is 4.2.39(2)-release.
The script is the following:
while :
do
min="3"
max="7"
fat1="$(($RANDOM%$max+$min))"
fat2="$(($RANDOM%$max+$min))"
prod="$(($fat1*$fat2))"
echo "$fat1 * $fat2 = ?"
read res
while [ "$res" != "$prod" ]
do
echo "$prod"
echo "Insert the correct result."
tavPit
done
return 0
done
Everything is up to date.
.bashrc
[[ $- != *i* ]] && return
complete -cf sudo
[ -f /etc/bash_completion ] && ! shopt -oq posix && . /etc/bash_completion
[ -f ~/.bash/include ] && . ~/.bash/include
[ -e "$HOME"/.dircolors ] && eval $(dircolors -b "$HOME"/.dircolors)
include
#!/bin/bash
[ -f ~/.bash/alias ] && . ~/.bash/alias
[ -f ~/.bash/color ] && . ~/.bash/color
[ -f ~/.bash/export ] && . ~/.bash/export
[ -f ~/.bash/shopt ] && . ~/.bash/shopt
[ -f ~/.bash/stty ] && . ~/.bash/stty
[ -f ~/.bash/set ] && . ~/.bash/set
color
nc="\e[0m"
nbk="\e[0;30m"
nre="\e[0;31m"
ngr="\e[0;32m"
nye="\e[0;33m"
nbl="\e[0;34m"
nma="\e[0;35m"
ncy="\e[0;36m"
nwh="\e[0;37m"
bbk="\e[1;30m"
bre="\e[1;31m"
bgr="\e[1;32m"
bye="\e[1;33m"
bbl="\e[1;34m"
bma="\e[1;35m"
bcy="\e[1;36m"
bwh="\e[1;37m"
end="\[\e[m\]"
man() {
env \
LESS_TERMCAP_mb=$(printf "\e[0;32m") \
LESS_TERMCAP_md=$(printf "\e[0;32m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;31m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;33m") \
man "${@}"
if [ "$TERM" = "linux" ]; then
echo -en "\e]P0000000" # Black.
echo -en "\e]P9ff0000" # Red.
echo -en "\e]PA00ff00" # Green.
echo -en "\e]PBffff00" # Yellow.
echo -en "\e]PC2b4f98" # Blue.
echo -en "\e]PDff00ff" # Magenta.
echo -en "\e]PE00ffff" # Cyan.
echo -en "\e]PFffffff" # White.
clear
fi
.dircolors
TERM linux
TERM linux+utf8
TERM rxvt-unicode
TERM rxvt-unicode-256color
TERM screen
TERM screen-256color
TERM xterm
TERM putty
EIGHTBIT 1
NORMAL 01;30
FILE 01;30
DIR 31
LINK 36
FIFO 03;33
SOCK 03;33
DOOR 32
BLK 32
CHR 32
ORPHAN 05;33
EXEC 33
.tar 31
.tgz 31
.arj 31
.taz 31
.lzh 31
.zip 31
.7z 31
.z 31
.Z 31
.gz 31
.bz2 31
.deb 31
.rpm 31
.jar 31
.rar 31
.xz 31
.jpg 35
.jpeg 35
.gif 35
.bmp 35
.pbm 35
.pgm 35
.ppm 35
.tga 35
.xbm 35
.xpm 35
.tif 35
.tiff 35
.png 35
.fli 35
.gl 35
.dl 35
.xcf 35
.xwd 35
.pdf 35
.ogg 34
.mp3 34
.wav 34
.mov 34
.mpg 34
.mpeg 34
.asf 34
.avi 34
.mkv 34
.wmv 34
.ogm 34
.C 37
.H 37
.c 37
.h 37
.cxx 37
.hxx 37
.cpp 37
.hpp 37
.py 37
.sh 37
.vim 37
.o 37
.so 37
.a 37
.ko 37
.rc 36
*rc 36
Thanks a lot.
Last edited by rix (2012-11-26 15:38:28)Bandit Bowman wrote:My colours are unaffected after running the function. [...]
Here colors change when I send SIGINT to a running instance of my script; as said before.
Bandit Bowman wrote:[...] What does $LS_COLORS look like before and after? [...]
When everything is working right:
$ echo $LS_COLORS
$ no=01;30:fi=01;30:di=31:ln=36:pi=03;33:so=03;33:do=32:bd=32:cd=32:or=05;33:ex=33:
*.tar=31:*.tgz=31:*.arj=31:*.taz=31:*.lzh=31:*.zip=31:*.7z=31:*.z=31:*.Z=31:*.gz=31:
*.bz2=31:*.deb=31:*.rpm=31:*.jar=31:*.rar=31:*.xz=31:*.jpg=35:*.jpeg=35:*.gif=35:
*.bmp=35:*.pbm=35:*.pgm=35:*.ppm=35:*.tga=35:*.xbm=35:*.xpm=35:*.tif=35:*.tiff=35:
*.png=35:*.fli=35:*.gl=35:*.dl=35:*.xcf=35:*.xwd=35:*.pdf=35:*.ogg=34:*.mp3=34:
*.wav=34:*.mov=34:*.mpg=34:*.mpeg=34:*.asf=34:*.avi=34:*.mkv=34:*.wmv=34:*.ogm=34:
*.C=37:*.H=37:*.c=37:*.h=37:*.cxx=37:*.hxx=37:*.cpp=37:*.hpp=37:*.py=37:*.sh=37:
*.vim=37:*.o=37:*.so=37:*.a=37:*.ko=37:*.rc=36:*rc=36:
When texts change color (the strange behaviour):
$ echo $LS_COLORS
$
Bandit Bowman wrote:[...] Is this the whole script or just a snippet [...]
Whole.
Bandit Bowman wrote:[...] because I don't see anything that should modify it. [...]
That's why I'm asking.
Bandit Bowman wrote:[...] here's a slightly more straightforward version [...]
Thanks, I've learnt something.
Bandit Bowman wrote:[...] although it won't help with the colours.
Thanks for the reply anyway.
Bandit Bowman wrote:[...] English: [...]
Also, many thanks again.
Edit: solved. "$LS_COLORS" must be set if you want colors.
Last edited by rix (2012-11-26 15:38:06) -
Ctrl-c in bash kill openbox started from rc file as background job
Hi,
Ctrl-c in bash kill openbox started from rc file as background job.
strange, isn't it ?I want to have openbox in the job list of a bash. as if my xinitrc was "exec xterm" and I manualy enter the "openbox &" commande in the xterm window. I suppose this is a common wish : telling bash to read from file then from keyboard, but that not exactly what bashrc do.
"ps j" for openbox started in bashrc
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
1769 1773 1773 845 pts/0 1752 S 1000 0:00 xterm -e bash --rcfile ~/bin/xsession.sh
1 1780 1773 845 pts/0 1752 S 1000 0:00 /usr/bin/dbus-launch --sh-syntax --exit-with-session
1773 1783 1783 1783 pts/2 1805 Ss 1000 0:00 bash --rcfile ~/bin/xsession.sh
1783 1795 1783 1783 pts/2 1805 S 1000 0:00 /usr/bin/openbox --startup /usr/lib/openbox/openbox-autostart OPENBOX
1783 1805 1805 1783 pts/2 1805 R+ 1000 0:00 ps j
"ps j" for openbox started by keyboard or PROMPT_COMMAND
1718 1722 1722 845 pts/0 1701 S 1000 0:00 xterm -title Login -e bash --rcfile ~/bin/xsession.sh
1 1729 1722 845 pts/0 1701 S 1000 0:00 /usr/bin/dbus-launch --sh-syntax --exit-with-session
1722 1732 1732 1732 pts/2 1747 Ss 1000 0:00 bash --rcfile ~/bin/xsession.sh
1732 1744 1744 1732 pts/2 1747 S 1000 0:00 openbox
1732 1747 1747 1732 pts/2 1747 R+ 1000 0:00 ps j
ps have PGID equal to the bash TPGID, so it is foreground. openbox from PROMPT_COMMAND have his own PGID, so it is background. openbox from bashrc share PGID wish bash ... so if bash do not consume Ctrl-c signal openbox receive it ? I assume it is some things like this, but why ? INVOCATION and JOB CONTROL sections in bash manpage do not seems describe this, so that's a strange behaviour. -
Slow and insecure but feature-rich pacman wrapper in bash
This project of mine started because I want to compile my packages in a way that lets me delete gnome apps. Here's the problem: I see that evince depends on gnome-keyring, gnome-keyring depends on gconf and alltray depends on gconf. This leads me to think that if I recompile evince to not use gnome-keyring and recompile alltray to not use gconf, I can delete gconf.
NO!
I have to recompile evince to not use gconf as well because little do I know from pacman's dependency handling... gconf is a direct (but second level) dependency of evince as it's compiled as well.
This is a pretty standard problem. It's the reason why debian dependency lists are so damn long. I don't want Arch to move to a system like that... well sort of. Here's what I did. I made a script that acts just like pacman but when you tell it to download and install a package, it tells pacman to only download that package into a separate cache, then it extracts the package, finds all dynamic executables in the package, uses ldd to determine their library dependencies, uses pacman -Qo to find packages that own these dependencies (and caches them in a file so they can be looked up more quickly in the future), applies some other enhancements that should be visible in the script, then adds the new dependencies to the depends array and makes sure that none are duplicated. It also formats the array so that it goes (original clean dependency list) kernel26 (new list). That way it can parse queries as well so -Qi will omit all the dependencies after kernel26 and the Required By section while -Qii shows everything. This is the perfect compromise for me. Not sure if it will be for you.
Other things it does:
* Checks if AUR packages need updating (but doesn't update them)
* Takes out docs and gconf schemas
* Cleans up man pages so there's no /usr/man and just /usr/share/man/man*
* Convers /usr/share/man/locale/man1/whatever.1.gz to /usr/share/man/man1/whatever-locale.1.gz
* Converts info pages to man pages with info2man and puts them in man9
* Gzips all man pages
* Allows replacing packages with -U
* Package specific stuff like disabling the firefox error console.
Regretably I had to make it play around with the md5sums. This essentially makes them useless but if I don't do this reinstalling a package that is in the main cache because this script put it there fails due to corruption. So you might want to get rid of this "feature" and probably the firefox / uvesafb /gstreamer / info2man stuff but this is cool so tell me what you think of it.
#!/bin/bash
function aur_check {
STARTDIR=`pwd`
cd /var/cache/pacman
for r in `pacman -Qmq`; do
wget "http://aur.archlinux.org/packages/$r/$r/PKGBUILD" >/dev/null 2>&1
if [ $? -eq 0 ]; then
LOCAL_VERSION_REL=`'pacman' -Q $r | awk '{print $2}'`
LOCAL_VERSION=`echo $LOCAL_VERSION_REL| sed -e 's/-.*//g'`
REMOTE_VERSION=`cat PKGBUILD | grep -E '^pkgver=' | sed -e 's/pkgver=//g' | sed -e 's/[ ]*//g'`
REMOTE_REL=`cat PKGBUILD | grep -E '^pkgrel=' | sed -e 's/pkgrel=//g'`
if [[ "$LOCAL_VERSION" < "$REMOTE_VERSION" ]]; then
printf "warning: $r: ignoring package upgrade ($LOCAL_VERSION_REL => ${REMOTE_VERSION}-${REMOTE_REL})\n"
fi
rm PKGBUILD
fi
done
cd $STARTDIR
function sync_check {
STARTDIR=`pwd`
cd /var/cache/pacman
IGNORED_PACKAGES=`cat /etc/pacman.conf | grep -E '^IgnorePkg' | sed -e 's/IgnorePkg[ ]*=[ ]*//g'`
for s in $IGNORED_PACKAGES; do
REMOTE_VERSION_STRING=`'pacman' -Si $s 2>/dev/null | grep -E '^Version'`
if [ $? -eq 0 ]; then
REMOTE_VERSION_REL=`echo $REMOTE_VERSION_STRING | awk '{print $3}'`
LOCAL_VERSION_STRING=`'pacman' -Q $s 2>/dev/null`
if [ $? -eq 0 ]; then
LOCAL_VERSION_REL=`echo $LOCAL_VERSION_STRING | awk '{print $2}'`
printf "warning: $s: ignoring package upgrade ($LOCAL_VERSION_REL => $REMOTE_VERSION_REL)\n"
fi
fi
done
cd $STARTDIR
function remove_crap {
# No docs or schemas.
rm -rf 2>/dev/null ./usr/share/doc
rm -rf 2>/dev/null ./usr/share/gtk-doc
rm -rf 2>/dev/null ./etc/gconf
# Please delete this file. It is not necessary for linking the library.
find . -name "*.la" -exec rm {} \;
# Only one man directory please.
if [ -d ./usr/man ]; then
if [ ! -d ./usr/share ]; then
mkdir ./usr/share
fi
mv ./usr/man ./usr/share/man
fi
if [ -d ./usr/share/man ]; then
cd ./usr/share/man
ls | grep 'cat' | xargs rm -rf
if [ -d ./man ]; then
mv ./man/* .
rm -rf ./man
fi
# Imposes what I consider to be a better naming convention for some reason.
for t in `ls`; do
if [ $t != 'man0' ] && [ $t != 'man1' ] && [ $t != 'man2' ] && [ $t != 'man3' ] && [ $t != 'man4' ] && [ $t != 'man5' ] && [ $t != 'man6' ] && [ $t != 'man7' ] && [ $t != 'man8' ] && [ $t != 'man9' ] && [ $t != 'mann' ] && [ $t != 'manm' ]; then
cd $t
for u in `ls`; do
cd $u
for v in `ls`; do
SECOND_LAST_EXTENSION=`echo $v | sed -e 's/\.gz$//g' | rev | sed -e 's/\..*//g' | rev`
PREFIX=`echo $v | sed -e 's/\.gz$//g' | sed -e "s/\.${SECOND_LAST_EXTENSION}//g"`
SUFFIX=`echo $v | sed -e "s/$PREFIX//g"`
if [ ! -h $v ]; then
install -D $v ../../${u}/${PREFIX}-${t}${SUFFIX}
else
TARGET=`readlink $v`
TARGET_SECOND_LAST_EXTENSION=`echo $TARGET | sed -e 's/\.gz$//g' | rev | sed -e 's/\..*//g' | rev`
TARGET_PREFIX=`echo $TARGET | sed -e 's/\.gz$//g' | sed -e "s/\.${TARGET_SECOND_LAST_EXTENSION}//g"`
TARGET_SUFFIX=`echo $TARGET | sed -e "s/${TARGET_PREFIX}//g"`
install -d ../../${u}
ln -s ${TARGET_PREFIX}-${t}${TARGET_SUFFIX} ../../${u}/${PREFIX}-${t}${SUFFIX}
fi
done
cd ..
done
cd ..
rm -rf $t
fi
done
# Now that it is nicely organized we can gzip everything and add symlinks.
for x in `ls`; do
cd $x
for y in `ls`; do
echo $y | grep -q -E '\.gz$'
if [ $? -ne 0 ]; then
gzip $y >/dev/null 2>&1
SECOND_LAST_EXTENSION=`echo $y | rev | sed -e 's/\..*//g' | rev`
PREFIX=`echo $y | sed -e "s/\.${SECOND_LAST_EXTENSION}//g"`
NEW_NAME=`echo $PREFIX | sed -e 's/\./-/g'`
if [ $NEW_NAME != $PREFIX ]; then
ln -s ${y}.gz ${NEW_NAME}.${SECOND_LAST_EXTENSION}.gz
fi
else
SECOND_LAST_EXTENSION=`echo $y | sed -e 's/\.gz$//g' | rev | sed -e 's/\..*//g' | rev`
PREFIX=`echo $y | sed -e 's/\.gz//g' | sed -e "s/\.${SECOND_LAST_EXTENSION}//g"`
NEW_NAME=`echo $PREFIX | sed -e 's/\./-/g'`
if [ $NEW_NAME != $PREFIX ]; then
ln -s ${y} ${NEW_NAME}.${SECOND_LAST_EXTENSION}.gz
fi
fi
done
cd ..
done
cd ../../..
fi
# Converts info pages to man pages in the man9 directory
if [ -d ./usr/share/info ]; then
if [ -d ./usr/share/man ]; then
mkdir ./usr/share/man/man9
else
mkdir ./usr/share/man
mkdir ./usr/share/man/man9
fi
cd ./usr/share/info
for z in `ls`; do
echo $z | grep -q -E '\.gz$'
if [ $? -eq 0 ]; then
NAME=`echo $z | sed -e 's/\.gz$//g'`
NEWNAME=`echo $NAME | sed -e 's/\./-/g'`
gunzip $z
info2man $NAME > ../man/man9/${NEWNAME}
gzip ../man/man9/${NEWNAME} >/dev/null 2>&1
else
NEWNAME=`echo $z | sed -e 's/\./-/g'`
info2man $z > ../man/man9/${NEWNAME}
gzip ../man/man9/${NEWNAME} >/dev/null 2>&1
fi
done
cd ../../..
rm -rf ./usr/share/info
fi
function install_with_u {
ULTIMATE_ANSWER="y"
# Checks if there are package conflicts
CONFLICTS=`cat .PKGINFO | grep 'conflict = ' | awk '{print $3}'`
ACTUAL_CONFLICTS=""
for p in $CONFLICTS; do
VERSION_CHECK=0
CONFLICTING_PACKAGE=`echo $p | sed -r 's/(>|=|<).*//g'`
# Checks if these conflicts actually affect packages on the system
'pacman' -Q $CONFLICTING_PACKAGE >/dev/null 2>&1
if [ $? -eq 0 ]; then
AFFECTED=1
if [ ${#p} -gt ${#CONFLICTING_PACKAGE} ]; then
AFFECTED=0
# If a version is specified, finds it out and sees if we're affected
CONFLICTING_VERSION_STRING=${p:${#CONFLICTING_PACKAGE}:${#p}-${#CONFLICTING_PACKAGE}}
RELATION=${CONFLICTING_VERSION_STRING:1:2}
if [ "$RELATION" = "=" ]; then
RELATION=${CONFLICTING_VERSION_STRING:0:1}${RELATION}
CONFLICTING_VERSION=${CONFLICTING_VERSION_STRING:2:${#CONFLICTING_VERSION_STRING}-2}
else
RELATION=${CONFLICTING_VERSION_STRING:0:1}
CONFLICTING_VERSION=${CONFLICTING_VERSION_STRING:1:${#CONFLICTING_VERSION_STRING}-1}
fi
ACTUAL_VERSION=`pacman -Q $CONFLICTING_PACKAGE | awk '{print $2}'`
if [ "$RELATION" = ">" ]; then
if [[ "$ACTUAL_VERSION" > "$CONFLICTING_VERSION" ]]; then
AFFECTED=1
fi
elif [ "$RELATION" = "<" ]; then
if [[ "$ACTUAL_VERSION" < "$CONFLICTING_VERSION" ]]; then
AFFECTED=1
fi
elif [ "$RELATION" = ">=" ]; then
if [ "$ACTUAL_VERSION" >= "$CONFLICTING_VERSION" ]; then
AFFECTED=1
fi
elif [ "$RELATION" = "<=" ]; then
if [ "$ACTUAL_VERSION" <= "$CONFLICTING_VERSION" ]; then
AFFECTED=1
fi
else
if [ "$ACTUAL_VERSION" = "$CONFLICTING_VERSION" ]; then
AFFECTED=1
fi
fi
fi
if [ $AFFECTED -ne 0 ]; then
ACTUAL_CONFLICTS="$ACTUAL_CONFLICTS $CONFLICTING_PACKAGE"
printf ":: ${1} conflicts with ${CONFLICTING_PACKAGE}. Remove ${CONFLICTING_PACKAGE}? [Y/n] "
read ANSWER
if [ $ANSWER != "Y" ] && [ $ANSWER != "y" ]; then
ULTIMATE_ANSWER="n"
break
fi
fi
fi
done
if [ $ULTIMATE_ANSWER = "y" ]; then
for q in $ACTUAL_CONFLICTS; do
'pacman' -Rd ${q}
done
return 0
fi
return 1
function get_deps {
PACKAGE_NAME=`cat .PKGINFO | grep 'pkgname = ' | sed -e 's/pkgname = //g'`
# Does a few package specific things
if [ $PACKAGE_NAME = "kernel26" ]; then
ln -s /etc/uvesafb.conf /etc/uvesafb
elif [ $PACKAGE_NAME = "firefox" ]; then
cd ./usr/lib
FIREFOX_DIR=`ls | grep 'firefox'`
if [ $? -eq 0 ]; then
cd $FIREFOX_DIR/chrome
jar -xf ./browser.jar
rm ./browser.jar
sed -i -e '/console.xul/s/^/\/\//g' ./content/browser/browser.js
jar -cf browser.jar content
rm -r content
cd ../..
fi
cd ../..
elif [ $PACKAGE_NAME = "gstreamer0.10-good-plugins" ]; then
rm ./usr/lib/gstreamer0.10/libgstesd.so
fi
POSSIBLE_LIBS=`find . -type f | grep -E '(\.so\.|\.so$)'`
POSSIBLE_BINS=`find . -type f | grep -v 'PKGINFO' | grep -v -E '\/.*\.[a-zA-Z0-9]+$' | grep -v 'LICENSE'`
POSSIBLE_ELFS="$POSSIBLE_LIBS $POSSIBLE_BINS"
DEPS=""
# Makes a list of all the direct dependencies
for i in $POSSIBLE_ELFS; do
#echo "SCANNING: $i"
ldd $i >/dev/null 2>&1
if [ $? -eq 0 ]; then
# Caches the shared libraries in a file to make it easier for everything else to look them up
DIRNAME=`dirname ${i:1:${#i}}`
echo "$i" | grep -q ".so"
if [ $? -eq 0 ]; then
if [ "$DIRNAME" = "/lib" ] || [ "$DIRNAME" = "/usr/lib" ]; then
grep -q "${i:1:${#i}} $PACKAGE_NAME" /var/cache/pacman/quicklookup
# If this package's library assigned to this package was not found...
if [ $? -ne 0 ]; then
grep -q "${i:1:${#i}}" /var/cache/pacman/quicklookup
# It may have been assigned to another package so we change that
if [ $? -eq 0 ]; then
sed -i -e "/${i:1:${#i}}/d" /var/cache/pacman/quicklookup
fi
# Otherwise we just assign it to this package
echo "${i:1:${#i}} $PACKAGE_NAME" >> /var/cache/pacman/quicklookup
fi
fi
fi
# Figures out what packages own the library dependencies
POSSIBLE_DEPS=`ldd $i 2>/dev/null | grep '=> ' | grep -v '=> ' | sed -e 's/.* => //g' | sed -e 's/ (.*//g'`
for j in $POSSIBLE_DEPS; do
DIRNAME=`dirname $j`
if [ "$DIRNAME" = "/lib" ] || [ "$DIRNAME" = "/usr/lib" ]; then
OWNER=`grep "$j" /var/cache/pacman/quicklookup`
# The owner of the dep is either already in the quicklookup file
if [ $? -eq 0 ]; then
OWNER=`echo $OWNER | awk '{print $2}'`
DEPS="$DEPS $OWNER"
else
# Or it's part of the current package
BASENAME=`basename $j`
find . -name ${BASENAME} | grep -q "${BASENAME}"
if [ $? -eq 0 ]; then
echo "$j $PACKAGE_NAME" >> /var/cache/pacman/quicklookup
else
# Or we figure out its owner with pacman and put it in the quicklookup file
OWNER=`'pacman' -Qoq $j 2>/dev/null`
if [ $? -eq 0 ]; then
echo "$j $OWNER" >> /var/cache/pacman/quicklookup
DEPS="$DEPS $OWNER"
fi
fi
fi
fi
done
fi
done
# Sticks a "kernel26" between the old dependencies and the new dependencies
CURRENT_DEPS=`cat .PKGINFO | grep -E '^depend = ' | sed -e 's/depend = //g'`
DEPS="$CURRENT_DEPS kernel26a $DEPS"
# Puts them into the PKGINFO file so that all depend lines are contiguous
grep -q -E '^depend = ' .PKGINFO
if [ $? -eq 0 ]; then
FIRST_DEPEND_LINE_NUMBER=`grep -n -E '^depend = ' .PKGINFO | head -1 | sed -e 's/:.*//g'`
LAST_DEPEND_LINE_NUMBER=`grep -n -E '^depend = ' .PKGINFO | tail -1 | sed -e 's/:.*//g'`
LAST_LINE_NUMBER=`wc -l .PKGINFO | awk '{print $1}'`
(( DIFFERENCE=$LAST_LINE_NUMBER-$LAST_DEPEND_LINE_NUMBER ))
cat .PKGINFO | tail -${DIFFERENCE} > .PKGINFO-3
touch .PKGINFO-2
(( FIRST_DEPEND_LINE_NUMBER-- ))
cat .PKGINFO | head -${FIRST_DEPEND_LINE_NUMBER} > .PKGINFO-1
else
cp .PKGINFO .PKGINFO-1
touch .PKGINFO-2
touch .PKGINFO-3
fi
for k in $DEPS; do
echo "depend = $k" >> .PKGINFO-2
done
# This is all so we don't get mesa and mesa=7.5 in the same dep array
cat .PKGINFO-2 | awk '{print $3}' | sed -r 's/(>=|>|=|<|<=)/ \1/g' > .RAW-DEPS
cat .RAW-DEPS | awk '{print $1}' > .COL-1
cat .RAW-DEPS | awk '{print $2}' > .COL-2
# Got this from sed1line.txt... it removes duplicate lines
sed -i -n 'G; s/\n/&&/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P' .COL-1
paste --delimiter="" .COL-1 .COL-2 > .RAW-DEPS
sed -i -e "/${PACKAGE_NAME}/d" .RAW-DEPS
sed -i -e 's/kernel26a/kernel26/g' .RAW-DEPS
sed -e 's/^/depend = /g' .RAW-DEPS > .PKGINFO-2
sed -i -e "/depend =[ ]*$/d" .PKGINFO-2
cat .PKGINFO-1 .PKGINFO-2 .PKGINFO-3 > .PKGINFO
rm .PKGINFO-1 .PKGINFO-2 .PKGINFO-3 .RAW-DEPS .COL-1 .COL-2
function do_install {
STARTDIR=`pwd`
cd /var/cache/pacman/tmp
for l in `ls -tr`; do
TEMP_DIR=`echo $l | sed -r 's/(-i686|-x86_64|-any|)\.pkg\.tar\.gz//g'`
# Extracts the package and makes the necessary modifications to it
mkdir $TEMP_DIR
mv $l $TEMP_DIR
cd $TEMP_DIR
tar -xf $l >/dev/null 2>&1
rm $l
remove_crap
get_deps
# Retars the package and installs it
if [ -e .INSTALL ]; then
tar -cf $l .INSTALL .PKGINFO * >/dev/null 2>&1
else
tar -cf $l .PKGINFO * >/dev/null 2>&1
fi
# Installs it and puts it in the cache
install_with_u $l
if [ $? -eq 0 ]; then
'pacman' -Udf $l
else
mv $l ../../pkg
cd ..
rm -r $TEMP_DIR
break;
fi
mv $l ../../pkg
cd ..
rm -r $TEMP_DIR
done
cd $STARTDIR
function get_answer {
read ANSWER
echo $ANSWER > /var/cache/pacman/answer
echo $ANSWER
if [ "$1" = "-Syu" ]; then
sync_check
aur_check
'pacman' --cachedir /var/cache/pacman/tmp -Syuw
do_install
elif [ "$1" = "-Su" ]; then
sync_check
aur_check
'pacman' --cachedir /var/cache/pacman/tmp -Suw
do_install
elif [ "$1" = "-S" ]; then
shift
PACKAGE_ARRAY=""
# If something we're installing is in the cache... move it to the temporary cache
for n in $@; do
if [ ${n:0:1} != "-" ]; then
NUM_MATCHES=`ls -1 /var/cache/pacman/pkg | grep -E "^${n}-" | wc -l`
for o in `seq 1 $NUM_MATCHES`; do
POSSIBLE_MATCH=`ls /var/cache/pacman/pkg | grep -E "^${n}-" -m${o} | tail -1`
HYPHENS=`echo $POSSIBLE_MATCH | sed -e "s/${n}//g" | grep -o "-" | wc -l`
if [ $HYPHENS -le 3 ]; then
mv /var/cache/pacman/pkg/${POSSIBLE_MATCH} /var/cache/pacman/tmp
# Changes the stored md5sum temporarily - I don't know a better way to do this
TEMP_DIR=`echo ${POSSIBLE_MATCH} | sed -r 's/(-i686|-x86_64|-any|)\.pkg\.tar\.gz//g'`
find /var/lib/pacman/sync -name $TEMP_DIR | grep -q $TEMP_DIR
if [ $? -eq 0 ]; then
MD5SUM=`md5sum /var/cache/pacman/tmp/${POSSIBLE_MATCH} | awk '{print $1}'`
REPOS=`find /var/lib/pacman/sync -name $TEMP_DIR | sed -e 's/\// /g' | awk '{print $5}'`
sed -i '/%MD5SUM%/G' /var/lib/pacman/sync/$REPOS/$TEMP_DIR/desc
MD5_LINE_NUMBER=`grep -n '%MD5SUM%' /var/lib/pacman/sync/$REPOS/$TEMP_DIR/desc | sed -e 's/:.*//g'`
(( MD5_LINE_NUMBER++ ))
sed -i -e "${MD5_LINE_NUMBER}s/.*/${MD5SUM}/" /var/lib/pacman/sync/$REPOS/$TEMP_DIR/desc
PACKAGE_ARRAY="${PACKAGE_ARRAY} ${REPOS}/${TEMP_DIR}"
fi
break;
fi
done
fi
done
# Pacman is run and then a function reads a y or an n from stdin and passes it to pacman's stdin
get_answer | 'pacman' --cachedir /var/cache/pacman/tmp -Sw $@
# The function also saves it in a file so we know whether to proceed or cancel because pacman was cancelled
LETTER=`cat /var/cache/pacman/answer`
if [ "$LETTER" != "y" ] || [ "$LETTER" != "Y" ]; then
do_install
else
# If anything got moved to the temporary cache for this it is sent back to the main one
FILES_IN_CACHE=`ls /var/cache/pacman/tmp | wc -l`
if [ $FILES_IN_CACHE -ne 0 ]; then
mv /var/cache/pacman/tmp/* /var/cache/pacman/pkg
fi
fi
# Changes all the md5sums back
for w in $PACKAGE_ARRAY; do
MD5_LINE_NUMBER=`grep -n '%MD5SUM%' /var/lib/pacman/sync/$w/desc | sed -e 's/:.*//g'`
(( MD5_LINE_NUMBER++ ))
sed -i -e "${MD5_LINE_NUMBER}d" /var/lib/pacman/sync/$w/desc
done
elif [ "$1" = "-U" ]; then
STARTDIR=`pwd`
TEMP_DIR=`echo $2 | sed -r 's/(-i686|-x86_64|-any|)\.pkg\.tar\.gz//g'`
mkdir /var/cache/pacman/$TEMP_DIR
cp "$2" /var/cache/pacman/$TEMP_DIR
cd /var/cache/pacman/$TEMP_DIR
tar -xf $2 >/dev/null 2>&1
rm $2
get_deps
# Retars the package and installs it
if [ -e .INSTALL ]; then
tar -cf $2 .INSTALL .PKGINFO * >/dev/null 2>&1
else
tar -cf $2 .PKGINFO * >/dev/null 2>&1
fi
install_with_u $2
if [ $? -eq 0 ]; then
'pacman' -U $2
fi
cd ..
rm -r $TEMP_DIR
cd $STARTDIR
elif [ "$1" = "-Qi" ] || [ "$1" = "-Qii" ]; then
INITIAL_ARG=$1
shift
if [ "$INITIAL_ARG" = "-Qi" ]; then
'pacman' -Qi $@ > /var/cache/pacman/tempquery
else
'pacman' -Qii $@ > /var/cache/pacman/tempquery
fi
if [ $? -ne 0 ] || [ ! -e /var/cache/pacman/tempquery ]; then
exit 1
fi
# Filters out all deps after kernel26 for a regular query
# Filters out all deps before kernel26 for a verbose query
if [ $? -eq 0 ]; then
START_LINE_NUMBER=`cat /var/cache/pacman/tempquery | grep -n 'Depends On' | sed -e 's/:.*//g'`
LINE_NUMBER=$START_LINE_NUMBER
(( LINE_NUMBER=$LINE_NUMBER+1 ))
cat /var/cache/pacman/tempquery | head -${LINE_NUMBER} | tail -1 | grep ':'>/dev/null 2>&1
while [ $? -ne 0 ]; do
(( LINE_NUMBER=$LINE_NUMBER+1 ))
cat /var/cache/pacman/tempquery | head -${LINE_NUMBER} | tail -1 | grep ':'>/dev/null 2>&1
done
(( END_LINE_NUMBER=$LINE_NUMBER-1 ))
(( DIFFERENCE=$LINE_NUMBER-$START_LINE_NUMBER ))
OLD_DEP_LIST=`cat /var/cache/pacman/tempquery | head -${END_LINE_NUMBER} | tail -${DIFFERENCE} | sed -e 's/.* : //g' | sed -e 's/ //g'`
for k in $OLD_DEP_LIST; do
if [ "$INITIAL_ARG" = "-Qi" ]; then
if [ "$k" != "kernel26" ]; then
NEW_DEP_LIST="$NEW_DEP_LIST $k"
else
break
fi
else
if [ "$k" != "kernel26" ]; then
NEW_DEP_LIST="$NEW_DEP_LIST $k"
fi
fi
done
fi
# Removes the old deps array and replaces it with the new one
sed -i -e "${START_LINE_NUMBER},${END_LINE_NUMBER}d" /var/cache/pacman/tempquery
(( START_LINE_NUMBER=$START_LINE_NUMBER-1 ))
END_LINE_NUMBER=`wc -l /var/cache/pacman/tempquery | awk '{print $1}'`
(( DIFFERENCE=$END_LINE_NUMBER-$START_LINE_NUMBER ))
cat /var/cache/pacman/tempquery | head -${START_LINE_NUMBER} > /var/cache/pacman/tempquery-1
cat /var/cache/pacman/tempquery | tail -${DIFFERENCE} > /var/cache/pacman/tempquery-3
CURRENT_LINE=""
CURRENT_LINE_NUMBER=1
for m in $NEW_DEP_LIST; do
if (( ${#CURRENT_LINE}+${#m}+1<=63 )); then
CURRENT_LINE="$CURRENT_LINE $m"
else
if [ $CURRENT_LINE_NUMBER -eq 1 ]; then
printf "Depends On :$CURRENT_LINE\n" >> /var/cache/pacman/tempquery-2
else
printf "\t\t$CURRENT_LINE\n" >> /var/cache/pacman/tempquery-2
fi
CURRENT_LINE=" $m"
CURRENT_LINE_NUMBER=0
fi
done
if [ $CURRENT_LINE_NUMBER -eq 1 ]; then
printf "Depends On :$CURRENT_LINE\n" >> /var/cache/pacman/tempquery-2
else
printf "\t\t$CURRENT_LINE\n" >> /var/cache/pacman/tempquery-2
fi
cat /var/cache/pacman/tempquery-1 /var/cache/pacman/tempquery-2 /var/cache/pacman/tempquery-3 > /var/cache/pacman/tempquery
# Removes the requirements array for a regular query
if [ "$INITIAL_ARG" = "-Qi" ]; then
START_LINE_NUMBER=`cat /var/cache/pacman/tempquery | grep -n 'Required By' | sed -e 's/:.*//g'`
LINE_NUMBER=$START_LINE_NUMBER
(( LINE_NUMBER=$LINE_NUMBER+1 ))
cat /var/cache/pacman/tempquery | head -${LINE_NUMBER} | tail -1 | grep ':'>/dev/null 2>&1
while [ $? -ne 0 ]; do
(( LINE_NUMBER++ ))
cat /var/cache/pacman/tempquery | head -${LINE_NUMBER} | tail -1 | grep ':'>/dev/null 2>&1
done
(( END_LINE_NUMBER=$LINE_NUMBER-1 ))
sed -i -e "${START_LINE_NUMBER},${END_LINE_NUMBER}d" /var/cache/pacman/tempquery
fi
cat /var/cache/pacman/tempquery
rm /var/cache/pacman/tempquery /var/cache/pacman/tempquery-1 /var/cache/pacman/tempquery-2 /var/cache/pacman/tempquery-3
elif [ "$1" = "-Scc" ]; then
LINE_NUMBER=0
for z in `cat /var/cache/pacman/quicklookup | awk '{print $1}'`; do
(( LINE_NUMBER++ ))
if [ ! -e $z ]; then
sed -i -e "${LINE_NUMBER}d" /var/cache/pacman/quicklookup
(( LINE_NUMBER-- ))
fi
done
'pacman' -Scc
else
'pacman' $@
fi
Last edited by ConnorBehan (2009-09-19 00:42:48)rls wrote:ABS is fine, but unless I am mistaken, it does nothing to ensure the configure and make stages go smoothly. It is a good way to integrate "home-rolled" packages into the Arch system.
hmmmm... I could be wrong because I've never used Gentoo, but if you make a package that doesn't already exist for Gentoo, does it do anything to make sure the compilation goes smoothly? If the package exists, then there is a way to build the package that has been tested by somebody else. This is how ABS works too; if a PKGBUILD exists, you can be reasonably sure it will work.
I can't imagine a program that can automatically fix or recover from compiler or Makefile errors. If it does, then... wow.
I assume that Gentoo has a larger package base than Arch, but let's not get into that discussiong again!
Xentacs script is basically designed to allow you to choose whether you are going to install from source or binary. Assuming the PKGBUILDS are in order (which for arch repository programs they are, because the binaries were built from them!), this should work as flawlessly as installing from binaries.
Dusty -
Can't get conky-cli and bash scripts to both display in dwm statusbar!
I'm trying to configure my dwm status bar to display some simple information using conky-cli and bash scripts. At first I tried just letting conky run the bash scripts (for network and volume state), but this increased my cpu usage by about 5%, which is significant considering I normally have 1-3% usage when idle. Also, I wanted to keep conky because it makes the display of certain information easy, such as cpu & RAM usage.
The problem is I'm having trouble getting both to display side by side. Here are the relevant parts of my .xinitrc:
network(){
iwconfig wlan0 2>&1 | grep -q no\ wireless\ extensions\. && {
echo wired
exit 0
essid=`iwconfig wlan0 | awk -F '"' '/ESSID/ {print $2}'`
stngth=`iwconfig wlan0 | awk -F '=' '/Quality/ {print $2}' | cut -d '/' -f 1`
bars=`expr $stngth / 10`
case $bars in
0) bar='[-------]' ;;
1) bar='[#------]' ;;
2) bar='[##-----]' ;;
3) bar='[###----]' ;;
4) bar='[####---]' ;;
5) bar='[#####--]' ;;
6) bar='[######-]' ;;
7) bar='[#######]' ;;
*) bar='[--!!!--]' ;;
esac
echo $essid$bar
exit 0
volume(){
vol=$(amixer get Master | awk -F'[]%[]' '/%/ {if ($7 == "off") { print "MM" } else { print $2 }}' | head -n 1)
echo Vol: $vol%
exit 0
conky | while true; read line; do xsetroot -name "`$line` `volume` `network` `date '+%a %m-%d-%Y %I:%M%p'`"; done &
exec dwm
(let me know if it would help to post any other files)
For some reason when I run this I only get the network/volume scripts and date running, updating every second (I think). The conky line just doesn't show up. I don't know what could be wrong, since I didn't see any error messages.
An even better solution would be to just have shell scripts to display CPU and MEM usage. I have a dual-core cpu, cpu0 and cpu1. I'd like to see both percentages if possible, or at least a percentage that is an accurate average of the two or something. In conky-cli I have something that shows:
cpu0/1: xx% xx%
Also, seeing RAM usage would help a lot. In conky it shows:
mem: xx% (xxxMB)
These are the ways I would like to have bash scripts show them, if possible, but I have zero skill in bash programming. I made this an option in case it's easier/cleaner/less resource hungry than a conky solution. Personally, if they're about the same in these aspects, I would prefer something with conky and the shell scripts because conky is so extensible, yet it's only flaw is executing scripts with minimal resource usage.
Help?Thanks. I was thinking of using load average to save a few characters, but I didn't quite understand the numbers. I'll try that once I get to my Linux box, but could you please explain or post a link to something that explains load average (what's low, high, normal, etc.)?
EDIT: I found a website that explains loadavg. I now have my dwm status bar displaying it perfectly (yay!). Now I just need to add a few more things like battery status, etc. and I might be done. I'll probably post here if I have more questions, though.
Thanks for your help!
Last edited by Allamgir (2009-07-18 14:41:11) -
How Can I Pass a Bash Variable to AppleScript?
Here's the deal. I'm used to just using sudo to edit files I don't have write access to, but the mate command doesn't work with sudo, so I end up entering my password twice (once with sudo and again when I want to save the file). To get around this I decided to sidestep the mate command completely and write my own script that will let me open TextMate either normally or as root using sudo. Here's what I have so far:
#!/usr/bin/env bash
tm=`ps ax | grep '[T]extMate'`
if [ "$tm" = ""]; then
/Applications/TextMate.app/Contents/MacOS/TextMate &
fi
osascript << EOT
tell application "TextMate"
activate
open "$@"
end tell
EOT
I originally tried just passing the files as arguments directly to the TextMate executable, but for some reason it opens them all as blank files instead of opening the existing files, so I figured I'd use AppleScript to open them once the application is open. The problem is that "$@" doesn't return all the arguments passed to the script, and I don't know what the AppleScript equivalent is (if there is one), so I need a way of passing that value directly to my AppleScript so I can tell it which files to open. I have no idea how to do that, though. Any ideas?That's exactly what the mate command does, and as I said, that's not what I want. I can't run TextMate with sudo and get root privileges that way because open will be run as root but the actual application itself will still be run normally. The only way I can open an app with root privileges (that I know of) is to use sudo to run the executable inside the app directly (sudo /Applications/SomeApp.app/Contents/MacOS/SomeApp). Opening it that way lets me open multiple instances of the same app, though, so I have to check if it's already open, and it doesn't bring the app to the front, so I use AppleScript to do that. Then once the app is running, I open the files in it. This way I can run the script with sudo and edit files that I don't have write privileges for without TextMate asking me for my password when I want to save them.
-
How can you deny bash system access when sourcing a file?
I'm having another one of my "Linux noob" moments. This is probably easy to answer for the experienced bashers here.
I need a bash function to extract data from a PKGBUILD for use in other scripts. I want to write it in such a way that there is no significant risk when checking PKGBUILDs from possibly untrusted sources. It would be unreasonable to request the user to manually inspect every PKGBUILD when only extracting information (i.e. not building the package) and when dealing with many PKGBUILDs.
The function itself is very simple in the unsafe version:
for ARG in $@; do
source "$ARG"
echo "$pkgname $pkgver $pkgrel"
done
The reason that I want to source the file is to catch variable changes within the script (obviously missing the build function, but there are some that change outside of it). Parsing the file externally is likely to miss some changes.
How can I safely source the PKGBUILD? Ideally I want to completely limit access to the system, specifically the users home directory. Is there a way to do this as a user without write permissions? Is this what the "nobody" user is for?
I've considered using chroot but that appears to need root privileges. I want to avoid sudo.
Thanks.
Last edited by Xyne (2009-05-19 11:09:25)Well, unsetting the PATH seems a good idea, but what if the pkgbuild contains sth like this:
pkgver=$(uname -r)
or any similar manner of dynamically generating one of the variables Xyne's interested in by using a command in a subshell? While the following works (i.e. fails as it should):
~$> OLDPATH=$PATH;export PATH="";/bin/bash -r -c 'foo=$(rm foo);foo=$(/bin/rm foo)';export PATH=$OLDPATH
/bin/bash: rm: No such file or directory
/bin/bash: /bin/rm: restricted: cannot specify `/' in command names
any legitimate use of command substitution will fail as well. Not to mention redirection, which is disabled in a restricted shell as well.
And yes, disabling (possibly) malicious bash builtins may be done as well, but it will fail as well if they are used in a legitimate way.
Using "nobody" also relies on the assumption that the user's files aren't world-writable. I think the only safe solution is using a chroot after all, but maybe I'm missing something here. -
Bash script: Rotate your wallpaper and SLiM theme at the same time
EDIT;
I've decided I should really thank Cerebral for his help with writing this script; this thank you should have been here from the get go.
After writing:
#!/usr/bin
echo "Hello World!"
I wrote a script to rotate my fluxbox background and SLiM theme at the same time, so I could have a contiuously changing background and still have a smooth transition from SLiM to fluxbox. (It just looks so much cooler when both have matching backgrounds). By the time you finish reading it, and configuring your box so it will work, you will probably have decided you could have writtin your own, better script to do the same thing. But, on the off chance anybody finds use for it, here it is:
(this should be obvious, but: don't run this script without at least reading the comments)
#!/bin/bash
#this is a script to rotate a number of backgrounds
#to be shared by the fluxbox desktop and SLiM login manager.
#it is the first meaningful script I've written. It may be
#freely distributed and used with the understanding that you are
#using it at your own risk.
#Before running this script you need to check that your SLiM
#themes are installed to the path /usr/share/slim/themes, which
#is the defulat path for installation in Arch. Here are some
#other things you need to set up:
#1. create (if you don't have it) the directory /usr/share/wallpapers
#2. create a wallpaper in /usr/share/wallpapers called 'dummy' by copying
#you current wallpaper to that filename
#3. set your window manager to display the wallpaper 'dummy', this works fine
#using a style overlay in fluxbox, I haven't tested it with any other window
#manager, but I don't see why this would cause a problem.
#4. create a directory /usr/share/slim/themes/current, you can copy one of
#your slim themes into that directory if you want. (this will prevent you
#from seeing some error messages the first time you run the script)
#5. define the names of the themes you want to rotate, in order for this
#script to work, you must name them "themeNUMBER", where NUMBER is replaced
#by an integer. Your themes must be numbered consecutively, start with 1
# that is:
#theme1 , theme2, theme3, etc. , theme305
#If you don't number consecutively, this script will not run properly. You
#must also define the total number of themes as "rotate_number"
#6. Check if the script runs, if it does, you should change /etc/slim.conf to
#use the theme "current"
#7. This theme will now rotate your SLiM theme and wallpaper in such a way as
#to make them match each other. Note that SLiM will not let you change themes
#"on the fly", (as of July 6, 2008), so changes will not be apparent unless you
#restart SLiM. I run the script before I run slim in my etc/rc.local local
#script, so each time I reboot I get different wallpaper / login background.
#Fred Drueck 2008
#Define here all themes to be rotated and the total number of
#themes to rotate:
rotate_number=9
theme1=/usr/share/slim/themes/default
theme2=/usr/share/slim/themes/lake
theme3=/usr/share/slim/themes/lunar
theme4=/usr/share/slim/themes/flower2
theme5=/usr/share/slim/themes/the-light
theme6=/usr/share/slim/themes/mindlock
theme7=/usr/share/slim/themes/parallel-dimensions
theme8=/usr/share/slim/themes/wave
theme9=/usr/share/slim/themes/fingerprint
#check you are running this script as super-user:
if [ $(id -u) != "0" ]; then
echo "You must be the superuser to run this script" >&2
exit 1
fi
echo "rotating themes"
#figure out which theme is currently set, then name it as the variable
#"last theme number", otherwise set last theme number as 0
if [ -f /usr/share/slim/themes/current/current_theme_number ]
then
echo "checking current theme"
cd /usr/share/slim/themes/current/
eval last_theme_number=$(cat /usr/share/slim/themes/current/current_theme_number)
echo $last_theme_number
else
echo "no theme is currently set, using theme 1"
last_theme_number=0
echo $1 > /usr/share/slim/themes/current/current_theme_number
fi
#set the new theme number
eval new_theme_number=$(($(($last_theme_number % $rotate_number))+1))
#select the new theme
placeholder=theme
eval new_theme=\$$placeholder$new_theme_number
echo $new_theme
#now clean out the "current" theme where I keep the current
#theme for slim
rm /usr/share/slim/themes/current/background*
rm /usr/share/slim/themes/current/panel*
rm /usr/share/slim/themes/current/slim.theme
#the wildcards are there since the themes use jpg and png files
cp $new_theme/background* /usr/share/slim/themes/current
cp $new_theme/panel* /usr/share/slim/themes/current
cp $new_theme/slim.theme /usr/share/slim/themes/current
#increase the theme number, but first clear the old file
rm /usr/share/slim/themes/current/current_theme_number
echo $new_theme_number > /usr/share/slim/themes/current/current_theme_number
#copy over the dummy wallpaper in "/usr/share/wallpapers" (with the theme
#background file
cp $new_theme/background* /usr/share/wallpapers/dummy
exit 0
Last edited by pseudonomous (2008-07-07 21:59:42)oh i forgot to mention... its rotating while moving. i.e. is doesn't have to stop rotate and then continue back to origin.
-
[SOLVED] After pacman glibc update, cannot find command bash?
A few days ago I ran into a problem after running pacman -Syu that ended up with an unbootable system. I found this topic that ultimately solved the kernel panic-
https://bbs.archlinux.org/viewtopic.php … 1#p1127251
All that was needed was a symlink "/lib" to point to "/usr/lib"
My system now almost boots but luckily I can now get a to a shell (zsh). The problem is that I can not run bash, and various other tools- including my desktop environment and pacman.
I have checked my $path, and have verified that I have the binary file "/usr/bin/bash" and a symlink in /bin/bash to point to that binary file, which does exist...
% ls -l /bin/bash
lrwxrwxrwx 1 root root 13 May 24 23:43 /bin/bash -> /usr/bin/bash
% ls -l /usr/bin/bash
-rwxr-xr-x 1 root root 738008 Mar 13 00:47 /usr/bin/bash
But when I try to start a bash shell or run a script
% bash
zsh: command not found: bash
% pacman
zsh: command not found: pacman
% /usr/bin/bash
zsh: no such file or directory /usr/bin/bash
% cat test.sh
#!/bin/bash
echo "Hello World"
% ./test.sh
zsh: ./test.sh: bad interpreter: /bin/bash: no such file or directory
I hope i was thorough enough in providing information about my system, but please let me know if there's anything else I left out that may be able to help.
Thanks so much!
[SOLVED]- Ended up mounting my system from a live install cd, and copying over each bash binary in my system with the live media's binary.
Last edited by OrangeCrush (2013-05-25 06:38:43)If it has only been a few months, that thread should have nothing to do with what you are experiencing. That problem stemmed from when the filesystem was actually changed from having /lib as an actual directory to /lib as a symlink to /usr/lib. Oh the problems that caused. For me it went perfectly smooth... well I did have to search for and rid /lib of extraneous unowned files, but it was smooth after that.
You say though that you did not have a /lib symlink when you checked, and then you created it? This is odd, as that is part of the filesystem package and therefore a tracked file. Maybe you should start by reinstalling the filesystem package just to make sure that the necessary components of the filesystem are all in order before proceeeding.
BTW, you should really update more often than every "few months" as that is what using a rolling release is all about. Also if you don't update very often still, never update the database (-Sy) without also updating the system (-Syu) as this will lead to partial upgrades, which can severly break your system. So never do "pacman -Sy <package>" as that is the equivalent of doing just a "pacman -Sy" and then continuing on your merry way. Big changes are in the air right now around these parts, so keeping your system up to date is probably going to be crucial in making subsequent updates as pain free as possible (we are heading towards the final /bin -> /usr/bin move!). -
Getting 2 errors in bash script
/Users/Myname/Desktop/Printer Install 2: line 115: unexpected EOF while looking for matching `"'
/Users/myname/Desktop/Printer Install 2: line 119: syntax error: unexpected end of file
logout
Please help I have no idea what is causing it. If I do a fake example script it works fine.
#!/bin/bash
PS3='Please enter your choice: '
options=("Andover" "Barkhamsted" "Berlin" "Bethany" "Bethlehem" "Bolton" "Bozrah" "Branford" "Bridgeport" "Bristol" "Brookfield" "Brooklyn" "Burlington" "Canaan" "Canton" "Chaplin" "Chester" "Colebrooke" "Cornwall" "Coventry" "Cornwall” Cromwell" "Danbury" "Darien" "Deepriver" "Derby" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Andover")
/usr/sbin/lpadmin -p Andover -L Unknown -E -v lpd:/172.16.62.160 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ CPP4005.gz
echo "installed Andover”
"Barkhamsted")
/usr/sbin/lpadmin -p Barkhamsted -L Unknown -E -v lpd:/172.16.62.124 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ 4200\ series.gz
echo "installed Barkhamsted”
"Berlin”)
/usr/sbin/lpadmin -p Berlin -L Unknown -E -v lpd:/172.28.165.249 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ 400\ M401dne.gz
echo “Installed Berlin”
"Bethany”)
/usr/sbin/lpadmin -p Bethany -L Unknown -E -v lpd:/172.16.62.17 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ P3010\ series.gz
echo “installed Bethany”
"Bethlehem")
/usr/sbin/lpadmin -p Bethlehem -L Unknown -E -v lpd:/172.16.62.74 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ P3005.gz
echo “Installed Bethlehem”
"Bolton")
/usr/sbin/lpadmin -p Bolton -L Unknown -E -v lpd:/172.16.62.64 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ P3005.gz
echo “Installed Bolton”
"Bozrah")
/usr/sbin/lpadmin -p Bozrah -L Unknown -E -v lpd:/172.16.62.89 -P afp:/al786.law.yale.edu/printers/PPDs/Contents/Resources/Kyocera\ CS\ 520i.PPD
echo “Installed Bozrah”
"Branford")
/usr/sbin/lpadmin -p Branford -L Unknown -E -v lpd:/172.16.62.83 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ 2430.gz
echo “Installed Bradford”
"Bridgeport")
/usr/sbin/lpadmin -p Bridgeport -L Unknown -E -v lpd:/172.16.62.250 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ P3005.gz
echo “Installed Bridgeport”
"Bristol")
/usr/sbin/lpadmin -p Bristol -L Unknown -E -v lpd:/172.28.84.109 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ P3010\ series.gz
echo “Installed Bristol”
"Brookfield")
/usr/sbin/lpadmin -p Brookfield -L Unknown -E -v lpd:/172.16.62.62 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ P3010\ series.gz
echo “Installed Brookfield”
"Brooklyn”)
/usr/sbin/lpadmin -p Brooklyn -L Unknown -E -v lpd:/172.16.62.86 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ P3010\ series.gz
echo “Installed Brooklyn”
"Burlington”)
/usr/sbin/lpadmin -p Burlington -L Unknown -E -v lpd:/172.16.62.44 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ P3010\ series.gz
echo “Installed Burlington”
"Canaan")
/usr/sbin/lpadmin -p Canaan -L Unknown -E -v lpd:/172.16.62.91 -P /Library/Printers/PPDs/Contents/Resources/HP\ Color\ LaserJet.gz
echo “Installed Canaan”
"Canton")
/usr/sbin/lpadmin -p Canton -L Unknown -E -v lpd:/172.16.62.101 -P /Library/Printers/PPDs/Contents/Resources/HP\ Color\ LaserJet\ 4650.gz
echo “Installed Canton”
"Chaplin")
/usr/sbin/lpadmin -p Chaplin -L Unknown -E -v lpd:/172.28.84.213 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ P4010_P4510\ series.gz
echo “Installed Chaplin”
"Chester")
/usr/sbin/lpadmin -p Chester -L Unknown -E -v lpd:/130.132.165.125 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ 5Si\ Mopier.gz
echo “Installed Chester”
"Colebrooke")
/usr/sbin/lpadmin -p Colebrooke -L Unknown -E -v lpd:/172.28.165.199 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ P3010\ series.gz
echo “Installed Colebrooke”
"Cornwall”)
/usr/sbin/lpadmin -p Cornwall -L Unknown -E -v lpd:/172.16.62.20 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ 4350.gz
echo “Installed Cornwall”
"Coventry")
/usr/sbin/lpadmin -p Cornwall -L Unknown -E -v lpd:/172.16.62.20 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ 4350.gz
echo “Installed Coventry”
"Cromwell")
/usr/sbin/lpadmin -p Cromwell -L 127-Wall-St-RM345 -E -v lpd:/172.16.62.47 -P /Library/Printers/PPDs/Contents/Resources/Ricoh\ Aficio\ MP\ 6002.gz
echo “Installed Cromwell”
"Danbury")
/usr/sbin/lpadmin -p Danbury -L Unknown -E -v lpd:/172.16.62.70 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ 5200.gz
echo “Installed Danbury”
"Darien")
/usr/sbin/lpadmin -p Darien -L Unknown -E -v lpd:/172.16.62.63 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ 5100\ Series.gz
echo “Installed Darien”
"Deepriver")
/usr/sbin/lpadmin -p Deepriver -L Unknown -E -v lpd:/172.16.62.23 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ 9050.gz
echo “Installed Deepriver”
"Derby")
/usr/sbin/lpadmin -p Derby -L Unknown -E -v lpd:/172.16.62.76 -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\ P3005.gz
echo “Installed Derby”
"Quit")
break
*) echo "invalid option"
esac
done1. Can I suggest creating a CSV file, which has a three fields per line, e.g.
Andover,172.16.62.160,CPP4005.gz
2. Write a simple loop
PS3='Please enter your choice: '
# Get option. Add logic if it is not Quit
Cty=`grep "${UserInput}" CSVFileName | awk '{print $1}'`
Ip=`grep "${UserInput}" CSVFileName | awk '{print $2}'`
Fname=`grep "${UserInput}" CSVFileName | awk '{print $3}'`
echo "Installing ${Cty}"
/usr/sbin/lpadmin -p ${Cty} -L Unknown -E -v lpd:/${Ip} -P /Library/Printers/PPDs/Contents/Resources/HP\ Laserjet\${Fname}
echo "Installed ${Cty}"
The script remains untouched if you add or remove input lines, instead of having to modify the script to address the Case statements.
PS: This should be to the OP.
Maybe you are looking for
-
Error message when opening flex table graphic
Hello, we're currently implementing our business processes in our CRM 7.0 SP3. This message is about an issue in the area the flex table graphics. When trying to display it, error message "Error while loading data. Graphic is reset to its initial sta
-
INSERT query or Transact-query
Hi folks, need some guidance here, do I use INSERT query or Transact-query to create a Customer order. I have 4 tables, details below; I would like to save this query as a Stored Procedure as the front end will be asp webpage. If possible could you p
-
IChat font sizes show up too large on other computers
Has anyone else seen an issue with iChat 4's fonts showing up considerably larger on other people's (usually Windows-based) computers? I'm using the default Helvetica 12 and it shows up at least 2px larger on other's screens. If I make the font close
-
hi all How to fecth the Goods receipt no(material Document no) and Invoice Receipt no for a particular Purchase order. i want from which tables i will get those information along with relation between tables...
-
Buddies on line but showing as offline
Hi my father in law has just bought a new macbook pro and trying to set up ichat so we can talk online. I have been using ichat successfully with other family members, but for some reason we can't get his to work with us. At the moment my status on h