From ffe0b8f65b8ab0eba56b61b415eb7b4f86cebda4 Mon Sep 17 00:00:00 2001 From: Bruno Tavares Date: Fri, 21 Feb 2014 15:11:59 -0300 Subject: [PATCH] Add profile support for mac --- kickstart/recipes/kickstart.sh | 8 ------- kickstart/recipes/kickstart/profile.sh | 32 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 kickstart/recipes/kickstart/profile.sh diff --git a/kickstart/recipes/kickstart.sh b/kickstart/recipes/kickstart.sh index 544bcce..2fc089d 100644 --- a/kickstart/recipes/kickstart.sh +++ b/kickstart/recipes/kickstart.sh @@ -27,14 +27,6 @@ kickstart.mute() { return $? } -kickstart.add_to_profile.d() { - file=$1 - [ ! -f files/$file ] && kickstart.info "File files/$file not found" && exit 1 - - cp files/$file /etc/profile.d/$file - grep -q $file /etc/zshenv 2>/dev/null || ( echo "[[ -f /etc/profile.d/$file ]] && source /etc/profile.d/$file" >> /etc/zshenv ) -} - kickstart.command_exists() { which $1 >/dev/null 2>&1 } diff --git a/kickstart/recipes/kickstart/profile.sh b/kickstart/recipes/kickstart/profile.sh new file mode 100644 index 0000000..0798ae9 --- /dev/null +++ b/kickstart/recipes/kickstart/profile.sh @@ -0,0 +1,32 @@ +kickstart.profile.add_to_profile() { + local file=$1 + [ ! -f files/$file ] && kickstart.info "File files/$file not found" && exit 1 + + local profile_d=`kickstart.profile.profile.d.location` + mkdir -p $profile_d + + cp files/$file $profile_d/$file + + kickstart.profile.source_on_configuration_file $file $profile_d `kickstart.profile.location.zsh` + kickstart.os.is Mac && kickstart.profile.source_on_configuration_file $file $profile_d `kickstart.profile.location.bash` +} + +kickstart.profile.profile.d.location() { + kickstart.os.is Ubuntu && echo /etc/profile.d + kickstart.os.is Mac && echo ~/.profile.d +} + +kickstart.profile.source_on_configuration_file() { + local file=$1 + local profile_d=$2 + local configuration=$3 + grep -q $file $configuration 2>/dev/null || ( echo "[[ -f $profile_d/$file ]] && source $profile_d/$file" >> $configuration ) +} + +kickstart.profile.location.zsh() { + [ `whoami` = root ] && echo /etc/zshenv || echo ~/.zshenv +} + +kickstart.profile.location.bash() { + [ `whoami` = root ] && echo /etc/profile || echo ~/.bashrc +}