| @@ -3,7 +3,7 @@ set -e | |||
| # setup.sh --- 10sr setup script | |||
| __setups="gitconf tmux scripts darwin dirs selfupdate windirs" | |||
| __setups="shrc_common gitconf tmux scripts darwin dirs selfupdate windirs" | |||
| __homelocal="$HOME/.local" | |||
| __homevar="$HOME/.var" | |||
| @@ -23,41 +23,47 @@ _download(){ | |||
| } | |||
| ############################# | |||
| # gen_common | |||
| ################################## | |||
| # Detect systems | |||
| # Generate ~/.shrc.common, which contains system infos and is sourced from | |||
| # setup.sh (this file) and dotfiles/shrc . | |||
| # This functions is always called. | |||
| detect_systems(){ | |||
| ismsys=false | |||
| iscygwin=false | |||
| iswindows=false | |||
| # this variable must consistent with shrc | |||
| __shrc_common="$HOME/.shrc.common" | |||
| isdarwin=false | |||
| isfreebsd=false | |||
| isbsd=false | |||
| gen_common(){ | |||
| test -f "$__shrc_common" && rm -- "$__shrc_common" | |||
| __ismsys=false | |||
| __iscygwin=false | |||
| __iswindows=false | |||
| __isdarwin=false | |||
| __isfreebsd=false | |||
| __isbsd=false | |||
| __islinux=false | |||
| islinux=false | |||
| # $OSTYPE is another choice. which is better? | |||
| # NOTE: sh on FreeBSD does not define OSTYPE | |||
| case `uname` in | |||
| (MINGW*) __ismsys=true ;; | |||
| (CYGWIN*) __iscygwin=true ;; | |||
| (Darwin*) __isdarwin=true ;; | |||
| (FreeBSD*) __isfreebsd=true ;; | |||
| (Linux*) __islinux=true ;; | |||
| (MINGW*) ismsys=true ;; | |||
| (CYGWIN*) iscygwin=true ;; | |||
| (Darwin*) isdarwin=true ;; | |||
| (FreeBSD*) isfreebsd=true ;; | |||
| (Linux*) islinux=true ;; | |||
| esac | |||
| ($__ismsys || $__iscygwin) && __iswindows=true | |||
| ($ismsys || $iscygwin) && iswindows=true | |||
| # is this true? | |||
| ($__isdarwin || $__isfreebsd) && __isbsd=true | |||
| ($isdarwin || $isfreebsd) && isbsd=true | |||
| return 0 | |||
| } | |||
| ############################# | |||
| # shrc_common | |||
| # Generate ~/.shrc.common, which contains system infos and is sourced from | |||
| # setup.sh (this file) and dotfiles/shrc . | |||
| # this variable must consistent with shrc | |||
| __shrc_common="$HOME/.shrc.common" | |||
| setup_shrc_common(){ | |||
| test -f "$__shrc_common" && rm -- "$__shrc_common" | |||
| cat <<__EOC__ >"$__shrc_common" | |||
| #!/bin/sh | |||
| @@ -65,15 +71,15 @@ gen_common(){ | |||
| # $__shrc_common | |||
| # Automatically generated by $0 | |||
| ismsys=$__ismsys | |||
| iscygwin=$__iscygwin | |||
| iswindows=$__iswindows | |||
| ismsys=$ismsys | |||
| iscygwin=$iscygwin | |||
| iswindows=$iswindows | |||
| isdarwin=$__isdarwin | |||
| isfreebsd=$__isfreebsd | |||
| isbsd=$__isbsd | |||
| isdarwin=$isdarwin | |||
| isfreebsd=$isfreebsd | |||
| isbsd=$isbsd | |||
| islinux=$__islinux | |||
| islinux=$islinux | |||
| __homelocal="$__homelocal" | |||
| __homevar="$__homevar" | |||
| @@ -293,12 +299,11 @@ setup_dirs(){ | |||
| main(){ | |||
| gen_common | |||
| . "$__shrc_common" | |||
| detect_systems | |||
| if test -z "$1" | |||
| then | |||
| echo "usage: ./setup.sh <setups> ..." | |||
| echo "Usage: ./setup.sh <setups> ..." | |||
| echo "setups: all $__setups" | |||
| exit 1 | |||
| fi | |||