• 0 Posts
  • 6 Comments
Joined 2 years ago
cake
Cake day: July 3rd, 2023

help-circle

  • For loops with find are evil for a lot of reasons, one of which is spaces:

    $ tree
    .
    ├── arent good with find loops
    │   ├── a
    │   └── innerdira
    │       └── docker-compose.yml
    └── dirs with spaces
        ├── b
        └── innerdirb
            └── docker-compose.yml
    
    3 directories, 2 files
    $ for y in $(find .); do echo $y; done
    .
    ./are
    t good with fi
    d loops
    ./are
    t good with fi
    d loops/i
    
    erdira
    ./are
    t good with fi
    d loops/i
    
    erdira/docker-compose.yml
    ./are
    t good with fi
    d loops/a
    ./dirs with spaces
    ./dirs with spaces/i
    
    erdirb
    ./dirs with spaces/i
    
    erdirb/docker-compose.yml
    ./dirs with spaces/b
    

    You can kinda fix that with IFS (this breaks if newlines are in the filename which would probably only happen in a malicious context):

    $ OIFS=$IFS
    $ IFS=$'\n'
    $ for y in $(find .); do echo "$y"; done
    .
    ./arent good with find loops
    ./arent good with find loops/innerdira
    ./arent good with find loops/innerdira/docker-compose.yml
    ./arent good with find loops/a
    ./dirs with spaces
    ./dirs with spaces/innerdirb
    ./dirs with spaces/innerdirb/docker-compose.yml
    ./dirs with spaces/b
    $ IFS=$OIFS
    

    But you can also use something like:

    find . -name 'docker-compose.yml' -printf '%h\0' | while read -r -d $'\0' dir; do
          ....
    done
    

    or in your case this could all be done from find alone:

    find . -name 'docker-compose.yml' -execdir ...
    

    -execdir in this case is basically replacing your cd $(dirname $y), which is also brittle when it comes to spaces and should be quoted: cd "$(dirname "$y")".


  • I see why it does this now. Debian does

    CONFIG=/etc/samba/smb.conf
    # stuff
    ucf --three-way --debconf-ok /usr/share/samba/smb.conf "$CONFIG"
    

    in the postinit inside the .deb file to create the /etc/samba/smb.conf file. They do it this way so they don’t nuke an already created file. I take back that they should be shipping an empty file, this way is better, but it also means you’ll never be able to query it without some changes to the packaging tools.

    The man page should mention the path though that’s a bit lame.


  • This is a good argument for shipping an empty config file.

    Your point stands, but this also isn’t completely unintuitive. There is pattern there: you installed samba and the config is in /etc/samba/. System level installs will almost always install their config in /etc/ and the sub directory will typically match the name somewhat.

    There is likely a general thought that if you’re going to administer a samba server, you’ll also be comfortable with conventions and man pages. Although, funnily enough, in the particular case of samba, man smb.conf doesn’t show the path lol