#! /bin/sh #---------------------------------------------------------------------------- # /var/install/bin/set-access-rights - set package access rights # # Copyright (c) 2001-2004 Frank Meyer # # Creation: 18.08.2004 jed # Last Update: $Id$ # # Usage: # set-access.sh [-quiet] [-dir file-list-dir] [-file file-to-change] PACKAGE1 PACKAGE2 ... # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- # include eislib . /var/install/include/eislib #---------------------------------------------------------------------------- # myecho #---------------------------------------------------------------------------- myecho () { if [ "$quietflag" != "-quiet" ] then mecho $@ fi } #---------------------------------------------------------------------------- # set ownership and access rights # $1 - filename #---------------------------------------------------------------------------- set_access () { file_name="$1" set $file_name type=$1 rights=$2 user=$3 group=$4 file=/$6 case $type in b|d|u ) # b - binary # d - dos # u - unix if [ ! -f $file ] then # error myecho -warn "F:$file: file not found." rtc=1 else # change ownership and access rights myecho "F:$file: processed." chown $user $file chgrp $group $file chmod $rights $file fi ;; D ) # D - directory if [ ! -d $file ] then # error myecho -warn "D:$file: directory not found." rtc=1 else # change ownership and access rights myecho "D:$file: processed." chown $user $file chgrp $group $file chmod $rights $file fi ;; i ) # i - ignore - do nothing ;; * ) # unknown type given myecho -error "$file: unknown type." rtc=1 ;; esac } #---------------------------------------------------------------------------- # process file(s) # $1 - package # $2 - filename #---------------------------------------------------------------------------- process_files () { package=$1 fname=$2 # set file list name check_file=$listdir/$package-files.txt if [ ! -f $check_file ] then myecho -error "file '$check_file' not found, check aborted." >&2 exit 1 fi if [ "$fname" != "" ] then # process single file # remove leading slash fname=`echo "$fname"|sed 's/^\///'` # process single file line="`grep -E \"$fname[ ]*\$\" $check_file`" # skip comments echo "$line"|grep "^#" > /dev/null if [ $? -ne 0 ] then set_access "$line" fi else # process complete file list while read line do if [ "$line" = "" ] then myecho -info "empty line or filename in '$check_file'" >&2 else # string not empty, go on echo $line|grep "^#" > /dev/null if [ $? -ne 0 ] then set_access "$line" fi fi done < $check_file fi myecho "done." cd $start_dir } #============================================================================ # main #============================================================================ rtc=0 quietflag='' packages='' listdir=/etc/filelist.d if [ $# -lt 1 ] then myecho "Usage: $0 [-quiet] [-dir file-list-dir] PACKAGE1 PACKAGE2 ..." >&2 exit 1 fi # check directory if [ ! -d $listdir ] then mkdir -p $listdir fi while [ $# -ne 0 ] do case $1 in '-dir') if [ -d $2 ] then listdir=$2 else myecho "-dir $2: directory not found, will be ignored." fi shift; shift ;; '-file') if [ -f $2 ] then filename=$2 else myecho "-file $2: file not found, will be ignored." fi shift; shift ;; '-quiet') quietflag='-quiet' shift ;; * ) packages="$packages$1 " shift ;; esac done # get current directory call_dir=`pwd` cd / # check list directory if [ ! -d $listdir ] then mkdir -p $listdir fi # process only given package(s) for package in $packages do process_files $package $filename done # return to previous directory cd $call_dir exit $rtc #============================================================================ # end #============================================================================