From 805998921ae219e9fdd26e52e3e5914c4f426c51 Mon Sep 17 00:00:00 2001 From: David Tomaschik Date: Wed, 3 Jan 2018 13:28:45 -0800 Subject: [PATCH 1/3] Fix options;modularize. --- install.sh | 55 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/install.sh b/install.sh index 66850e5..30b4793 100755 --- a/install.sh +++ b/install.sh @@ -1,7 +1,7 @@ #!/bin/bash -set nounset -set errexit +set -o nounset +set -o errexit function prerequisites { if which zsh > /dev/null 2>&1 ; then @@ -282,13 +282,32 @@ EOF } function verbose { - (( ${VERBOSE:-0} )) && echo "$@" >&2 + (( ${VERBOSE:-0} )) && echo "$@" >&2 || return 0 +} + +# Operations + +function install_main { + (( $MINIMAL )) || prerequisites + (( $INSTALL_PKGS )) && is_deb_system && install_apt_pkgs + install_dotfile_dir "${BASEDIR}/dotfiles" + test -d "${BASEDIR}/private_dotfiles" && \ + test -d "${BASEDIR}/.git/git-crypt" && \ + install_dotfile_dir "${BASEDIR}/private_dotfiles" + test -d "${BASEDIR}/local_dotfiles" && \ + install_dotfile_dir "${BASEDIR}/local_dotfiles" + install_basic_dir "${BASEDIR}/bin" "${HOME}/bin" + (( $MINIMAL )) || postinstall + (( $INSTALL_KEYS )) && install_keys + save_prefs + cleanup } # Setup variables read_saved_prefs -# Defaults if not passed in or saved +# Defaults if not passed in or saved. +# TODO: use flags instead of environment variables. BASEDIR=${BASEDIR:-$HOME/.skel} MINIMAL=${MINIMAL:-0} INSTALL_KEYS=${INSTALL_KEYS:-1} @@ -309,20 +328,20 @@ else HAVE_X=0 fi -IS_KALI=`grep -ci kali /etc/os-release 2>/dev/null` +IS_KALI=`grep -ci kali /etc/os-release 2>/dev/null || true` ARCH=`uname -m` +OPERATION=${1:-install} -(( $MINIMAL )) || prerequisites -(( $INSTALL_PKGS )) && is_deb_system && install_apt_pkgs -install_dotfile_dir "${BASEDIR}/dotfiles" -test -d "${BASEDIR}/private_dotfiles" && \ - test -d "${BASEDIR}/.git/git-crypt" && \ - install_dotfile_dir "${BASEDIR}/private_dotfiles" -test -d "${BASEDIR}/local_dotfiles" && \ - install_dotfile_dir "${BASEDIR}/local_dotfiles" -install_basic_dir "${BASEDIR}/bin" "${HOME}/bin" -(( $MINIMAL )) || postinstall -(( $INSTALL_KEYS )) && install_keys -save_prefs -cleanup +case $OPERATION in + install) + install_main + ;; + package*) + install_pkg_set packages.${2} + ;; + *) + echo "Unknown operation $OPERATION." >/dev/stderr + exit 1 + ;; +esac From 085990872425e8424f2a9b43502d5faa5586b725 Mon Sep 17 00:00:00 2001 From: David Tomaschik Date: Wed, 3 Jan 2018 13:50:57 -0800 Subject: [PATCH 2/3] Support arguments to install_git. --- install.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index 30b4793..bd371e8 100755 --- a/install.sh +++ b/install.sh @@ -55,15 +55,16 @@ function install_git { if ! which git > /dev/null ; then return 1 fi - local REPO="${1}" - local DESTDIR="${2}" + local REPO="${*: -2:1}" + local DESTDIR="${*: -1:1}" + set ${*:1:-2} if [[ -d ${DESTDIR}/.git ]] ; then ( cd ${DESTDIR} ; git pull -q ) else if [[ ${MINIMAL} -eq 1 ]] ; then - git clone --depth 1 ${REPO} ${DESTDIR} + git clone --depth 1 $* ${REPO} ${DESTDIR} else - git clone ${REPO} ${DESTDIR} + git clone $* ${REPO} ${DESTDIR} fi fi } @@ -82,7 +83,7 @@ function install_pwndbg { if ! which gdb > /dev/null 2>&1 ; then return 1 fi - install_git https://github.com/pwndbg/pwndbg.git $HOME/.pwndbg + install_git -b stable https://github.com/pwndbg/pwndbg.git $HOME/.pwndbg mkdir -p $HOME/.pwndbg/vendor local PYVER=$(gdb -batch -q --nx -ex 'pi import platform; print(".".join(platform.python_version_tuple()[:2]))') local PYTHON=$(gdb -batch -q --nx -ex 'pi import sys; print(sys.executable)') From 5d1eaccbbc63aab1dda2afa049c2c31cb2216987 Mon Sep 17 00:00:00 2001 From: David Tomaschik Date: Thu, 4 Jan 2018 09:57:22 -0800 Subject: [PATCH 3/3] Make pwndbg a separate action. --- install.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index bd371e8..5ca5e4a 100755 --- a/install.sh +++ b/install.sh @@ -96,8 +96,6 @@ function install_pwndbg { } function postinstall { - install_pwndbg - # Install Vundle plugins if [[ -d $HOME/.vim/bundle/Vundle.vim ]] ; then vim +VundleInstall +qall @@ -341,6 +339,9 @@ case $OPERATION in package*) install_pkg_set packages.${2} ;; + pwndbg) + install_pwndbg + ;; *) echo "Unknown operation $OPERATION." >/dev/stderr exit 1