From f9fa0ba17dd800e0b1b21027582a7803d42dcc8c Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Tue, 12 Nov 2019 17:59:41 -0800 Subject: [PATCH] Update packages to install multiple packages and a bunch of linting updates --- helpers/default | 126 +++++++++-------------------------- master-cookbook | 2 +- recipes/default/bin | 5 +- recipes/default/build-fish | 10 +-- recipes/default/build-neovim | 10 +-- recipes/default/build-vim | 16 ++--- recipes/default/dotfiles | 0 recipes/default/fish | 12 ++-- recipes/default/git | 2 +- recipes/default/golang | 9 +-- recipes/default/mac-bin | 6 +- recipes/default/packages | 32 +++++---- recipes/default/salesforce | 4 +- recipes/default/vim-settings | 10 +-- 14 files changed, 95 insertions(+), 149 deletions(-) mode change 100644 => 100755 recipes/default/bin mode change 100644 => 100755 recipes/default/build-fish mode change 100644 => 100755 recipes/default/build-neovim mode change 100644 => 100755 recipes/default/build-vim mode change 100644 => 100755 recipes/default/dotfiles mode change 100644 => 100755 recipes/default/fish mode change 100644 => 100755 recipes/default/git mode change 100644 => 100755 recipes/default/mac-bin mode change 100644 => 100755 recipes/default/salesforce mode change 100644 => 100755 recipes/default/vim-settings diff --git a/helpers/default b/helpers/default index 2060166..d59eeb0 100644 --- a/helpers/default +++ b/helpers/default @@ -4,7 +4,7 @@ # DO NOT MODIFY THIS FILE. Instead, modify 'helpers/custom'. ############################################################################## -COOKBOOK_NAME="$(basename $0)" +COOKBOOK_NAME="$(basename "$0")" if [ -z "$SHOESTRAP_BASE" ]; then DIR="$( cd "$( dirname "$0" )" && pwd )" else @@ -24,19 +24,19 @@ recipe () { local default_recipe="$DIR/recipes/default/$CURRENT_RECIPE_NAME" local cookbook_recipe="$DIR/recipes/$COOKBOOK_NAME/$CURRENT_RECIPE_NAME" - if [ -f $cookbook_recipe ]; then + if [ -f "$cookbook_recipe" ]; then log "Running recipe '$cookbook_recipe'..." 1 separator - . $cookbook_recipe - elif [ -f $default_recipe ]; then + . "$cookbook_recipe" + elif [ -f "$default_recipe" ]; then log "Running recipe '$default_recipe'..." 1 separator - . $default_recipe + . "$default_recipe" else error "Could not find recipe for '$CURRENT_RECIPE_NAME'. Fail!" fi - cd $DIR + cd "$DIR" || error "Failed to find recipe" } # @@ -61,13 +61,13 @@ finished () { # log () { if [[ $2 -gt 0 ]]; then - spacer $2 + spacer "$2" fi echo " * $1" if [[ $3 -gt 0 ]]; then - spacer $3 + spacer "$3" fi } @@ -91,7 +91,7 @@ spacer () { local spaces=1 fi - for (( i=0; i<$spaces; i++ )) do + for (( i=0; i /dev/null 2>&1 - - if [ $? -eq 0 ]; then - log "Package '$1' is already installed. Skipping." - return 0 - fi - - if [ "$PACKAGE_MANAGER" == 'apt-get' ]; then - DEBIAN_FRONTEND=noninteractive apt-get install -y --force-yes $1 - elif [ "$PACKAGE_MANAGER" == 'yum' ]; then - yum install -y $1 - elif [ "$PACKAGE_MANAGER" == 'port' ]; then - # Unintuitive, but this skips all promps which should assume Y - port -N install $1 - elif [ "$PACKAGE_MANAGER" == 'brew' ]; then - brew install $1 - else - error "Unknown package manager: $PACKAGE_MANAGER" - fi - - if [ $? -ne 0 ]; then - error "An error occured while installing package '$1'. Fail!" - else - spacer 2 - fi -} - - sudo_package () { - log "Installing package '$1'..." + log "Installing packages '$*'..." detect_package_manager - test_package_installed $1 > /dev/null 2>&1 - - if [ $? -eq 0 ]; then - log "Package '$1' is already installed. Skipping." - return 0 - fi - if [ "$PACKAGE_MANAGER" == 'apt-get' ]; then - DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --force-yes $1 + DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --allow $* elif [ "$PACKAGE_MANAGER" == 'yum' ]; then - sudo yum install -y $1 + sudo yum install -y $* elif [ "$PACKAGE_MANAGER" == 'port' ]; then # Unintuitive, but this skips all promps which should assume Y - sudo port -N install $1 + sudo port -N install $* elif [ "$PACKAGE_MANAGER" == 'brew' ]; then - brew install $1 + brew install $* else error "Unknown package manager: $PACKAGE_MANAGER" fi if [ $? -ne 0 ]; then - error "An error occured while installing package '$1'. Fail!" + error "An error occured while installing packages. Fail!" else spacer 2 fi @@ -354,17 +292,17 @@ try_link () { src="$src" elif [ -f "$cookbook_assets_source" ]; then src="$cookbook_assets_source" - elif [ -f $default_assets_source ]; then + elif [ -f "$default_assets_source" ]; then src="$default_assets_source" elif [ -d "$cookbook_assets_source" ]; then src="$cookbook_assets_source" - elif [ -d $default_assets_source ]; then + elif [ -d "$default_assets_source" ]; then src="$default_assets_source" else error "Could not find '$1' to link Fail!" fi - if [ -L "$2" ] && [ "$(readlink $2)" == "$src" ] ; then + if [ -L "$2" ] && [ "$(readlink "$2")" == "$src" ] ; then log "Link already exists: $2" else log "Creating link: $2 -> $src" @@ -380,18 +318,16 @@ add_user () { local pass=$2 local args=$3 - id $user > /dev/null 2>&1 - - if [ $? -eq 0 ]; then + if id "$user" > /dev/null 2>&1 ; then log "User $user already exists. Skipped creation." else log "Adding user $user..." [ "$pass" == "" ] && pass=generate_password if [[ "$args" != *nohome* ]]; then - /usr/sbin/useradd --password `openssl passwd -crypt $pass` --create-home $user --shell /bin/bash + /usr/sbin/useradd --password "$(openssl passwd -crypt "$pass")" --create-home "$user" --shell /bin/bash else - /usr/sbin/useradd --password `openssl passwd -crypt $pass` $user --shell /bin/bash + /usr/sbin/useradd --password "$(openssl passwd -crypt "$pass")" "$user" --shell /bin/bash fi fi } @@ -415,7 +351,7 @@ run_as () { log "$cmd" # sudo -u $user -H -s /bin/bash -c "$cmd" # sudo -u $user -s /bin/bash -i "$cmd" - su -c "$cmd" -s /bin/bash $user + su -c "$cmd" -s /bin/bash "$user" } # @@ -438,7 +374,7 @@ add_line () { # Write a warning if user is not root. # warn_if_not_root () { - uid=`id -u` && [ "$uid" = "0" ] || + uid="$(id -u)" && [ "$uid" = "0" ] || { echo "WARNING: You are NOT running this script as 'root'. You might want to consider that..."; } } @@ -446,7 +382,7 @@ warn_if_not_root () { # Stops the execution of the script if user is not root. # fail_if_not_root () { - uid=`id -u` && [ "$uid" = "0" ] || + uid="$(id -u)" && [ "$uid" = "0" ] || { echo "You must run this as 'root'. Exiting."; exit 1; } } @@ -473,8 +409,8 @@ set_installed () { local args=$* local name=${args//[ \/:@]/-} - mkdir -p ~/.shoestrap/installed - touch ~/.shoestrap/installed/$name + mkdir -p "$HOME/.shoestrap/installed" + touch "$HOME/.shoestrap/installed/$name" } # diff --git a/master-cookbook b/master-cookbook index b640847..81012da 100755 --- a/master-cookbook +++ b/master-cookbook @@ -8,7 +8,7 @@ ############################################################## # Get current directory for future use in links -cd $(dirname $0) +cd "$(dirname "$0")" || { echo "Could not change directory to $0"; exit 1;} PROJECT_DIR=$(pwd) detect_package_manager diff --git a/recipes/default/bin b/recipes/default/bin old mode 100644 new mode 100755 index ba78b64..7ecf8d1 --- a/recipes/default/bin +++ b/recipes/default/bin @@ -1,6 +1,7 @@ #! /bin/bash -for f in $DEFAULT_ASSETS_PATH/* ; do - try_link "$f" "$USER_BIN/$(basename $f)" +# Link all user specific scripts to user bin +for f in "$DEFAULT_ASSETS_PATH"/* ; do + try_link "$f" "$USER_BIN/$(basename "$f")" done diff --git a/recipes/default/build-fish b/recipes/default/build-fish old mode 100644 new mode 100755 index 7600736..d025dba --- a/recipes/default/build-fish +++ b/recipes/default/build-fish @@ -2,13 +2,13 @@ log "Compiling and installing fish-shell" -local fish_shell_dir=$WORKSPACE/fish-shell +fish_shell_dir="$WORKSPACE/fish-shell" -if [ ! -d $fish_shell_dir ]; then +if [ ! -d "$fish_shell_dir" ]; then log "Cloning fish-shell" - git clone https://github.com/fish-shell/fish-shell $fish_shell_dir + git clone https://github.com/fish-shell/fish-shell "$fish_shell_dir" else - (cd $fish_shell_dir && git pull) + (cd "$fish_shell_dir" && git pull) fi -(cd $fish_shell_dir && ./configure && make && sudo make install) +(cd "$fish_shell_dir" && ./configure && make && sudo make install) diff --git a/recipes/default/build-neovim b/recipes/default/build-neovim old mode 100644 new mode 100755 index f5b27e9..f081dff --- a/recipes/default/build-neovim +++ b/recipes/default/build-neovim @@ -22,13 +22,13 @@ if command_exist pip3 ; then sudo pip3 install neovim fi -local neovim_dir=$WORKSPACE/neovim +neovim_dir="$WORKSPACE/neovim" -if [ ! -d $neovim_dir ]; then +if [ ! -d "$neovim_dir" ]; then log "Cloning neovim" - git clone https://github.com/neovim/neovim $neovim_dir + git clone https://github.com/neovim/neovim "$neovim_dir" else - (cd $neovim_dir && git fetch) + (cd "$neovim_dir" && git fetch) fi -(cd $neovim_dir && git checkout stable && make && sudo make install) +(cd "$neovim_dir" && git checkout stable && make && sudo make install) diff --git a/recipes/default/build-vim b/recipes/default/build-vim old mode 100644 new mode 100755 index 5c612f6..a010c7e --- a/recipes/default/build-vim +++ b/recipes/default/build-vim @@ -1,6 +1,6 @@ #!/bin/bash -local vim_dir="$WORKSPACE/vim" +vim_dir="$WORKSPACE/vim" # Get the build dependencies if [ "$PACKAGE_MANAGER" == 'apt-get' ]; then @@ -9,17 +9,17 @@ fi # TODO: Add pacman support # Build latest vim -if [ ! -d $vim_dir ]; then +if [ ! -d "$vim_dir" ]; then log "Cloning vim" - git clone https://github.com/vim/vim.git $vim_dir + git clone https://github.com/vim/vim.git "$vim_dir" else - (cd $vim_dir && git fetch) + (cd "$vim_dir" && git fetch) fi function conf_build_and_install() { # Get latest tagged source code - latest_tag=`git describe --tags` - git checkout $latest_tag + latest_tag=$(git describe --tags) + git checkout "$latest_tag" # Configure vim with ruby, python and GTK ./configure --with-features=huge \ @@ -32,8 +32,8 @@ function conf_build_and_install() { # Install newly compiled vim sudo make install # Link vi to vim out of convenience - vim_path=$(which vim) - sudo ln -s $vim_path ${vim_path:0:(-1)} + vim_path=$(command -v vim) + sudo ln -s "$vim_path" "${vim_path:0:(-1)}" } (cd $vim_dir && conf_build_and_install) diff --git a/recipes/default/dotfiles b/recipes/default/dotfiles old mode 100644 new mode 100755 diff --git a/recipes/default/fish b/recipes/default/fish old mode 100644 new mode 100755 index ab98849..818e8c5 --- a/recipes/default/fish +++ b/recipes/default/fish @@ -1,8 +1,10 @@ #! /bin/bash -mkdir -p $XDG_CONFIG_HOME/fish -touch $XDG_CONFIG_HOME/fish/config.fish +# Link and add source all synced fish configs -try_link $DEFAULT_ASSETS_PATH $XDG_CONFIG_HOME/fish/synced -add_line "set -gx fish_synced_dir $XDG_CONFIG_HOME/fish/synced " $XDG_CONFIG_HOME/fish/config.fish -add_line "source $XDG_CONFIG_HOME/fish/synced/init.fish " $XDG_CONFIG_HOME/fish/config.fish +mkdir -p "$XDG_CONFIG_HOME/fish" +touch "$XDG_CONFIG_HOME/fish/config.fish" + +try_link "$DEFAULT_ASSETS_PATH" "$XDG_CONFIG_HOME/fish/synced" +add_line "set -gx fish_synced_dir $XDG_CONFIG_HOME/fish/synced " "$XDG_CONFIG_HOME/fish/config.fish" +add_line "source $XDG_CONFIG_HOME/fish/synced/init.fish " "$XDG_CONFIG_HOME/fish/config.fish" diff --git a/recipes/default/git b/recipes/default/git old mode 100644 new mode 100755 index cbc3840..2341c07 --- a/recipes/default/git +++ b/recipes/default/git @@ -10,6 +10,6 @@ git config --global diff.tool vimdiff # Suppress launching prompt git config --global difftool.prompt false # Create global ignore file -mkdir -p $XDG_CONFIG_HOME/git/ +mkdir -p "$XDG_CONFIG_HOME/git/" git config --global core.excludesfile "$XDG_CONFIG_HOME/git/exclude_global" try_link "exclude_global" "$XDG_CONFIG_HOME/git/exclude_global" diff --git a/recipes/default/golang b/recipes/default/golang index e395177..0c6837d 100644 --- a/recipes/default/golang +++ b/recipes/default/golang @@ -1,12 +1,13 @@ #!/bin/bash -version="1.5.1" +# Installs golang from the web +version="1.13.3" if [[ "$UNAME_STR" == "Darwin" ]]; then - wget -P $TMP_DIR/ http://golang.org/dl/go${version}.darwin-amd64-osx10.8.pkg - installer -pkg $TMP_DIR/go${version}.darwin-amd64-osx10.8.pkg + wget -P "$TMP_DIR/" "http://golang.org/dl/go${version}.darwin-amd64-osx10.8.pkg" + installer -pkg "$TMP_DIR/go${version}.darwin-amd64-osx10.8.pkg" elif [[ "$UNAME_STR" == "Linux" ]]; then - wget -P $TMP_DIR/ http://golang.org/dl/go${version}.linux-amd64.tar.gz + wget -P "$TMP_DIR/" "http://golang.org/dl/go${version}.linux-amd64.tar.gz" # Do something echo "**** Install from $TMP_DIR/go${version}.linux-amd64.tar.gz" fi diff --git a/recipes/default/mac-bin b/recipes/default/mac-bin old mode 100644 new mode 100755 index ba78b64..49320da --- a/recipes/default/mac-bin +++ b/recipes/default/mac-bin @@ -1,6 +1,8 @@ #! /bin/bash -for f in $DEFAULT_ASSETS_PATH/* ; do - try_link "$f" "$USER_BIN/$(basename $f)" +# Try to link all local bin assets specific to macOS + +for f in "$DEFAULT_ASSETS_PATH"/* ; do + try_link "$f" "$USER_BIN/$(basename "$f")" done diff --git a/recipes/default/packages b/recipes/default/packages index b46a80e..72de2cb 100755 --- a/recipes/default/packages +++ b/recipes/default/packages @@ -1,12 +1,14 @@ #! /bin/bash sudo_package_update -packages="tmux htop curl wget mercurial ctags tig pv jq fish mosh bash-completion doxygen shellcheck" # This now installs a lot of language specific stuff from python, gradle, to go. # Should consider pulling these into different recipes that are dependent on the environment # that I wish to bootstrap. If not a dev environment, I can trim out some of this. +# Packages that are pretty much the same treatment or names in all systems +packages="tmux htop curl wget mercurial ctags tig pv jq fish mosh bash-completion doxygen shellcheck" + # Manager specific packages case "$PACKAGE_MANAGER" in "port") @@ -23,11 +25,11 @@ case "$PACKAGE_MANAGER" in packages="$packages git +bash_completion" # Neovim with python plugins packages="$packages neovim py-neovim py27-neovim py37-neovim" - - # Install packages - sudo_package $packages - - # Select defaults + + # Install packages + sudo_package "$packages" + + # Select defaults sudo port select --set python python27 sudo port select --set python2 python27 sudo port select --set python3 python37 @@ -35,10 +37,12 @@ case "$PACKAGE_MANAGER" in sudo port select --set ipython2 py27-ipython sudo port select --set ipython3 py37-ipython sudo port select --set pip pip27 - sudo port select --set tox tox27 - sudo port select --set flake8 flake8-27 - sudo port select --set virtualenv virtualenv27 - try_link $(which pip-3.7) "$USER_BIN/pip3" + sudo port select --set pip2 pip27 + sudo port select --set pip3 pip37 + # Use py3 versions for utilities + sudo port select --set tox tox37 + sudo port select --set flake8 flake8-37 + sudo port select --set virtualenv virtualenv37 ;; "apt-get") if [ -n "$(apt-cache policy silversearcher-ag)" ] ; then @@ -50,9 +54,9 @@ case "$PACKAGE_MANAGER" in # Python packages packages="$packages python python-ipython python-pip python-six python-tox python-flake8 python-virtualenv" packages="$packages python3 python3-ipython python3-pip python3-six python3-flake8 python3-virtualenv python3-venv" - # No python3-tox for ubuntu - sudo pip3 install tox - - sudo_package $packages + # No python3-tox for ubuntu + sudo pip3 install tox + + sudo_package "$packages" ;; esac diff --git a/recipes/default/salesforce b/recipes/default/salesforce old mode 100644 new mode 100755 index 1d1eaba..d7c797e --- a/recipes/default/salesforce +++ b/recipes/default/salesforce @@ -18,7 +18,7 @@ if $install_fcli ; then recipe 'force-cli' fi -for f in $DEFAULT_ASSETS_PATH/* ; do - try_link "$f" "$USER_BIN/$(basename $f)" +for f in "$DEFAULT_ASSETS_PATH"/* ; do + try_link "$f" "$USER_BIN/$(basename "$f")" done diff --git a/recipes/default/vim-settings b/recipes/default/vim-settings old mode 100644 new mode 100755 index 2615785..3bed941 --- a/recipes/default/vim-settings +++ b/recipes/default/vim-settings @@ -1,12 +1,12 @@ #! /bin/bash -VIM_SETTINGS_DIR=$WORKSPACE/vim-settings +vim_settings_dir="$WORKSPACE/vim-settings" # Clone vundle if not done already -if [ ! -d $VIM_SETTINGS_DIR ]; then +if [ ! -d "$vim_settings_dir" ]; then log "Cloning vim-settings" - git clone https://github.com/ViViDboarder/vim-settings $VIM_SETTINGS_DIR - (cd $VIM_SETTINGS_DIR && ./vim-sync-append.sh) + git clone https://github.com/ViViDboarder/vim-settings "$vim_settings_dir" + (cd "$vim_settings_dir" && ./vim-sync-append.sh) else log "Updating vim-settings" - (cd $VIM_SETTINGS_DIR && git pull) + (cd "$vim_settings_dir" && git pull) fi