head 1.28; access; symbols SHTOOL_2_0_8:1.28 SHTOOL_2_0_7:1.27 SHTOOL_2_0_6:1.26 SHTOOL_2_0_5:1.26 SHTOOL_2_0_4:1.26 SHTOOL_2_0_3:1.25 SHTOOL_2_0_2:1.25 SHTOOL_2_0_1:1.24 SHTOOL_2_0_0:1.24 SHTOOL_2_0b3:1.24 SHTOOL_2_0b2:1.24 SHTOOL_2_0b1:1.24 SHTOOL_1_6:1.19.0.2 SHTOOL_1_6_2:1.19 SHTOOL_1_6_1:1.18 SHTOOL_1_6_0:1.18 SHTOOL_1_5:1.16.0.2 SHTOOL_1_5_4:1.16 SHTOOL_1_5_3:1.16 SHTOOL_1_5_2:1.14 SHTOOL_1_5_1:1.12 SHTOOL_1_5_0:1.12 SHTOOL_1_4_9:1.11 SHTOOL_1_4_8:1.10 SHTOOL_1_4_7:1.8 SHTOOL_1_4_6:1.7 SHTOOL_1_4_5:1.7 SHTOOL_1_4_4:1.7 SHTOOL_1_4_3:1.7 SHTOOL_1_4_2:1.7 SHTOOL_1_4_1:1.7 SHTOOL_1_4_0:1.7 SHTOOL_1_3_3:1.5 SHTOOL_1_3_2:1.4 SHTOOL_1_3_1:1.3 SHTOOL_1_3_0:1.3 SHTOOL_1_2_9:1.1.1.1 SHTOOL_1_2_8:1.1.1.1 SHTOOL_1_2_7:1.1.1.1 SHTOOL_1_2_6:1.1.1.1 SHTOOL_1_2_5:1.1.1.1 SHTOOL_1_2_4:1.1.1.1 SHTOOL_1_2_3:1.1.1.1 SHTOOL_1_2_2:1.1.1.1 SHTOOL_1_2_1:1.1.1.1 SHTOOL_1_2_0:1.1.1.1 SHTOOL_1_1_0:1.1.1.1 RSE:1.1.1; locks; strict; comment @# @; 1.28 date 2008.04.02.20.13.43; author rse; state Exp; branches; next 1.27; commitid eB5Wirx8MdMyDzXs; 1.27 date 2007.05.19.19.09.39; author rse; state Exp; branches; next 1.26; commitid OPUF1UBbllBTwzis; 1.26 date 2006.02.04.09.43.25; author rse; state Exp; branches; next 1.25; commitid oWk7BmnyAitJtfkr; 1.25 date 2005.06.15.08.14.35; author rse; state Exp; branches; next 1.24; 1.24 date 2004.02.12.16.06.27; author rse; state Exp; branches; next 1.23; 1.23 date 2004.01.01.16.54.20; author rse; state Exp; branches; next 1.22; 1.22 date 2003.08.13.14.20.34; author rse; state Exp; branches; next 1.21; 1.21 date 2003.02.11.13.00.50; author rse; state Exp; branches; next 1.20; 1.20 date 2003.02.11.12.56.40; author rse; state Exp; branches; next 1.19; 1.19 date 2002.11.02.12.35.56; author rse; state Exp; branches; next 1.18; 1.18 date 2001.12.31.15.06.04; author rse; state Exp; branches; next 1.17; 1.17 date 2001.09.23.10.58.10; author rse; state Exp; branches; next 1.16; 1.16 date 2001.04.19.07.52.02; author rse; state Exp; branches; next 1.15; 1.15 date 2001.04.19.07.33.55; author rse; state Exp; branches; next 1.14; 1.14 date 2001.01.17.09.55.11; author rse; state Exp; branches; next 1.13; 1.13 date 2000.11.29.19.58.58; author rse; state Exp; branches; next 1.12; 1.12 date 2000.05.12.09.55.57; author rse; state Exp; branches; next 1.11; 1.11 date 2000.03.24.15.22.51; author rse; state Exp; branches; next 1.10; 1.10 date 2000.03.12.13.28.24; author rse; state Exp; branches; next 1.9; 1.9 date 2000.03.12.11.12.21; author rse; state Exp; branches; next 1.8; 1.8 date 99.12.24.15.11.23; author rse; state Exp; branches; next 1.7; 1.7 date 99.07.01.15.02.48; author rse; state Exp; branches; next 1.6; 1.6 date 99.07.01.14.47.17; author rse; state Exp; branches; next 1.5; 1.5 date 99.06.29.17.37.34; author rse; state Exp; branches; next 1.4; 1.4 date 99.06.28.15.18.44; author rse; state Exp; branches; next 1.3; 1.3 date 99.06.12.14.46.37; author rse; state Exp; branches; next 1.2; 1.2 date 99.06.12.14.08.49; author rse; state Exp; branches; next 1.1; 1.1 date 99.04.29.11.19.50; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 99.04.29.11.19.50; author rse; state Exp; branches; next ; desc @@ 1.28 log @adjust copyright for year 2008 @ text @## ## mkdir -- Make one or more directories ## Copyright (c) 1996-2008 Ralf S. Engelschall ## ## This file is part of shtool and 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. ## ## This file is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, ## USA, or contact Ralf S. Engelschall . ## str_tool="mkdir" str_usage="[-t|--trace] [-f|--force] [-p|--parents] [-m|--mode ] [-o|--owner ] [-g|--group ] [ ...]" arg_spec="1+" opt_spec="t.f.p.m:o:g:" opt_alias="t:trace,f:force,p:parents,m:mode,o:owner,g:group" opt_t=no opt_f=no opt_p=no opt_m="" opt_o="" opt_g="" . ./sh.common errstatus=0 for p in ${1+"$@@"}; do # if the directory already exists... if [ -d "$p" ]; then if [ ".$opt_f" = .no ] && [ ".$opt_p" = .no ]; then echo "$msgprefix:Error: directory already exists: $p" 1>&2 errstatus=1 break else continue fi fi # if the directory has to be created... if [ ".$opt_p" = .no ]; then if [ ".$opt_t" = .yes ]; then echo "mkdir $p" 1>&2 fi mkdir $p || errstatus=$? if [ ".$opt_o" != . ]; then if [ ".$opt_t" = .yes ]; then echo "chown $opt_o $p" 1>&2 fi chown $opt_o $p || errstatus=$? fi if [ ".$opt_g" != . ]; then if [ ".$opt_t" = .yes ]; then echo "chgrp $opt_g $p" 1>&2 fi chgrp $opt_g $p || errstatus=$? fi if [ ".$opt_m" != . ]; then if [ ".$opt_t" = .yes ]; then echo "chmod $opt_m $p" 1>&2 fi chmod $opt_m $p || errstatus=$? fi else # the smart situation set fnord `echo ":$p" |\ sed -e 's/^:\//%/' \ -e 's/^://' \ -e 's/\// /g' \ -e 's/^%/\//'` shift pathcomp='' for d in ${1+"$@@"}; do pathcomp="$pathcomp$d" case "$pathcomp" in -* ) pathcomp="./$pathcomp" ;; esac if [ ! -d "$pathcomp" ]; then if [ ".$opt_t" = .yes ]; then echo "mkdir $pathcomp" 1>&2 fi mkdir $pathcomp || errstatus=$? if [ ".$opt_o" != . ]; then if [ ".$opt_t" = .yes ]; then echo "chown $opt_o $pathcomp" 1>&2 fi chown $opt_o $pathcomp || errstatus=$? fi if [ ".$opt_g" != . ]; then if [ ".$opt_t" = .yes ]; then echo "chgrp $opt_g $pathcomp" 1>&2 fi chgrp $opt_g $pathcomp || errstatus=$? fi if [ ".$opt_m" != . ]; then if [ ".$opt_t" = .yes ]; then echo "chmod $opt_m $pathcomp" 1>&2 fi chmod $opt_m $pathcomp || errstatus=$? fi fi pathcomp="$pathcomp/" done fi done shtool_exit $errstatus ## ## manual page ## =pod =head1 NAME B - B mkdir(1) style command =head1 SYNOPSIS B [B<-t>|B<--trace>] [B<-f>|B<--force>] [B<-p>|B<--parents>] [B<-m>|B<--mode> I] [B<-o>|B<--owner> I] [B<-g>|B<--group> I] I [I ...] =head1 DESCRIPTION This is a mkdir(1) style command with additional options and the ability to be smart if the directory already exists which is important for installation procedures. =head1 OPTIONS The following command line options are available. =over 4 =item B<-t>, B<--trace> Shows the actually involved shell commands. =item B<-f>, B<--force> Forced continuation and no complaints if directory already exists. Default is to terminate with error. =item B<-p>, B<--parents> Automatic parent directory creation. Default is to only create the last directory in the path and fail if parents are missing. =item B<-m>, B<--mode> I The directory mode applied to the directory, see chmod(1). Omitting mode skips this step and leaves the operating system default which is usually based on umask(1). Some directory modes require superuser privileges to be set. Default is to stick with operating system defaults. =item B<-o>, B<--owner> I The directory owner name or id applied to the directory, see chown(1). This option requires superuser privileges to execute. Default is to skip this step and leave the operating system default which is usually based on the executing uid or the parent setuid directory. =item B<-g>, B<--group> I The directory group name or id applied to the directory, see chgrp(1). This option requires superuser privileges to execute to the fullest extend, otherwise the choice of I is limited on most operating systems. Default is to skip this step and leave the operating system default which is usually based on the executing gid or the parent setgid directory. =head1 EXAMPLE # Makefile install: shtool mkdir -f -p -m 755 $(bindir) shtool mkdir -f -p -m 755 $(mandir)/man1 : =head1 HISTORY The B B command was originally written for Public Domain by Noah Friedman and later revised by Ralf S. Engelschall Erse@@engelschall.comE in 1999 for inclusion into B. =head1 SEE ALSO shtool(1), mkdir(1). =cut @ 1.27 log @Adjust copyright for year 2007. @ text @d3 1 a3 1 ## Copyright (c) 1996-2007 Ralf S. Engelschall @ 1.26 log @Adjust copyright for year 2006 @ text @d3 1 a3 1 ## Copyright (c) 1996-2006 Ralf S. Engelschall @ 1.25 log @Adjust copyright for year 2005 @ text @d3 1 a3 1 ## Copyright (c) 1996-2005 Ralf S. Engelschall @ 1.24 log @Embedded the command documentation from shtool.pod into the individual sh.xxxx scripts and this way split the large shtool(1) manual page into individual manual pages shtool-xxxx(1). Submitted partly by: Thomas Lotterer @ text @d3 1 a3 1 ## Copyright (c) 1996-2004 Ralf S. Engelschall @ 1.23 log @Bump copyright year for 2004 @ text @a3 2 ## Originally written for public domain by Noah Friedman ## Cleaned up and enhanced for shtool d113 1 d115 90 @ 1.22 log @Replace "[ x -o/-a x ]" constructs with "[ x ] ||/&& [ x ]" and "egrep"/"fgrep" constructs with compatible "grep" or "case" constructs. This way GNU shtool is now more POSIX 1003.1-2001 compliant. Submitted by: Paul Eggert @ text @d3 1 a3 1 ## Copyright (c) 1996-2003 Ralf S. Engelschall @ 1.21 log @Bump year in copyright messages to cover new year 2003. @ text @d41 1 a41 1 if [ ".$opt_f" = .no -a ".$opt_p" = .no ]; then @ 1.20 log @Fixed error exit in all commands by introducing an "shtool_exit" function (which correctly cleans up temporary files) and replacing all "exit" calls with "shtool_exit". THIS THE FIRST TIME INTRODUCED THE USAGE OF A SHELL FUNCTION TO THE SHTOOL CODE. This is known to break on _very_ anchient and broken Bourne-Shell implementations and is considered to be no longer a real problem in the year 2003. Especially there is no alternative way anyway. @ text @d3 1 a3 1 ## Copyright (c) 1996-2002 Ralf S. Engelschall @ 1.19 log @Add -o|--owner and -g|--group options to "shtool mkdir". @ text @d115 1 a115 1 exit $errstatus @ 1.18 log @bump copyright years @ text @d24 1 a24 1 str_usage="[-t|--trace] [-f|--force] [-p|--parents] [-m|--mode ] [ ...]" d26 2 a27 2 opt_spec="t.f.p.m:" opt_alias="t:trace,f:force,p:parents,m:mode" d32 2 d55 12 d92 12 @ 1.17 log @*** empty log message *** @ text @d3 1 a3 1 ## Copyright (c) 1996-2001 Ralf S. Engelschall @ 1.16 log @*** empty log message *** @ text @d24 1 a24 1 str_usage="[-t] [-f] [-p] [-m] [ ...]" d27 1 @ 1.15 log @*** empty log message *** @ text @d54 1 a54 1 echo "chmod $opt_m $pathcomp" 1>&2 d56 1 a56 1 chmod $opt_m $pathcomp || errstatus=$? @ 1.14 log @*** empty log message *** @ text @d52 6 @ 1.13 log @*** empty log message *** @ text @d3 1 a3 1 ## Copyright (c) 1996-2000 Ralf S. Engelschall @ 1.12 log @*** empty log message *** @ text @d38 1 a38 1 if [ ".$opt_f" = .no ] && [ ".$opt_p" = .no ]; then @ 1.11 log @*** empty log message *** @ text @d38 1 a38 1 if [ ".$opt_f" = .no ]; then @ 1.10 log @*** empty log message *** @ text @d36 1 a36 1 # when the directory already exists... d39 1 a39 1 echo "$msgprefix:Error: file exists: $p" 1>&2 d46 1 a46 1 # when the directory has to be created d60 1 a60 1 pathcomp= @ 1.9 log @*** empty log message *** @ text @d26 4 a29 1 opt_spec="tfpm:" @ 1.8 log @*** empty log message *** @ text @d3 1 a3 1 ## Copyright (c) 1996-1999 Ralf S. Engelschall @ 1.7 log @*** empty log message *** @ text @d27 1 @ 1.6 log @*** empty log message *** @ text @d1 1 a1 1 ## @ 1.5 log @*** empty log message *** @ text @d24 1 a24 1 str_usage="[-f] [-p] [-m] [ ...]" d26 1 a26 1 opt_spec="fpm:" d44 3 d63 3 d68 3 @ 1.4 log @*** empty log message *** @ text @d31 1 a31 1 for p in ${1+"$@@"}; do @ 1.3 log @*** empty log message *** @ text @d28 1 a28 1 . sh.common @ 1.2 log @*** empty log message *** @ text @d7 15 @ 1.1 log @Initial revision @ text @a0 1 #!/bin/sh d2 2 a3 1 ## mkdir -- Make a directory d5 1 a5 3 ## Cleaned up and enhanced by Ralf S. Engelschall ## Copyright (c) 1996-1999 Ralf S. Engelschall ## Usage: mkdir [-f] [-p] [-m ] [ ...] d8 6 a13 16 # command line parsing mode="" force=0 parent=0 while [ ".$1" != . ]; do case $1 in -f) force=1; shift; continue ;; -p) parent=1; shift; continue ;; -m) mode="$2"; shift; shift; continue ;; *) break ;; esac done if [ $# -eq 0 ]; then echo "$0:Usage: mkdir [-f] [-p] [-m ] [ ...]" 1>&2 exit 1 fi d19 2 a20 2 if [ $force = 0 ]; then echo "$0:Error: file exists: $p" 1>&2 d28 1 a28 1 if [ $parent = 0 ]; then d46 2 a47 2 if [ ".$mode" != . ]; then chmod $mode $pathcomp || errstatus=$? @ 1.1.1.1 log @Import of shtool 1.1.0 @ text @@