Skip to content

Instantly share code, notes, and snippets.

@zundr
Last active October 9, 2015 05:48
Show Gist options
  • Select an option

  • Save zundr/3448412 to your computer and use it in GitHub Desktop.

Select an option

Save zundr/3448412 to your computer and use it in GitHub Desktop.

Revisions

  1. zundr revised this gist Jun 10, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -82,7 +82,7 @@ function ensure_package() {
    msg $GREEN "Package $1 installed, OK"
    return
    fi
    if dpkg -s $package >/dev/null 2>&1; then return; fi
    if dpkg -s $package | grep "install ok installed" >/dev/null 2>&1; then return; fi
    msg $BOLD "Installing $package..."

    if test -z "$NO_SUDO"; then
  2. zundr revised this gist Jun 10, 2013. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -89,7 +89,6 @@ function ensure_package() {
    msg $GREEN "If you cannot SUDO just press Ctrl-C"
    if sudo apt-get install $package; then
    NO_SUDO=1
    return
    fi
    fi

  3. zundr revised this gist Jun 10, 2013. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -100,12 +100,14 @@ function ensure_package() {
    local target_dir=$PWD/tmp/$package
    mkdir -p $target_dir
    dpkg-deb --extract $target_deb $target_dir
    export PATH="$target_dir/usr/bin:$PATH"
    export CFLAGS="-I$target_dir/usr/include $CFLAGS"
    export CPPFLAGS="-I$target_dir/usr/include $CFLAGS"
    export LDFLAGS="-L$target_dir/usr/lib $LDFLAGS"
    export RUBYLIB="$target_dir/usr/lib:$RUBYLIB"
    export PKG_CONFIG_PATH="$target_dir/usr/lib/pkgconfig:$PKG_CONFIG_PATH"

    export PATH="$target_dir/usr/bin:$PATH"
    hash -r
    }

    function link_binaries() {
  4. zundr revised this gist Jun 10, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -100,11 +100,12 @@ function ensure_package() {
    local target_dir=$PWD/tmp/$package
    mkdir -p $target_dir
    dpkg-deb --extract $target_deb $target_dir
    export PATH="$target_dir/usr/bin:$PATH"
    export CFLAGS="-I$target_dir/usr/include $CFLAGS"
    export CPPFLAGS="-I$target_dir/usr/include $CFLAGS"
    export LDFLAGS="-L$target_dir/usr/lib $LDFLAGS"
    export RUBYLIB="$target_dir/usr/lib:$RUBYLIB"
    export PKG_CONFIG
    export PKG_CONFIG_PATH="$target_dir/usr/lib/pkgconfig:$PKG_CONFIG_PATH"
    }

    function link_binaries() {
  5. zundr revised this gist Jun 10, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ function msg() {
    local color="\033[${1}m"
    local message=$2
    local normal="\033[0m"
    echo -e "${color}${message}${normal}
    echo -e "${color}${message}${normal}"
    }

    function link_files() {
  6. zundr revised this gist Jun 10, 2013. 1 changed file with 20 additions and 8 deletions.
    28 changes: 20 additions & 8 deletions dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,10 @@
    function msg() {
    local color="\033[${1}m"
    local message=$2
    local normal="\033[0m"
    echo -e "${color}${message}${normal}
    }
    function link_files() {
    local source_dir=$1
    local pattern=$2
    @@ -64,21 +71,26 @@ function link_directory() {
    fi
    }
    NORMAL="\033[0m"
    BOLD="\033[1;31m"
    GREEN="\033[32m"
    BOLD="1;31"
    GREEN="32"
    function ensure_package() {
    local package=$1
    local testfile=$2
    echo "${BOLD}Checking for $package ($testfile)...${NORMAL}"
    if test -n "$testfile" -a -f "$testfile"; then echo "${GREEN}Package $1 installed, OK${NORMAL}"; return; fi
    msg $GREEN "Checking for $package ($testfile)..."
    if test -n "$testfile" -a -f "$testfile"; then
    msg $GREEN "Package $1 installed, OK"
    return
    fi
    if dpkg -s $package >/dev/null 2>&1; then return; fi
    echo -n "Installing $package..."
    msg $BOLD "Installing $package..."
    if test -z "$NO_SUDO"; then
    echo -e "${GREEN}If you cannot SUDO just press Ctrl-C${NORMAL}"
    if sudo apt-get install $package; then NO_SUDO=1; return; fi
    msg $GREEN "If you cannot SUDO just press Ctrl-C"
    if sudo apt-get install $package; then
    NO_SUDO=1
    return
    fi
    fi
    # try local install (fails if several versions available :/)
  7. zundr revised this gist Jun 10, 2013. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -64,15 +64,20 @@ function link_directory() {
    fi
    }

    NORMAL="\033[0m"
    BOLD="\033[1;31m"
    GREEN="\033[32m"

    function ensure_package() {
    local package=$1
    local testfile=$2
    if test -n "$testfile" -a -f "$testfile"; then echo "Package $1 installed, OK"; return; fi
    echo "${BOLD}Checking for $package ($testfile)...${NORMAL}"
    if test -n "$testfile" -a -f "$testfile"; then echo "${GREEN}Package $1 installed, OK${NORMAL}"; return; fi
    if dpkg -s $package >/dev/null 2>&1; then return; fi
    echo -n "Installing $package..."

    if test -z "$NO_SUDO"; then
    echo -e "\033[32mIf you cannot SUDO just press Ctrl-C\033[0m"
    echo -e "${GREEN}If you cannot SUDO just press Ctrl-C${NORMAL}"
    if sudo apt-get install $package; then NO_SUDO=1; return; fi
    fi

    @@ -87,6 +92,7 @@ function ensure_package() {
    export CPPFLAGS="-I$target_dir/usr/include $CFLAGS"
    export LDFLAGS="-L$target_dir/usr/lib $LDFLAGS"
    export RUBYLIB="$target_dir/usr/lib:$RUBYLIB"
    export PKG_CONFIG
    }

    function link_binaries() {
  8. zundr revised this gist Jun 10, 2013. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -94,4 +94,16 @@ function link_binaries() {
    local bin_dir=$HOME/bin
    mkdir -p $bin_dir
    cp -sfv --target-directory=$bin_dir $source_dir/bin/*
    }

    function git_clone_or_update() {
    local repo_url=$1
    local target_dir=$2
    if [ -d $target_dir ]; then
    echo "Updating repo..."
    (cd $target_dir && git pull)
    else
    echo "Cloning repo $repo_url..."
    git clone $repo_url $target_dir
    fi
    }
  9. zundr revised this gist Jun 10, 2013. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -66,10 +66,15 @@ function link_directory() {

    function ensure_package() {
    local package=$1
    local testfile=$2
    if test -n "$testfile" -a -f "$testfile"; then echo "Package $1 installed, OK"; return; fi
    if dpkg -s $package >/dev/null 2>&1; then return; fi
    echo -n "Installing $package..."

    # if sudo apt-get install $package; then return; fi
    if test -z "$NO_SUDO"; then
    echo -e "\033[32mIf you cannot SUDO just press Ctrl-C\033[0m"
    if sudo apt-get install $package; then NO_SUDO=1; return; fi
    fi

    # try local install (fails if several versions available :/)
    local filename=$(apt-cache show $package|perl -ne 'print $1 if m/Filename: (.*)/')
  10. zundr revised this gist May 30, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -69,7 +69,7 @@ function ensure_package() {
    if dpkg -s $package >/dev/null 2>&1; then return; fi
    echo -n "Installing $package..."

    if sudo apt-get install $package; then return; fi
    # if sudo apt-get install $package; then return; fi

    # try local install (fails if several versions available :/)
    local filename=$(apt-cache show $package|perl -ne 'print $1 if m/Filename: (.*)/')
    @@ -78,6 +78,7 @@ function ensure_package() {
    local target_dir=$PWD/tmp/$package
    mkdir -p $target_dir
    dpkg-deb --extract $target_deb $target_dir
    export CFLAGS="-I$target_dir/usr/include $CFLAGS"
    export CPPFLAGS="-I$target_dir/usr/include $CFLAGS"
    export LDFLAGS="-L$target_dir/usr/lib $LDFLAGS"
    export RUBYLIB="$target_dir/usr/lib:$RUBYLIB"
  11. zundr revised this gist Nov 7, 2012. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -69,6 +69,9 @@ function ensure_package() {
    if dpkg -s $package >/dev/null 2>&1; then return; fi
    echo -n "Installing $package..."

    if sudo apt-get install $package; then return; fi

    # try local install (fails if several versions available :/)
    local filename=$(apt-cache show $package|perl -ne 'print $1 if m/Filename: (.*)/')
    local target_deb=$PWD/tmp/$package.deb
    wget -c http://ftp.de.debian.org/debian/$filename -O $target_deb
  12. zundr revised this gist Oct 4, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,8 @@ function link_file() {
    local old_link="$(readlink $target_file)"
    if [ "$old_link" = "$source_file" ]; then
    echo "$file_name: already linked"
    else
    else
    rm --force $target_file
    cp --force --symbolic-link $source_file $target_dir
    echo "$file_name: replaced (was linking to $old_link)"
    fi
  13. zundr revised this gist Oct 3, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -76,6 +76,7 @@ function ensure_package() {
    dpkg-deb --extract $target_deb $target_dir
    export CPPFLAGS="-I$target_dir/usr/include $CFLAGS"
    export LDFLAGS="-L$target_dir/usr/lib $LDFLAGS"
    export RUBYLIB="$target_dir/usr/lib:$RUBYLIB"
    }

    function link_binaries() {
  14. zundr revised this gist Sep 14, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -74,7 +74,7 @@ function ensure_package() {
    local target_dir=$PWD/tmp/$package
    mkdir -p $target_dir
    dpkg-deb --extract $target_deb $target_dir
    export CFLAGS="-I$target_dir/usr/include $CFLAGS"
    export CPPFLAGS="-I$target_dir/usr/include $CFLAGS"
    export LDFLAGS="-L$target_dir/usr/lib $LDFLAGS"
    }

  15. zundr revised this gist Sep 14, 2012. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -77,3 +77,10 @@ function ensure_package() {
    export CFLAGS="-I$target_dir/usr/include $CFLAGS"
    export LDFLAGS="-L$target_dir/usr/lib $LDFLAGS"
    }

    function link_binaries() {
    local source_dir=$1
    local bin_dir=$HOME/bin
    mkdir -p $bin_dir
    cp -sfv --target-directory=$bin_dir $source_dir/bin/*
    }
  16. zundr revised this gist Sep 14, 2012. 1 changed file with 16 additions and 1 deletion.
    17 changes: 16 additions & 1 deletion dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -61,4 +61,19 @@ function link_directory() {
    ln --symbolic --target-directory=$target_dir $source_file
    echo "$file_name: replaced (backed up old file)"
    fi
    }
    }

    function ensure_package() {
    local package=$1
    if dpkg -s $package >/dev/null 2>&1; then return; fi
    echo -n "Installing $package..."

    local filename=$(apt-cache show $package|perl -ne 'print $1 if m/Filename: (.*)/')
    local target_deb=$PWD/tmp/$package.deb
    wget -c http://ftp.de.debian.org/debian/$filename -O $target_deb
    local target_dir=$PWD/tmp/$package
    mkdir -p $target_dir
    dpkg-deb --extract $target_deb $target_dir
    export CFLAGS="-I$target_dir/usr/include $CFLAGS"
    export LDFLAGS="-L$target_dir/usr/lib $LDFLAGS"
    }
  17. zundr revised this gist Aug 24, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    unction link_files() {
    function link_files() {
    local source_dir=$1
    local pattern=$2
    local target_dir=$3
  18. zundr revised this gist Aug 24, 2012. 1 changed file with 34 additions and 7 deletions.
    41 changes: 34 additions & 7 deletions dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,17 @@
    function link_files() {
    unction link_files() {
    local source_dir=$1
    local pattern=$2
    local target_dir=$3
    echo "** Processing $source_dir"
    local files="$(find $source_dir -maxdepth 1 -type f -name "$pattern")"
    local files="$(find $source_dir -mindepth 1 -maxdepth 1 -name "$pattern")"
    if [ -n "$files" ]; then
    mkdir -p $target_dir
    for file in $files; do
    link_file $file $target_dir
    if [ -d $file ]; then
    link_directory $file $target_dir
    else
    link_file $file $target_dir
    fi
    done
    else
    echo "No files to link!"
    @@ -19,19 +23,42 @@ function link_file() {
    local target_dir=$2
    local file_name="$(basename $source_file)"
    local target_file="$target_dir/$file_name"
    if [ ! -f $target_file ]; then
    echo "$file_name: linked!"
    if [ ! -e $target_file ]; then
    cp --symbolic-link $source_file $target_dir
    echo "$file_name: linked!"
    elif [ -L $target_file ]; then
    local old_link="$(readlink $target_file)"
    if [ "$old_link" = "$source_file" ]; then
    echo "$file_name: already linked"
    else
    echo "$file_name: replaced (was linking to $old_link)"
    cp --force --symbolic-link $source_file $target_dir
    echo "$file_name: replaced (was linking to $old_link)"
    fi
    else
    echo "$file_name: replaced (backed up old file)"
    VERSION_CONTROL=numbered cp --backup --symbolic-link $source_file $target_dir
    echo "$file_name: replaced (backed up old file)"
    fi
    }

    function link_directory() {
    local source_file=$1
    local target_dir=$2
    local file_name="$(basename $source_file)"
    local target_file="$target_dir/$file_name"
    if [ ! -e $target_file ]; then
    ln --symbolic --target-directory=$target_dir $source_file
    echo "$file_name: linked!"
    elif [ -L $target_file ]; then
    local old_link="$(readlink $target_file)"
    if [ "$old_link" = "$source_file" ]; then
    echo "$file_name: already linked"
    else
    ln --symbolic --target-directory=$target_dir --force $source_file
    echo "$file_name: replaced (was linking to $old_link)"
    fi
    else
    VERSION_CONTROL=numbered mv $target_file $target_file-old
    ln --symbolic --target-directory=$target_dir $source_file
    echo "$file_name: replaced (backed up old file)"
    fi
    }
  19. zundr revised this gist Aug 24, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion dotfiles-installer.sh
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ function link_files() {
    local pattern=$2
    local target_dir=$3
    echo "** Processing $source_dir"
    local files="$(find $source_dir -type f -name "$pattern")"
    local files="$(find $source_dir -maxdepth 1 -type f -name "$pattern")"
    if [ -n "$files" ]; then
    mkdir -p $target_dir
    for file in $files; do
  20. zundr renamed this gist Aug 24, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  21. zundr created this gist Aug 24, 2012.
    37 changes: 37 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    function link_files() {
    local source_dir=$1
    local pattern=$2
    local target_dir=$3
    echo "** Processing $source_dir"
    local files="$(find $source_dir -type f -name "$pattern")"
    if [ -n "$files" ]; then
    mkdir -p $target_dir
    for file in $files; do
    link_file $file $target_dir
    done
    else
    echo "No files to link!"
    fi
    }

    function link_file() {
    local source_file=$1
    local target_dir=$2
    local file_name="$(basename $source_file)"
    local target_file="$target_dir/$file_name"
    if [ ! -f $target_file ]; then
    echo "$file_name: linked!"
    cp --symbolic-link $source_file $target_dir
    elif [ -L $target_file ]; then
    local old_link="$(readlink $target_file)"
    if [ "$old_link" = "$source_file" ]; then
    echo "$file_name: already linked"
    else
    echo "$file_name: replaced (was linking to $old_link)"
    cp --force --symbolic-link $source_file $target_dir
    fi
    else
    echo "$file_name: replaced (backed up old file)"
    VERSION_CONTROL=numbered cp --backup --symbolic-link $source_file $target_dir
    fi
    }