add dist-config to move into a new host
authorJoerg Jaspert <joerg@debian.org>
Wed, 6 Mar 2013 07:16:30 +0000 (08:16 +0100)
committerJoerg Jaspert <joerg@debian.org>
Wed, 6 Mar 2013 07:16:30 +0000 (08:16 +0100)
A .zsh/functions/dist-config
D .zsh/functions/logout
D .zsh/functions/mcdrom
D .zsh/functions/reallyexit
M .zsh/install.zsh

.zsh/functions/dist-config [new file with mode: 0644]
.zsh/functions/logout [deleted file]
.zsh/functions/mcdrom [deleted file]
.zsh/functions/reallyexit [deleted file]
.zsh/install.zsh

diff --git a/.zsh/functions/dist-config b/.zsh/functions/dist-config
new file mode 100644 (file)
index 0000000..3d28727
--- /dev/null
@@ -0,0 +1,143 @@
+# -*- sh -*-
+
+autoload colors ; colors
+
+plog() {
+    if [ $1 = "OK" ]; then
+        print "$fg[cyan]OK.${reset_color}"
+    else
+        print -n "$fg[green]$@...${reset_color} "
+    fi
+}
+
+# We can be executed to install ourself to the final destination
+if [[ $1 == "MAGIC" ]]; then
+    local anon=${2:-"true"}
+    plog "Installing basic dotfile support"
+
+    mkdir -p ${HOME}/bin
+    mkdir -p ${HOME}/.certs
+    for file in mr vcsh; do
+        cp bin/${file} ${HOME}/bin/${file}
+    done
+    cp .certs/ganneff.pem ${HOME}/.certs/ganneff.pem
+    plog "OK"
+    PATH=$HOME/bin:$PATH
+    answer="y"
+    if [[ -d "${HOME}/.config/vcsh/" ]]; then
+        answer="N"
+        echo "$fg[blue]Looks like there is a vcsh controlled config already."
+        echo "I can get rid of it and all its files before fetching the new one.${reset_color}"
+        echo "$fg[red]This will move ALL files from ANY vcsh controlled repository into '~/.oldhome'!${reset_color}"
+        vared -p "Want to do this it? [N/y] " answer
+        case ${answer} in
+            y|Y)
+                # Replace, get rid of old
+                plog "Moving files from vcsh"
+                mkdir ${HOME}/.oldhome
+                for delfile in $(vcsh list-tracked); do
+                    dirpart=${delfile:h}
+                    mkdir -p "${HOME}/.oldhome/${dirpart}"
+                    mv --target-directory="${HOME}/.oldhome/${dirpart}" ${HOME}/${delfile}
+                done
+                plog "OK"
+                mkdir -p "${HOME}/.oldhome/.config/"
+                mv --target-directory="${HOME}/.oldhome" "${HOME}/.config/vcsh/"
+                mv --target-directory="${HOME}/.oldhome" "${HOME}/.config/mr/"
+                mv --target-directory="${HOME}/.oldhome" "${HOME}/.mrconfig"
+                plog "OK"
+                answer="y"
+                read
+                ;;
+            n|N)
+                plog "Not deleting old vcsh directories, trying to continue with existing stuff\n"
+                ;;
+            *)
+                echo "Silly?"
+                return
+        esac
+    fi
+    if [[ $answer = "y" ]]; then
+        plog "Fetching mr config "
+        if [[ $anon = "true" ]]; then
+            plog "using the anonymous version\n"
+            GIT_SSL_CAINFO=${HOME}/.certs/ganneff.pem vcsh clone https://kosh.ganneff.de/git/mr.git
+            cd ${HOME}/.config/mr/config.d
+            for file in *.vcsh; do
+                rm ${file}
+                ln -s ../available.d/${file}-anon
+            done
+            plog "OK"
+        else
+            plog "using the ssh version\n"
+            vcsh clone git@git.ganneff.de:mr.git
+            plog "OK"
+        fi
+    fi
+    plog "Pulling all dotfile repositories\n"
+    cd ${HOME}
+    # The GIT_SSL_CAINFO variable isn't used when using the ssh version.
+    # But it also doesn't hurt, so leave it in, less code than an if clause
+    GIT_SSL_CAINFO=${HOME}/.certs/ganneff.pem mr update
+    plog "OK"
+    if [[ $anon = "true" ]]; then
+        plog "Setup ssl certs for all dotfile repositories\n"
+        mr run git config --local --add http.sslCAInfo ${HOME}/.certs/ganneff.pem
+        plog "OK"
+    fi
+    plog "Hard resetting dotfiles to ensure all files are there and the VCS versions\n"
+    mr run git reset --hard
+    plog "OK"
+
+    plog "Now sourcing parts of the new zsh config"
+    # Shut up "helper" function
+    function debug() {}
+    source ${HOME}/.zsh/zshenv.home
+    source ${HOME}/.zsh/00_Basics.zsh
+    source ${HOME}/.zsh/30_Options.zsh
+    autoload -U udh
+    plog "OK"
+    mkdir ${HOME}/tmp
+    plog "Running udh to setup the rest\n"
+    udh
+
+    unfunction plog
+    return
+fi
+
+{
+    # install my dotfiles in a remote host.
+    # needs makeself locally and git remotely.
+    local remote
+    local work
+    local start
+    remote=$1
+    anon=${2:-"true"}
+    work=$(mktemp -d)
+    start=$(pwd)
+    {
+        plog "Building archive..."
+        mkdir -p ${work}/bin
+        cp $(which mr) ${work}/bin
+        cp $(which vcsh) ${work}/bin
+        mkdir -p ${work}/.certs
+        cp ~/.TinyCA/Ganneff_CA/cacert.pem ${work}/.certs/ganneff.pem
+        cp ~/.zsh/functions/dist-config ${work}/dist-config
+        plog "OK"
+        plog "Building installer..."
+        makeself --gzip $work ${TMPDIR}/dotfiles-install.sh \
+            "$USER dotfiles" zsh ./dist-config MAGIC ${anon}
+        plog "OK"
+        [[ -z $1 ]] || {
+            plog "Remote install..."
+            scp $TMPDIR/dotfiles-install.sh ${remote}:
+            ssh $remote sh ./dotfiles-install.sh
+            plog "OK"
+        }
+    } always {
+        # Always clean up behind us
+        rm -rf $work
+        cd $start
+        unfunction plog
+    }
+}
diff --git a/.zsh/functions/logout b/.zsh/functions/logout
deleted file mode 100644 (file)
index 9c1c166..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-# -*- mode:sh -*-
-
-# Process the exceptions which allow logging out while still having
-# attached jobs.
-
-# This is weird . . $1 seems to contain "logout" because the "logout"
-# command has been aliased to "noglob logout" - and $0 is the noglob.
-# I can't believe that this is what is meant to happen.
-if [[ $1 = "logout" ]]
-then
-       shift
-fi
-# If the checkjobs option is unset, just plain exit.  (This option
-# emerged in zsh 3.1.8.)
-if [[ ! -o checkjobs ]]
-then
-    reallyexit ${1+"$@"}
-fi
-# Did I type logout twice in a row?  Note check for history number.
-if [[ $history[$#history] = (exit|(logout|lo)(|\ *)) || $lastlogout = $#history ]]; then
-    reallyexit ${1+"$@"}
-fi
-
-# Did I type jobs, then logout?
-if [[ $history[$#history] = (j(|obs)(|\ *)) ]]; then
-    reallyexit ${1+"$@"}
-fi
-
-lastlogout=$#history
-
-# Emulate the code that protects against logout if I have
-# attached jobs.
-if [[ $#jobstates -gt 0 ]]; then
-    # The first listed state is good enough to be a hint of my job states.
-    echo "You have ${jobstates[${${(k)jobstates}[1]}]%%:*} jobs."
-    return
-fi
-
-# If we got here we're really exiting.
-reallyexit ${1+"$@"}
diff --git a/.zsh/functions/mcdrom b/.zsh/functions/mcdrom
deleted file mode 100644 (file)
index 9e44506..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-# -*- mode:sh -*-
-
-local mounted
-local cpwd
-mounted=$(grep cdrom /etc/mtab)
-if [[ $mounted = "" ]];then
-    mount /cdrom/
-    echo "-- mounted cdrom --"
-    cd /cdrom/ ; ls
-else
-    cpwd=$(pwd|grep cdrom)
-    if [[ $cpwd = "" ]];then
-        umount /cdrom/
-        echo "-- umounted cdrom --"
-       else
-        cd; umount /cdrom/
-        echo "-- umounted cdrom --"
-        pwd
-    fi
-fi
diff --git a/.zsh/functions/reallyexit b/.zsh/functions/reallyexit
deleted file mode 100644 (file)
index 98a854a..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-# -*- mode:sh -*-
-
-# logging out
-# It isn't bulletproof, but it's good
-# enough for my needs.
-# This function is called if I really want to exit the shell.
-kill -HUP $$
-
index bf1fea5..1855360 100644 (file)
@@ -16,9 +16,6 @@ install-zsh() {
         print -n "$fg[green]Building archive...${reset_color} "
         cd $ZSH 
         git archive HEAD | tar -C $work -xf -
-        mkdir -p $work/zsh-syntax-highlighting
-        cd $ZSH/zsh-syntax-highlighting 
-        git archive HEAD | tar -C $work/zsh-syntax-highlighting -xf -
         cp $HOME/.zshenv $work/zshenv.home
         print $OK
         print -n "$fg[green]Building installer...${reset_color} "