Преглед изворни кода

setup.sh: add msg functions and make use of them instead of echo

pull/1/head
10sr пре 10 година
родитељ
комит
7fef1ed1d8
1 измењених фајлова са 61 додато и 12 уклоњено
  1. +61
    -12
      setup.sh

+ 61
- 12
setup.sh Прегледај датотеку

@@ -4,7 +4,7 @@ set -e
# setup.sh --- 10sr setup script
# 2014, 10sr. Unlicensed <http://unlicense.org>

__setups="shrc_common gitconf tmux scripts darwin dirs selfupdate windirs dotfiles"
__setups="shrc_common gitconf tmux scripts darwin dirs selfupdate windirs dotfiles env"

__homelocal="$HOME/.local"
__homevar="$HOME/.var"
@@ -35,6 +35,26 @@ islinux=
###########################
# utils

##########################33
# Utilities

__tput_bold=`tput bold || true`
__tput_default=`tput sgr0 || true`
__tput_yellow=`tput setaf 3 || true`

_msg(){
echo ">> ${__tput_bold}$*${__tput_default}"
}

_warn(){
echo ">>> ${__tput_yellow}${__tput_bold}$*${__tput_default}" 1>&2
}

_die(){
_warn "$@"
exit 1
}

_download(){
# download <url> <file>
if type wget >/dev/null 2>&1
@@ -43,6 +63,9 @@ _download(){
elif type curl >/dev/null 2>&1
then
curl --url "$1" --output "$2"
else
_warn "No download program found."
_die "Install wget or curl."
fi
}

@@ -71,7 +94,7 @@ detect_systems(){
($ismsys || $iscygwin) && iswindows=true
# is this true?
($isdarwin || $isfreebsd) && isbsd=true
return 0
_msg "Detecting the system...done"
}

################################
@@ -82,6 +105,7 @@ detect_systems(){
# setup selfupdate

setup_selfupdate(){
_msg "Download latest setup.sh from 10sr repository."
mkdir -p "$DOTFILES_DIR"
_download $_dotfiles_url_base/setup.sh "$DOTFILES_DIR/"setup.sh
chmod +x "$DOTFILES_DIR"/setup.sh
@@ -92,20 +116,23 @@ setup_selfupdate(){
# setup dotfiles

setup_dotfiles(){
_msg "Prepare latest dotfiles."
mkdir -p "$DOTFILES_DIR"
if test "$1" = "--git"
then
# git clone
_msg "Using git"
if test -d "$DOTFILES_DIR"/.git
then
echo "Git repository $DOTFILES_DIR already exists"
echo "Skipping"
_warn "Git repository $DOTFILES_DIR already exists"
_warn "Skipping"
else
git clone git@github.com:10sr/dotfiles.git "$DOTFILES_DIR"
fi
else
for f in $@
do
_msg "Prepareing $f"
mkdir -p "`dirname $f`"
_download $_dotfiles_url_base/$f "$DOTFILES_DIR"/$f
done
@@ -122,6 +149,7 @@ setup_dotfiles(){
__shrc_common="$HOME/.shrc.common"

setup_shrc_common(){
_msg "Generate $__shrc_common"
test -f "$__shrc_common" && rm -- "$__shrc_common"

cat <<__EOC__ >"$__shrc_common"
@@ -149,9 +177,10 @@ __EOC__
# setup gitconf

setup_gitconf(){
_msg "Configure git environment"
if ! command -v git >/dev/null
then
echo "git not found"
_msg "Git program not found"
return 0
fi

@@ -212,6 +241,7 @@ git checkout master && git merge --no-ff --stat --verbose -'"

setup_tmux(){
tmux_conf_local="$HOME/.tmux.conf.local"
_msg "Generate $tmux_conf_local"

case "`hostname`" in
arch-aspireone)
@@ -236,9 +266,9 @@ setup_tmux(){
;;
esac

cat <<__EOC__ >"$tmux_conf_local"
_date= `date` cat <<__EOC__ >"$tmux_conf_local"
# $tmux_conf_local
# Automatically generated by $0
# Automatically generated by $0 at $_date

set -g status-right "${USER}@$(hostname) | #(tmux -V) "

@@ -268,10 +298,13 @@ _fetch_script(){
}

setup_scripts(){
_msg "Download some utility scripts"
_fetch_script \
https://gist.github.com/10sr/6852317/raw/colortable16.sh colortable16.sh
_fetch_script \
https://gist.github.com/10sr/6852331/raw/256colors2.pl 256colors2.pl
_fetch_script \
https://github.com/icy/pacapt/raw/ng/pacapt pacapt
}

################################
@@ -316,6 +349,7 @@ setup_darwin(){

setup_windirs(){
$iswindows || return 0
_msg "Setup some directories for windows environment"

if $iscygwin
then
@@ -325,6 +359,7 @@ setup_windirs(){

if test -n "$__winhome" -a -d "$__winhome" -a '!' -e "$HOME/.winhome"
then
_msg Make symlink to "$__winhome" with name "$HOME/.winhome"
ln -s "$__winhome" "$HOME/.winhome"
fi
}
@@ -333,12 +368,26 @@ setup_windirs(){
# setup dirs

setup_dirs(){
mkdir -p "$__homelocal"
mkdir -p "$__homelocal/bin"
mkdir -p "$__homevar"
_msg Make some direcoties
mkdir -vp "$__homelocal"
mkdir -vp "$__homelocal/bin"
mkdir -vp "$__homevar"
}


####################################
# setup env
# setup new environment with default options

setup_env(){
setup_shrc_common
setup_dirs
setup_gitconf
setup_tmux
setup_scripts
setup_dotfiles --git
}


#########################
# main
@@ -357,9 +406,9 @@ main(){
_cmd=$1
shift

set -x
_msg Running setup_$_cmd
setup_$_cmd "$@"
set +x
_msg Setup done
}

main "$@"

Loading…
Откажи
Сачувај