X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=lib.sh;h=bb60c521b959d79ecba52b33dd7e9c4bcd74de36;hb=a5ac763c6afcfdf885da5fd9f06907981c9a127e;hp=ba4e658f978d4033e732b88839577341729e6209;hpb=b1c443c9ab5b960e08e079863d4c679f226871b6;p=config%2Fdotfiles.git diff --git a/lib.sh b/lib.sh index ba4e658..bb60c52 100644 --- a/lib.sh +++ b/lib.sh @@ -2,7 +2,7 @@ # # Their setup.sh script sources this file. -# Copyright (C) 2009-2013 Simon Ruderich +# Copyright (C) 2009-2018 Simon Ruderich # # 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 @@ -68,7 +68,7 @@ cmd_i() { # Usage: sed_i ... # -# sed -i is not compatible due to different implementations. See cmd_i. +# sed -i is not portable due to different implementations. See cmd_i. sed_i() { cmd_i sed "$@" } @@ -111,7 +111,6 @@ simple_cpp() { # # - Debian (debian) # - Gentoo (gentoo) -# - Mac OS X (darwin) # - Solaris/OpenSolaris (sun) # - FreeBSD (freebsd) # @@ -121,11 +120,9 @@ os() { echo debian elif test -f /etc/gentoo-release; then echo gentoo - elif test x`uname` = xDarwin; then - echo darwin - elif test x`uname` = xSunOS; then + elif test x"`uname`" = xSunOS; then echo sun - elif test x`uname` = xFreeBSD; then + elif test x"`uname`" = xFreeBSD; then echo freebsd else echo 'unsupported OS!' >&2 @@ -153,21 +150,20 @@ link() { # Abort if the target file exists and is no symbolic link. Prevents # overwriting real files. - if ( test -f "$target" && test ! -h "$target" ) || \ - ( test -s "$target" && test ! -h "$target" ); then - printf "link(): target '%s' exists already and is no symbolic link!" \ + if test -e "$target" && test ! -h "$target"; then + printf 'link(): target "%s" exists already and is no symbolic link!\n' \ "$target" >&2 exit 1 fi - # Make sure the source exists (is file, directory or link). - if test ! -f "$source" && test ! -d "$source" && test ! -h "$source"; then - printf "link(): source '%s' doesn't exist!" "$source" >&2 + # Make sure the source exists. + if test ! -e "$source"; then + printf 'link(): source "%s" does not exist!\n' "$source" >&2 exit 1 fi # Create the new symbolic link; remove the old one if necessary. - printf "link(): linking '%s' to '%s'\n" "$source" "$target" + printf 'link(): linking "%s" to "%s"\n' "$source" "$target" rm -f "$target" ln -s "$source" "$target" @@ -197,14 +193,14 @@ generate() { file_tmp="$file.tmp" else # We only need this message if we generate a new file. - printf "%s: generating from '%s' (%s)\n" \ + printf '%s: generating from "%s" (%s)\n' \ "$file" "$file$extension" "$1" echo '###################################' >"$file" echo '# WARNING! DO NOT EDIT THIS FILE! #' >>"$file" echo '###################################' >>"$file" echo >>"$file" - printf "# It was generated from '%s' on %s.\n" \ + printf '# It was generated from "%s" on %s.\n' \ "$file$extension" "`date`" >>"$file" echo >>"$file"