Update packages to install multiple packages and a bunch of linting updates

This commit is contained in:
ViViDboarder 2019-11-12 17:59:41 -08:00
parent 72d5ffaa4f
commit f9fa0ba17d
14 changed files with 95 additions and 149 deletions

View File

@ -4,7 +4,7 @@
# DO NOT MODIFY THIS FILE. Instead, modify 'helpers/custom'. # DO NOT MODIFY THIS FILE. Instead, modify 'helpers/custom'.
############################################################################## ##############################################################################
COOKBOOK_NAME="$(basename $0)" COOKBOOK_NAME="$(basename "$0")"
if [ -z "$SHOESTRAP_BASE" ]; then if [ -z "$SHOESTRAP_BASE" ]; then
DIR="$( cd "$( dirname "$0" )" && pwd )" DIR="$( cd "$( dirname "$0" )" && pwd )"
else else
@ -24,19 +24,19 @@ recipe () {
local default_recipe="$DIR/recipes/default/$CURRENT_RECIPE_NAME" local default_recipe="$DIR/recipes/default/$CURRENT_RECIPE_NAME"
local cookbook_recipe="$DIR/recipes/$COOKBOOK_NAME/$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 log "Running recipe '$cookbook_recipe'..." 1
separator separator
. $cookbook_recipe . "$cookbook_recipe"
elif [ -f $default_recipe ]; then elif [ -f "$default_recipe" ]; then
log "Running recipe '$default_recipe'..." 1 log "Running recipe '$default_recipe'..." 1
separator separator
. $default_recipe . "$default_recipe"
else else
error "Could not find recipe for '$CURRENT_RECIPE_NAME'. Fail!" error "Could not find recipe for '$CURRENT_RECIPE_NAME'. Fail!"
fi fi
cd $DIR cd "$DIR" || error "Failed to find recipe"
} }
# #
@ -61,13 +61,13 @@ finished () {
# #
log () { log () {
if [[ $2 -gt 0 ]]; then if [[ $2 -gt 0 ]]; then
spacer $2 spacer "$2"
fi fi
echo " * $1" echo " * $1"
if [[ $3 -gt 0 ]]; then if [[ $3 -gt 0 ]]; then
spacer $3 spacer "$3"
fi fi
} }
@ -91,7 +91,7 @@ spacer () {
local spaces=1 local spaces=1
fi fi
for (( i=0; i<$spaces; i++ )) do for (( i=0; i<spaces; i++ )) do
echo "" echo ""
done done
} }
@ -115,41 +115,18 @@ separator () {
local char='-' local char='-'
fi fi
local width=$(tput cols) local width=""
width=$(tput cols)
for (( i=0; i < $width-2; i++ )) do for (( i=0; i < width-2; i++ )) do
local output="$output$char" local output="$output$char"
done done
echo $output echo "$output"
} }
# #
# Update packages in package manager. # Update packages in package manager.
# #
package_update () {
log "Updating package manager..." 0 1
detect_package_manager
if [ "$PACKAGE_MANAGER" == 'apt-get' ]; then
apt-get update -y
elif [ "$PACKAGE_MANAGER" == 'yum' ]; then
yum check-update -y
elif [ "$PACKAGE_MANAGER" == 'port' ]; then
port selfupdate
elif [ "$PACKAGE_MANAGER" == 'brew' ]; then
brew update
else
error "Unknown package manager: $PACKAGE_MANAGER"
fi
if [ $? -ne 0 ]; then
error "An error occured while updating packages. Fail!"
else
spacer 2
fi
}
sudo_package_update () { sudo_package_update () {
log "Updating package manager..." 0 1 log "Updating package manager..." 0 1
detect_package_manager detect_package_manager
@ -174,66 +151,27 @@ sudo_package_update () {
} }
# #
# Install a package through package manager # Install a package or packages through package manager
# #
package () {
log "Installing package '$1'..."
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 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 () { sudo_package () {
log "Installing package '$1'..." log "Installing packages '$*'..."
detect_package_manager 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 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 elif [ "$PACKAGE_MANAGER" == 'yum' ]; then
sudo yum install -y $1 sudo yum install -y $*
elif [ "$PACKAGE_MANAGER" == 'port' ]; then elif [ "$PACKAGE_MANAGER" == 'port' ]; then
# Unintuitive, but this skips all promps which should assume Y # Unintuitive, but this skips all promps which should assume Y
sudo port -N install $1 sudo port -N install $*
elif [ "$PACKAGE_MANAGER" == 'brew' ]; then elif [ "$PACKAGE_MANAGER" == 'brew' ]; then
brew install $1 brew install $*
else else
error "Unknown package manager: $PACKAGE_MANAGER" error "Unknown package manager: $PACKAGE_MANAGER"
fi fi
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
error "An error occured while installing package '$1'. Fail!" error "An error occured while installing packages. Fail!"
else else
spacer 2 spacer 2
fi fi
@ -354,17 +292,17 @@ try_link () {
src="$src" src="$src"
elif [ -f "$cookbook_assets_source" ]; then elif [ -f "$cookbook_assets_source" ]; then
src="$cookbook_assets_source" src="$cookbook_assets_source"
elif [ -f $default_assets_source ]; then elif [ -f "$default_assets_source" ]; then
src="$default_assets_source" src="$default_assets_source"
elif [ -d "$cookbook_assets_source" ]; then elif [ -d "$cookbook_assets_source" ]; then
src="$cookbook_assets_source" src="$cookbook_assets_source"
elif [ -d $default_assets_source ]; then elif [ -d "$default_assets_source" ]; then
src="$default_assets_source" src="$default_assets_source"
else else
error "Could not find '$1' to link Fail!" error "Could not find '$1' to link Fail!"
fi fi
if [ -L "$2" ] && [ "$(readlink $2)" == "$src" ] ; then if [ -L "$2" ] && [ "$(readlink "$2")" == "$src" ] ; then
log "Link already exists: $2" log "Link already exists: $2"
else else
log "Creating link: $2 -> $src" log "Creating link: $2 -> $src"
@ -380,18 +318,16 @@ add_user () {
local pass=$2 local pass=$2
local args=$3 local args=$3
id $user > /dev/null 2>&1 if id "$user" > /dev/null 2>&1 ; then
if [ $? -eq 0 ]; then
log "User $user already exists. Skipped creation." log "User $user already exists. Skipped creation."
else else
log "Adding user $user..." log "Adding user $user..."
[ "$pass" == "" ] && pass=generate_password [ "$pass" == "" ] && pass=generate_password
if [[ "$args" != *nohome* ]]; then 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 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
fi fi
} }
@ -415,7 +351,7 @@ run_as () {
log "$cmd" log "$cmd"
# sudo -u $user -H -s /bin/bash -c "$cmd" # sudo -u $user -H -s /bin/bash -c "$cmd"
# sudo -u $user -s /bin/bash -i "$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. # Write a warning if user is not root.
# #
warn_if_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..."; } { 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. # Stops the execution of the script if user is not root.
# #
fail_if_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; } { echo "You must run this as 'root'. Exiting."; exit 1; }
} }
@ -473,8 +409,8 @@ set_installed () {
local args=$* local args=$*
local name=${args//[ \/:@]/-} local name=${args//[ \/:@]/-}
mkdir -p ~/.shoestrap/installed mkdir -p "$HOME/.shoestrap/installed"
touch ~/.shoestrap/installed/$name touch "$HOME/.shoestrap/installed/$name"
} }
# #

View File

@ -8,7 +8,7 @@
############################################################## ##############################################################
# Get current directory for future use in links # 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) PROJECT_DIR=$(pwd)
detect_package_manager detect_package_manager

5
recipes/default/bin Normal file → Executable file
View File

@ -1,6 +1,7 @@
#! /bin/bash #! /bin/bash
for f in $DEFAULT_ASSETS_PATH/* ; do # Link all user specific scripts to user bin
try_link "$f" "$USER_BIN/$(basename $f)" for f in "$DEFAULT_ASSETS_PATH"/* ; do
try_link "$f" "$USER_BIN/$(basename "$f")"
done done

10
recipes/default/build-fish Normal file → Executable file
View File

@ -2,13 +2,13 @@
log "Compiling and installing fish-shell" 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" 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 else
(cd $fish_shell_dir && git pull) (cd "$fish_shell_dir" && git pull)
fi fi
(cd $fish_shell_dir && ./configure && make && sudo make install) (cd "$fish_shell_dir" && ./configure && make && sudo make install)

10
recipes/default/build-neovim Normal file → Executable file
View File

@ -22,13 +22,13 @@ if command_exist pip3 ; then
sudo pip3 install neovim sudo pip3 install neovim
fi fi
local neovim_dir=$WORKSPACE/neovim neovim_dir="$WORKSPACE/neovim"
if [ ! -d $neovim_dir ]; then if [ ! -d "$neovim_dir" ]; then
log "Cloning neovim" log "Cloning neovim"
git clone https://github.com/neovim/neovim $neovim_dir git clone https://github.com/neovim/neovim "$neovim_dir"
else else
(cd $neovim_dir && git fetch) (cd "$neovim_dir" && git fetch)
fi fi
(cd $neovim_dir && git checkout stable && make && sudo make install) (cd "$neovim_dir" && git checkout stable && make && sudo make install)

16
recipes/default/build-vim Normal file → Executable file
View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
local vim_dir="$WORKSPACE/vim" vim_dir="$WORKSPACE/vim"
# Get the build dependencies # Get the build dependencies
if [ "$PACKAGE_MANAGER" == 'apt-get' ]; then if [ "$PACKAGE_MANAGER" == 'apt-get' ]; then
@ -9,17 +9,17 @@ fi
# TODO: Add pacman support # TODO: Add pacman support
# Build latest vim # Build latest vim
if [ ! -d $vim_dir ]; then if [ ! -d "$vim_dir" ]; then
log "Cloning vim" log "Cloning vim"
git clone https://github.com/vim/vim.git $vim_dir git clone https://github.com/vim/vim.git "$vim_dir"
else else
(cd $vim_dir && git fetch) (cd "$vim_dir" && git fetch)
fi fi
function conf_build_and_install() { function conf_build_and_install() {
# Get latest tagged source code # Get latest tagged source code
latest_tag=`git describe --tags` latest_tag=$(git describe --tags)
git checkout $latest_tag git checkout "$latest_tag"
# Configure vim with ruby, python and GTK # Configure vim with ruby, python and GTK
./configure --with-features=huge \ ./configure --with-features=huge \
@ -32,8 +32,8 @@ function conf_build_and_install() {
# Install newly compiled vim # Install newly compiled vim
sudo make install sudo make install
# Link vi to vim out of convenience # Link vi to vim out of convenience
vim_path=$(which vim) vim_path=$(command -v vim)
sudo ln -s $vim_path ${vim_path:0:(-1)} sudo ln -s "$vim_path" "${vim_path:0:(-1)}"
} }
(cd $vim_dir && conf_build_and_install) (cd $vim_dir && conf_build_and_install)

0
recipes/default/dotfiles Normal file → Executable file
View File

12
recipes/default/fish Normal file → Executable file
View File

@ -1,8 +1,10 @@
#! /bin/bash #! /bin/bash
mkdir -p $XDG_CONFIG_HOME/fish # Link and add source all synced fish configs
touch $XDG_CONFIG_HOME/fish/config.fish
try_link $DEFAULT_ASSETS_PATH $XDG_CONFIG_HOME/fish/synced mkdir -p "$XDG_CONFIG_HOME/fish"
add_line "set -gx fish_synced_dir $XDG_CONFIG_HOME/fish/synced " $XDG_CONFIG_HOME/fish/config.fish touch "$XDG_CONFIG_HOME/fish/config.fish"
add_line "source $XDG_CONFIG_HOME/fish/synced/init.fish " $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"

2
recipes/default/git Normal file → Executable file
View File

@ -10,6 +10,6 @@ git config --global diff.tool vimdiff
# Suppress launching prompt # Suppress launching prompt
git config --global difftool.prompt false git config --global difftool.prompt false
# Create global ignore file # 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" git config --global core.excludesfile "$XDG_CONFIG_HOME/git/exclude_global"
try_link "exclude_global" "$XDG_CONFIG_HOME/git/exclude_global" try_link "exclude_global" "$XDG_CONFIG_HOME/git/exclude_global"

View File

@ -1,12 +1,13 @@
#!/bin/bash #!/bin/bash
version="1.5.1" # Installs golang from the web
version="1.13.3"
if [[ "$UNAME_STR" == "Darwin" ]]; then if [[ "$UNAME_STR" == "Darwin" ]]; then
wget -P $TMP_DIR/ http://golang.org/dl/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 installer -pkg "$TMP_DIR/go${version}.darwin-amd64-osx10.8.pkg"
elif [[ "$UNAME_STR" == "Linux" ]]; then 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 # Do something
echo "**** Install from $TMP_DIR/go${version}.linux-amd64.tar.gz" echo "**** Install from $TMP_DIR/go${version}.linux-amd64.tar.gz"
fi fi

6
recipes/default/mac-bin Normal file → Executable file
View File

@ -1,6 +1,8 @@
#! /bin/bash #! /bin/bash
for f in $DEFAULT_ASSETS_PATH/* ; do # Try to link all local bin assets specific to macOS
try_link "$f" "$USER_BIN/$(basename $f)"
for f in "$DEFAULT_ASSETS_PATH"/* ; do
try_link "$f" "$USER_BIN/$(basename "$f")"
done done

View File

@ -1,12 +1,14 @@
#! /bin/bash #! /bin/bash
sudo_package_update 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. # 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 # 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. # 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 # Manager specific packages
case "$PACKAGE_MANAGER" in case "$PACKAGE_MANAGER" in
"port") "port")
@ -23,11 +25,11 @@ case "$PACKAGE_MANAGER" in
packages="$packages git +bash_completion" packages="$packages git +bash_completion"
# Neovim with python plugins # Neovim with python plugins
packages="$packages neovim py-neovim py27-neovim py37-neovim" packages="$packages neovim py-neovim py27-neovim py37-neovim"
# Install packages # Install packages
sudo_package $packages sudo_package "$packages"
# Select defaults # Select defaults
sudo port select --set python python27 sudo port select --set python python27
sudo port select --set python2 python27 sudo port select --set python2 python27
sudo port select --set python3 python37 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 ipython2 py27-ipython
sudo port select --set ipython3 py37-ipython sudo port select --set ipython3 py37-ipython
sudo port select --set pip pip27 sudo port select --set pip pip27
sudo port select --set tox tox27 sudo port select --set pip2 pip27
sudo port select --set flake8 flake8-27 sudo port select --set pip3 pip37
sudo port select --set virtualenv virtualenv27 # Use py3 versions for utilities
try_link $(which pip-3.7) "$USER_BIN/pip3" sudo port select --set tox tox37
sudo port select --set flake8 flake8-37
sudo port select --set virtualenv virtualenv37
;; ;;
"apt-get") "apt-get")
if [ -n "$(apt-cache policy silversearcher-ag)" ] ; then if [ -n "$(apt-cache policy silversearcher-ag)" ] ; then
@ -50,9 +54,9 @@ case "$PACKAGE_MANAGER" in
# Python packages # Python packages
packages="$packages python python-ipython python-pip python-six python-tox python-flake8 python-virtualenv" 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" packages="$packages python3 python3-ipython python3-pip python3-six python3-flake8 python3-virtualenv python3-venv"
# No python3-tox for ubuntu # No python3-tox for ubuntu
sudo pip3 install tox sudo pip3 install tox
sudo_package $packages sudo_package "$packages"
;; ;;
esac esac

4
recipes/default/salesforce Normal file → Executable file
View File

@ -18,7 +18,7 @@ if $install_fcli ; then
recipe 'force-cli' recipe 'force-cli'
fi fi
for f in $DEFAULT_ASSETS_PATH/* ; do for f in "$DEFAULT_ASSETS_PATH"/* ; do
try_link "$f" "$USER_BIN/$(basename $f)" try_link "$f" "$USER_BIN/$(basename "$f")"
done done

10
recipes/default/vim-settings Normal file → Executable file
View File

@ -1,12 +1,12 @@
#! /bin/bash #! /bin/bash
VIM_SETTINGS_DIR=$WORKSPACE/vim-settings vim_settings_dir="$WORKSPACE/vim-settings"
# Clone vundle if not done already # Clone vundle if not done already
if [ ! -d $VIM_SETTINGS_DIR ]; then if [ ! -d "$vim_settings_dir" ]; then
log "Cloning vim-settings" log "Cloning vim-settings"
git clone https://github.com/ViViDboarder/vim-settings $VIM_SETTINGS_DIR git clone https://github.com/ViViDboarder/vim-settings "$vim_settings_dir"
(cd $VIM_SETTINGS_DIR && ./vim-sync-append.sh) (cd "$vim_settings_dir" && ./vim-sync-append.sh)
else else
log "Updating vim-settings" log "Updating vim-settings"
(cd $VIM_SETTINGS_DIR && git pull) (cd "$vim_settings_dir" && git pull)
fi fi