std/c/README.md: Add section skeletons and don't indent lists
[sunny256-utils.git] / mymkdir
blob3b34a92699204b780175dc96e2702ac295a3f3f8
1 #!/usr/bin/env bash
3 #=======================================================================
4 # mymkdir
5 # File ID: cbdb01c6-63be-11e5-84b6-fefdb24f8e10
7 # Create a directory using sudo(8) where the current user don't have
8 # permission to do so, and set the owner of that directory to the
9 # current user.
11 # Author: Øyvind A. Holm <sunny@sunbase.org>
12 # License: GNU General Public License version 2 or later.
13 #=======================================================================
15 progname=mymkdir
16 VERSION=0.2.1
18 ARGS="$(getopt -o "\
22 " -l "\
23 help,\
24 quiet,\
25 verbose,\
26 version,\
27 " -n "$progname" -- "$@")"
28 test "$?" = "0" || exit 1
29 eval set -- "$ARGS"
31 opt_help=0
32 opt_quiet=0
33 opt_verbose=0
34 while :; do
35 case "$1" in
36 -h|--help) opt_help=1; shift ;;
37 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
38 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
39 --version) echo $progname $VERSION; exit 0 ;;
40 --) shift; break ;;
41 *) echo $progname: Internal error >&2; exit 1 ;;
42 esac
43 done
44 opt_verbose=$(($opt_verbose - $opt_quiet))
46 if test "$opt_help" = "1"; then
47 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
48 cat <<END
50 Create a directory using sudo(8) where the current user don't have
51 permission to do so, and set the owner of that directory to the current
52 user.
54 Usage: $progname [options] DIRECTORY
56 Options:
58 -h, --help
59 Show this help.
60 -q, --quiet
61 Be more quiet. Can be repeated to increase silence.
62 -v, --verbose
63 Increase level of verbosity. Can be repeated.
64 --version
65 Print version information.
67 END
68 exit 0
71 user="$(whoami)"
73 if test "$user" = "root"; then
74 echo $progname: You are root, should be run as a regular user
75 exit 1
78 sudo mkdir -vp "$1"
79 sudo chown -v "$user"."$user" "$1"
80 sudo -k