mu-wizard

shell script to easily configure mu4e accounts on Emacs
git clone git://git.ckyln.com/mu-wizard
Log | Files | Refs | LICENSE

install.sh (1465B)


      1 #!/bin/sh -e
      2 # Portable install version that supports -D -m and -t
      3 # We have our own extension flag -s for running sed on the given files while
      4 # installing.
      5 usage() {
      6     printf '%s\n' "usage: $0 [-D] [-m mode] [-s sedcmd] source dest" \
      7                   "   or: $0 [-D] [-m mode] [-s sedcmd] [-t dir] [source...]" >&2
      8     exit 0
      9 }
     10 
     11 die() { printf '%s\n' "$@" >&2; exit 1;}
     12 
     13 sed=''
     14 mkdirp=''
     15 target=''
     16 mode=''
     17 REST=''
     18 
     19 while getopts 'Dm:s:t:h' opt; do
     20     case $opt in
     21         D) mkdirp=1 ;;
     22         s) sed=$OPTARG ;;
     23         t) target=$OPTARG ;;
     24         m) mode=$OPTARG ;;
     25         h) usage
     26            exit 0
     27            ;;
     28         '?') exit 1
     29     esac
     30 done
     31 
     32 shift "$((OPTIND - 1))"
     33 
     34 if [ "$target" ]; then
     35     [ "$mkdirp" ] || [ -d "$target" ] || die "$target doesn't exist"
     36     mkdir -p "$target"
     37     for arg; do
     38         [ -d "$target/${arg##*/}" ] && die "$target/${arg##*/} is a directory"
     39         if [ "$sed" ]; then
     40             sed "$sed" < "$arg" > "$target/${arg##*/}"
     41         else
     42             cp "$arg" "$target"
     43         fi
     44 
     45         # Most implementations set the mode to 0755 by default when -t is set.
     46         chmod "${mode:=0755}" "$target/${arg##*/}"
     47     done
     48 else
     49     case "$2" in */*) [ "$mkdirp" ] || [ -d "${2%/*}" ] || die "${2%/*} doesn't exist"
     50                       mkdir -p "${2%/*}"
     51     esac
     52     [ -d "$2" ] && die "$2 is a directory"
     53     if [ "$sed" ]; then sed "$sed" < "$1" > "$2"; else cp "$1" "$2"; fi
     54     chmod "${mode:=0755}" "$2"
     55 fi