.
[zsh.git] / .zsh / install.zsh
1 # -*- sh -*-
2
3 autoload colors ; colors
4
5 # Install or update my ZSH config on a remote host.
6 # Needs Git and makeself locally
7 install-zsh() {
8 local remote
9 local work
10 local start
11 remote=$1
12 work=$(mktemp -d)
13 start=$(pwd)
14 {
15 local OK="$fg_bold[green]OK.${reset_color}"
16 print -n "$fg[green]Building archive...${reset_color} "
17 cd $ZSH
18 git archive HEAD | tar -C $work -xf -
19 cp $HOME/.zshenv $work/zshenv.home
20 print $OK
21 print -n "$fg[green]Building installer...${reset_color} "
22 makeself --gzip $work $ZSH/zsh-install.sh \
23 "$USER ZSH config files" zsh ./install.zsh MAGIC
24 print $OK
25 [[ -z $1 ]] || {
26 print "$fg[green]Remote install...${reset_color} "
27 scp $ZSH/zsh-install.sh ${remote}:
28 ssh $remote sh ./zsh-install.sh
29 print $OK
30 }
31 } always {
32 rm -rf $work
33 cd $start
34 }
35 }
36
37 # We can be executed to install ourself to the final destination
38 if [[ $1 == "MAGIC" ]]; then
39 (( $+commands[rsync] )) || {
40 print "$fg_bold[red]rsync not found, install it${reset_color}"
41 exit 2
42 }
43 local OK="$fg[green]OK.${reset_color}"
44
45 # Migrate history
46 print -n "$fg[green]History migration...${reset_color} "
47 mkdir -p ~/.zsh/var/dirhist
48 if [[ -f ~/.zsh_history ]] && [[ ! -f ~/.zsh/var/history.$USER.$HOST ]]; then
49 { mv ~/.zsh_history ~/.zsh/var/history.$USER.$HOST }
50 fi
51 print $OK
52 print -n "$fg[green]HMoving completion dump...${reset_color} "
53 mkdir -p ~/.zsh/.zcompcache
54 for file in ~/.zcompdump ~/.zsh/.zcompdump; do
55 if [[ -f $file ]]; then
56 mv $file ~/.zsh/var/.zcompdump
57 fi
58 done
59 print $OK
60 print "$fg[green]Installation of zsh files...${reset_color} "
61 rsync -rlp --exclude=var/ --exclude=.zcompcache/ --delete . ~/.zsh/.
62 rm -f ~/.zlogin
63 rm -f ~/.zlogout
64 rm -f ~/.zshrc
65 rm -f ~/.zshenv
66 ln -s .zsh/zshenv.home ~/.zshenv
67 linktarget=$(relative "${HOME}/zshenv.local" "${HOME}/zshenv.local.sample")
68 /bin/ln -s "${linktarget}" "${HOME}/zshenv.local.sample"
69 print $OK
70 print "$fg[green]Disabling old udh cronjob...${reset_color} "
71 crontab -l|sed -e 's_\(#\?[0-9][0-9] [/6*]* \* \* \* $HOME/bin/udh >/dev/null\)_#off#\1_'|crontab
72 print $OK
73 fi