From 62d188a135b113b271807159bc38fe0ca04ba855 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 3 Oct 2017 23:53:15 +0200 Subject: [PATCH] autopush by david@ghost --- install.sh | 167 ++++++++++++++++++++++------------------------------- myzsh.sh | 10 +++- 2 files changed, 79 insertions(+), 98 deletions(-) diff --git a/install.sh b/install.sh index 4cafa99..3f745b0 100755 --- a/install.sh +++ b/install.sh @@ -1,108 +1,81 @@ -#!/bin/sh +#!/bin/bash -installdeps() -{ +# +# myzsh installation script +# - #dependencies - readonly deps="git zsh vim curl wget" +#dependencies +readonly deps="git zsh vim curl wget" - #check for dependencies - missingdeps="" - i=0 - for dep in $deps; do - if [ $(command -v $dep > /dev/null; echo $?) -ne "0" ]; then - missingdeps="$missingdeps $dep" - i=$((i+1)) +#check for dependencies +missingdeps="" +i=0 +for dep in $deps; do + if [ $(command -v $dep > /dev/null; echo $?) -ne "0" ]; then + missingdeps="$missingdeps $dep" + i=$((i+1)) + fi +done + +#try to install unmet dependencies +if [ $i -ne 0 ]; then + + #checking for system + echo "[myzsh]: installing missing dependencies ($missingdeps)" + readonly systems="ubuntu arch raspbian solus" + issue="$(cat /etc/issue)" + for item in $systems; do + echo $issue | grep -i $item + if [ $? -eq 0 ]; then + system=$item fi done - #try to install unmet dependencies - if [ $i -ne 0 ]; then + case $system in + ubuntu) + sudo apt-get update && sudo apt-get install -y $missingdeps + ;; + arch) + sudo pacman -Su $missingdeps + ;; + raspbian) + sudo apt-get update && sudo apt-get install -y $missingdeps + ;; + solus) + sudo eopkg update-repo && sudo eopkg install $missingdeps + ;; - #checking for system - readonly systems="ubuntu arch raspbian solus" - issue="$(cat /etc/issue)" - for item in $systems; do - echo $issue | grep -i $item - if [ $? -eq 0 ]; then - system=$item - fi - done + ?) + echo "[myzsh]: i cannot install dependencies. goodbye." + exit 1 + ;; + esac - case $system in - ubuntu) - sudo apt-get update && sudo apt-get install -y $missingdeps - ;; - arch) - sudo pacman -Su $missingdeps - ;; - raspbian) - sudo apt-get update && sudo apt-get install -y $missingdeps - ;; - solus) - sudo eopkg update-repo && sudo eopkg install $missingdeps - ;; - - ?) - echo "[myzsh]: i cannot install dependencies. unknown system." - exit 1 - ;; - esac - - fi - -} - - -installmyzsh() -{ - - rm -rf ~/.myzsh - choice="null" - while [ $choice != "y" ] && [ $choice != "n" ]; do - read -p "[myzsh]: should i clone myzsh writeable? [y/n]" choice - if [ "$choice" == "y" ]; then - git clone git@socialg.it:david/myzsh.git ~/.myzsh - else - git clone https://socialg.it/david/myzsh.git ~/.myzsh - fi - done - echo 'ZSH="$HOME/.myzsh"' > ~/.zshrc - echo 'THEME="david"' >> ~/.zshrc - echo 'plugins=(david)' >> ~/.zshrc - echo 'source $ZSH/myzsh.sh' >> ~/.zshrc - echo "export PATH=$PATH" >> ~/.zshrc - - cat /etc/passwd | grep ~ | grep "/bin/zsh" - #set default shell if not set already - if [ $? -eq 1 ]; then - read -p "[myzsh]: time to change your default shell to /bin/zsh" - sudo vim /etc/passwd - fi - - -} - -#start of script - - -if [ -d ~/.myzsh ]; then - choice="null" - echo "[myzsh]: it seems i have already been set up." - read -p "[myzsh]: should i cleanup & reinstall? [y/n]" choice - if [ "$choice" == "y" ]; then - installdeps - installmyzsh - else - echo "[myzsh]: updating instead." - cd ~/.myzsh - git pull origin master - cd - - fi -else - installdeps - installmyzsh fi -#end of script +#install +echo "[myzsh]: cleaning up previous installations." +rm -rf ~/.myzsh + +echo "[myzsh]: downloading repository." +if [ -r ~/.ssh/id_rsa ]; then + git clone git@socialg.it:david/myzsh.git ~/.myzsh +else + git clone https://socialg.it/david/myzsh.git ~/.myzsh +fi +if [ $? -ne 0 ]; then + echo "[myzsh]: i cannot clone repository. goodbye." + exit 1 +fi + +#config +echo "[myzsh]: setting up config." +echo 'ZSH="$HOME/.myzsh"' > ~/.zshrc +echo 'THEME="david"' >> ~/.zshrc +echo 'plugins=(david)' >> ~/.zshrc +echo 'source $ZSH/myzsh.sh' >> ~/.zshrc +echo "export PATH=$PATH" >> ~/.zshrc + +echo "[myzsh]: successfully installed." + exit 0 diff --git a/myzsh.sh b/myzsh.sh index 66d37a5..0c90b38 100644 --- a/myzsh.sh +++ b/myzsh.sh @@ -3,6 +3,13 @@ # (runs at shell start) # +# check for default shell +cat /etc/passwd | grep ~ | grep "/bin/zsh" > /dev/null +if [ $? -eq 1 ]; then + echo "[myzsh]: you should set me as your default shell." +fi + + # check if there is canges to be pushed cd $ZSH local SUBMODULE_SYNTAX='' @@ -10,7 +17,8 @@ if [[ $POST_1_7_2_GIT -gt 0 ]]; then SUBMODULE_SYNTAX="--ignore-submodules=dirty" fi if [[ -n $(git status -s ${SUBMODULE_SYNTAX} 2> /dev/null) ]]; then - echo -e "[myzsh]: local myzsh repo is dirty. commit and push changes? [y/n] \c" + choice="null" + echo -n "[myzsh]: local myzsh repo is dirty. commit and push changes? [y/n]" read choice if [ $choice = "y" ]; then git add **/*[^lastrun]