Friday, March 29, 2013

Disable wildcard expansion when calling BASH scripts

This is a rarely needed, but very useful item. I wanted to create a script that I could pass wildcards into. But bash will automatically expand wildcards before the script can get them, so running

$ myscript.sh *

will call myscript with a bunch of filenames instead of the "*" character.

The solution is to create an alias to disable globbing:

noglob_helper() {
    "$@"
    case "$shopts" in
        *noglob*) ;;
        *) set +f ;;
    esac
    unset shopts
}

alias noglob='shopts="$SHELLOPTS"; set -f; noglob_helper'
Now you can preface your script with the alias and the wildcards will not be expanded:

$ noglob myscript.sh *

This code is from Simon Tatham's home page (the author of PuTTY among other things) http://www.chiark.greenend.org.uk/~sgtatham/aliases.html

Outlook 2010 in Wine on Arch Linux

I have been trying for WAY too long to get Outlook to connect to my exchange account under wine. This is mostly because I just can't seem to find anything else that works, I've been using Thunderbird but Meeting invitations don't appear in my Inbox. My "new message count" shows I have new messages, but there is nothing in my Inbox and there seem to be no plugins that can get it to work properly, plus I don't seem to be be able to get the exchange calendar to work.

Anyway, I finally figured out why Outlook running on Wine would not connect... My smb.conf file was missing. So the solution was....

# cp /etc/samba/smb.conf.default /etc/samba/smb.conf

And everything worked perfectly. I figured this out by the way by starting Outlook from command line with a bunch of overly complex options and seeing an error message saying that /etc/samba/smb.conf was missing.

Permissions problems when using UserDir mod with Apache2

I have had trouble in the past getting Apache to work properly with the UserDir mod. I just installed a new server and had to solve the problem again. In the past I set ww-data (Apache's user) as the group owner for all user's home folders as well as public_html, which is a pain and feels wrong somehow.

Turns out the issue is that Apache needs executable access on all parent folders at the "everyone" level.

So anyway, the following command did the trick by setting the x bit at all levels on the home directories.

# chmod 711 /home/*

The downside of course is that someone can run applications in any other user's home folder if they know the name of the program and where it is stored.
This forum exchange tipped me off to the solution.

Wednesday, March 20, 2013

Add existing user to a group

I can never seem to remember how to do this without having to search. There are way to many programs that allow users and groups to be created/updated/modified.

Add an existing user to an existing group:
# usermod -a -G <group> <user>

Or for a list of groups:
# usermod -a -G <group1,group2,...> <user>

I found this at http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/

Tuesday, March 12, 2013

Using pacman

From https://wiki.archlinux.org/index.php/Pacman_Tips

Finding what pacman installs

This is what I actually was looking for was how to show what pacman installs for a given package. I didn't find it on the wiki page, but at https://bbs.archlinux.org/viewtopic.php?id=89448

$ pacman -Qql packagename

Remove packages with dependencies

If a package has dependencies, pacman will not allow you to remove it saying it is required for the dependencies. Use the -Rdd option to remove it anyway and leave the dependencies. This allows upgrading versions etc...
$ pacman -Rdd packagename

Remove old cached packages with paccache (from package "pacman-contrib") 

Packages are cached in /var/cache/pacman/pkg/. By default "paccache -rv"  deletes all but the most recent 3 versions of packages, I have no idea why I would ever want to go back 3 versions of something. Adding -k n allows you to specify the number of versions. (this freed over a gigabyte for me, and I just installed arch about 2 months ago)

$ paccache -rv -k 1

Install from a package file

$ sudo pacman -U filename.pkg.tar.xz

Remove package along with unneeded dependencies and configuration files

$ sudo pacman -Rns packagename

Show detailed information on package

Installed package:

$ pacman -Qi packagename

From repository:

$ pacman -Si packagename

Remove orphans recursively

$ pacman -Rs $(pacman -Qtdq)

Wednesday, March 6, 2013

TinyOS, TOSSIM and the Yeti2 plugin for Eclipse

I've wrestled with this for quite some time. Everything worked except the tossim code kept showing as an error in Eclipse.

I had added the tossim folder as an include location, but it didn't seem to matter. I finally tried clicking on some of the settings and found that by left clicking you toggle through the options. So after I made the settings look as in the image, my TOSSIM errors finally went away.

NCC: Consider, default was ignore
Include: Source, default was never
Search: Recursive, default was flat





Friday, March 1, 2013

The ip command (iproute2) and virtual interfaces

I've never quite gotten the hang of using "ip" in place of ifconfig, but this blog post shows how to do several things I have wondered about.
The main thing I was looking for was how to add and delete a virtual interface which required some additional research.

The not at all obvious way to get help on this is:
# ip link add help
or
# man ip-link

Show status of interfaces

# ip ad
<... snipped loopback stuff ...>
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 5c:26:0a:2b:29:54 brd ff:ff:ff:ff:ff:ff
    inet 64.112.251.9/21 brd 64.112.255.255 scope global eno1
    inet6 fe80::5e26:aff:fe2b:2954/64 scope link
       valid_lft forever preferred_lft forever

Add a virtual interface

# ip link add type veth
# ip ad
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 5c:26:0a:2b:29:54 brd ff:ff:ff:ff:ff:ff
    inet 64.112.251.9/21 brd 64.112.255.255 scope global eno1
    inet6 fe80::5e26:aff:fe2b:2954/64 scope link
       valid_lft forever preferred_lft forever
17: veth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 9e:59:c1:cc:3a:e3 brd ff:ff:ff:ff:ff:ff
18: veth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 2e:5e:c1:b0:71:44 brd ff:ff:ff:ff:ff:ff

For some reason, it always adds two interfaces.

Set address for a virtual interface

# ip addr add 10.1.2.3/8 dev veth0
# ip ad
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 5c:26:0a:2b:29:54 brd ff:ff:ff:ff:ff:ff
    inet 64.112.251.9/21 brd 64.112.255.255 scope global eno1
    inet6 fe80::5e26:aff:fe2b:2954/64 scope link
       valid_lft forever preferred_lft forever
17: veth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 02:d1:8f:79:fe:db brd ff:ff:ff:ff:ff:ff
    inet 10.1.2.3/8 scope global veth0
18: veth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether ee:84:34:2c:ce:bc brd ff:ff:ff:ff:ff:ff
The link is still in the "down" state, and can't be used yet.

Set status of virtual interface to "up"

# ip link set up dev veth0
# ip ad
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 5c:26:0a:2b:29:54 brd ff:ff:ff:ff:ff:ff
    inet 64.112.251.9/21 brd 64.112.255.255 scope global eno1
    inet6 fe80::5e26:aff:fe2b:2954/64 scope link
       valid_lft forever preferred_lft forever
17: veth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 100
    link/ether 02:d1:8f:79:fe:db brd ff:ff:ff:ff:ff:ff
    inet 10.1.2.3/32 scope global veth0

Notice that the state is still listed as down, but ifconfig shows the same device with a state of up. Go figure.

# ifconfig veth0
veth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 10.1.2.3  netmask 255.255.255.255  broadcast 0.0.0.0
        ether 02:d1:8f:79:fe:db  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Remove virtual interface

# ip link delete dev veth0