From 9f6cb2e72eeb5b99d0251bdf7d697012c9674217 Mon Sep 17 00:00:00 2001 From: Bruno 21 Date: Wed, 30 Dec 2020 08:21:46 +0100 Subject: [PATCH] New installer Features: +when update, disabled plugins stay disabled +if new install, choice to disable some plugins --- install.sh | 66 +++++++++++++++-- plugins.d/conda.sh | 69 ++++++++++++++++++ plugins.d/gem.sh | 42 +++++++++++ plugins.d/{_installed.sh => installed.sh} | 88 +++++++++++++++-------- plugins.d/perl.sh | 72 +++++++++++++++++++ plugins.d/perlbrew.sh | 80 +++++++++++++++++++++ plugins.d/{_wp.sh => wp.sh} | 0 7 files changed, 381 insertions(+), 36 deletions(-) create mode 100755 plugins.d/conda.sh create mode 100755 plugins.d/gem.sh rename plugins.d/{_installed.sh => installed.sh} (71%) create mode 100755 plugins.d/perl.sh create mode 100755 plugins.d/perlbrew.sh rename plugins.d/{_wp.sh => wp.sh} (100%) diff --git a/install.sh b/install.sh index 0f121e5..f75acb6 100755 --- a/install.sh +++ b/install.sh @@ -1,14 +1,70 @@ #!/usr/bin/env bash +italic="\033[3m" +underline="\033[4m" +bold="\033[1m" +reset="\033[0m" + KYMSU_PATH=`pwd` # Make Kymsu accessible in PATH +echo -e "Installing ${bold}kymsu2${reset} in ${bold}/usr/local/bin${reset} ..." ln -fs "${KYMSU_PATH}"/kymsu2.sh /usr/local/bin/kymsu2 # Store Kymsu stuff in home directory -mkdir -p ~/.kymsu && echo "${KYMSU_PATH}" > ~/.kymsu/path -cp -R "${KYMSU_PATH}/plugins.d" ~/.kymsu +mkdir -p $HOME/.kymsu && echo "${KYMSU_PATH}" > $HOME/.kymsu/path -echo "altKYMSU has been installed. Run kymsu2 command!" -echo "It's a fork from https://github.com/welcoMattic/kymsu" -echo "All credits to welcoMattic" +pluginpath=$HOME/.kymsu/plugins.d/ + +if [ ! -d $pluginpath ]; then new_install=true; fi + +# Backup disabled plugins +disabled=$(ls $pluginpath | grep ^_ | sed 's/^_//') + +# Delete plugins folder +rm -rf $pluginpath + +# Install new plugins +echo -e "Copying plugins in ${bold}$pluginpath${reset} ..." +cp -R "${KYMSU_PATH}/plugins.d" $HOME/.kymsu + +if [ -n "$disabled" ]; then + + echo -e "Disabling previous disabled plugins ..." + # Disable previous disabled plugins + for i in $(ls $pluginpath) + do + [[ $disabled =~ $i ]] && mv "$pluginpath$i" "$pluginpath"_"$i" + done + +fi + +echo -e "\n${bold}altKYMSU${reset} has been installed. Run ${bold}kymsu2${reset} command!" +echo -e "It's a fork from ${italic}https://github.com/welcoMattic/kymsu${reset}" +echo -e "All credits to ${underline}welcoMattic${reset}\n" + +# If NEW install, we choose to desactivate some plugins +if [ "$new_install" = true ]; then + read -p "Do you want to activate / deactivate some plugins ? [y/n]" deactivate + echo "" + + if [[ "$deactivate" == "y" || "$deactivate" == "Y" ]]; then + + for i in $(ls $pluginpath) + do + + if [[ ${i: -3} == ".sh" ]] && [[ ! ${i:0:2} == "00" ]] && [[ ! ${i:0:1} == "_" ]]; then + + a=$(echo -e "Do you want to deactivate ${bold}$i${reset} plugins ? [y/n]") + read -p "$a" rep + + if [[ "$rep" == "y" || "$rep" == "Y" ]]; then + mv "$pluginpath$i" "$pluginpath"_"$i" && echo -e "${bold}$i${reset} deactivated !" + fi + + fi + + done + + fi +fi \ No newline at end of file diff --git a/plugins.d/conda.sh b/plugins.d/conda.sh new file mode 100755 index 0000000..f12296a --- /dev/null +++ b/plugins.d/conda.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash + +# conda plugin for KYMSU +# https://github.com/welcoMattic/kymsu + +# If you'd prefer that conda's base environment not be activated on startup, set the auto_activate_base parameter to false: +# conda config --set auto_activate_base false + +# In order to initialize after the installation process is done, +# first run source /bin/activate and then run conda init. + + +# Update conda + +echo -e "\033[1m๐ŸฆŽ conda \033[0m" + +path_to_conda=$(conda config --show | grep 'root_prefix' | awk '{print $2}') + +cd $path_to_conda +#conda update conda +# conda update -n base -c defaults conda +#upd=$(conda update --all) +#echo $upd + +#avail_update=$(echo $upd | grep '$ conda update -n base -c defaults conda') +#avail_update=$(conda update --all | grep '$ conda update -n base -c defaults conda') +#avail_update=$(conda update --all) +conda update --all + + +avail_update="$(conda update --all 2>&1 > /dev/null)" + + +# Proceed ([y]/n)? n + +echo "---" + +if echo "$avail_update" | grep -q "$ conda update -n base -c defaults conda" +then + echo "need update" +fi + +echo "" + + + +# If you want to update to a newer version of Anaconda, type: +# +# $ conda update --prefix /Users/bruno/miniconda3 anaconda + + +# Initialisation + +# source $HOME/miniconda3/bin/activate +# source $path_to_conda/bin/activate +# conda init + + +# Configuration + +#conda config --help +#conda config --set auto_update_conda False + + +# Packages installรฉs dans l'environnement conda + +echo -e "\033[4mInstalled packages in conda environment:\033[0m" +echo "" +conda list \ No newline at end of file diff --git a/plugins.d/gem.sh b/plugins.d/gem.sh new file mode 100755 index 0000000..ae5d1e3 --- /dev/null +++ b/plugins.d/gem.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +# gem plugin for KYMSU (install local package) +# https://github.com/welcoMattic/kymsu +# https://guides.rubygems.org/what-is-a-gem/ + +# No distract mode +no_distract=false + +if [[ $1 == "--nodistract" ]]; then + no_distract=true +fi + +echo -e "\033[1m ๐Ÿ’ Gem (Ruby) \033[0m" + +echo "" + +gem_outdated=$(gem outdated --local) +upd=$(echo "$gem_outdated" | awk '{print $1}') + +if [ -n "$upd" ]; then + nb=$(echo "$upd" | wc -w | xargs) + + echo -e "\\033[1;41m $nb \033[0m \033[4mavailables updates:\033[0m" + echo "$gem_outdated" + echo "" + + for i in $upd + do + + if [ "$no_distract" = false ]; then + echo "$i" | xargs -n 1 gem info + echo "$i" | xargs -p -n 1 gem update + echo -e "\n" + else + echo "$i" | xargs -n 1 gem update + echo -e "\n" + fi + done +else + echo -e "\033[4mNo gem updates.\033[0m" +fi diff --git a/plugins.d/_installed.sh b/plugins.d/installed.sh similarity index 71% rename from plugins.d/_installed.sh rename to plugins.d/installed.sh index 19d4fc6..00b5784 100755 --- a/plugins.d/_installed.sh +++ b/plugins.d/installed.sh @@ -8,12 +8,17 @@ # npm local install local_path=/Users/bruno/Sites/node_modules/ -chemin=$(pwd) +# folder contains Brewfile and Installer.md +#chemin=$(pwd) +chemin=$HOME/Documents/kymsu #version: pip ou pip3 pip_version=pip3 # ######################################### +#if [ ! -d chemin ]; then mkdir $chemin; fi +mkdir -p $chemin + now=$(date +"%d-%m-%Y_%T") mac=$(hostname -s) file=$mac"@"$now @@ -23,19 +28,19 @@ echo -e "\033[1m๐Ÿ›  Installed \033[0m" echo '' -Installed=$(find . -name 'Installed*.md' -maxdepth 1) +Installed=$(find $chemin -name 'Installed*.md' -maxdepth 1) if [ -n "$Installed" ]; then echo -e "A file \033[93mInstalled*.md\033[0m already exist! We remove it." a=$(echo "$Installed" | xargs rm) fi -if [ -f Brewfile ]; then +if [ -f $chemin/Brewfile ]; then echo -e "The \033[93mBrewfile\033[0m already exist! We rename it." - find . -name 'Brewfile_*' -maxdepth 1 -print0 | xargs rm - d=$(date -r Brewfile "+%d-%m-%Y_%H:%M:%S") + find $chemin -name 'Brewfile_*' -maxdepth 1 -print0 | xargs rm + d=$(date -r $chemin/Brewfile "+%d-%m-%Y_%H:%M:%S") - mv Brewfile "Brewfile_$mac@$d" + mv "$chemin/Brewfile" "$chemin/Brewfile_$mac@$d" fi { @@ -50,11 +55,11 @@ echo '' echo '## ๐Ÿบ Homebrew' echo '' -} >> Installed.md +} >> $chemin/Installed.md echo -e "๐Ÿบ Get Homebrew \033[3m\033[93mtap\033[0m list" -echo '### Tap:' >> Installed.md +echo '### Tap:' >> $chemin/Installed.md tap=$(brew tap) { echo "\`\`\`bash" @@ -62,49 +67,49 @@ echo "$tap" echo "\`\`\`" echo "" echo '' -} >> Installed.md +} >> $chemin/Installed.md echo -e "๐Ÿบ Get Homebrew \033[3m\033[93mpackages\033[0m installed list" -echo '### Packages:' >> Installed.md -brew=$(brew list) +echo '### Packages:' >> $chemin/Installed.md +brew=$(brew list --formula) { echo "\`\`\`bash" echo "$brew" echo "\`\`\`" echo "" echo '' -} >> Installed.md +} >> $chemin/Installed.md echo -e "๐Ÿบ Get Homebrew \033[3m\033[93mCask\033[0m installed list" -echo '### Casks:' >> Installed.md -cask=$(brew cask list) +echo '### Casks:' >> $chemin/Installed.md +cask=$(brew list --cask) { echo "\`\`\`bash" echo "$cask" echo "\`\`\`" echo "" echo '' -} >> Installed.md +} >> $chemin/Installed.md # liste des apps de l'Appstore installรฉes (nom & numรฉro) echo -e "๐Ÿ Get mas \033[3m\033[93mApp Store applications\033[0m list" -echo '## ๐Ÿ mas (Mac App Store)' >> Installed.md -echo '' >> Installed.md +echo '## ๐Ÿ mas (Mac App Store)' >> $chemin/Installed.md +echo '' >> $chemin/Installed.md appfrommas=$(mas list | sort -k2) #echo "$appfrommas" #declare -a appstore -echo "\`\`\`bash" >> Installed.md +echo "\`\`\`bash" >> $chemin/Installed.md # todo: trier la liste par nom while read -r line; do number=$(echo "$line" | awk '{print $1}') #name=$(echo "$line" | awk -F "(" '{print $1}' | awk {'first = $1; $1=""; print $0'} | sed 's/^ //g') name=$(echo "$line" | awk -F "(" '{print $1}' | awk '{first = $1; $1=""; print $0}' | sed 's/^ //g') - echo "$name ($number)" >> Installed.md + echo "$name ($number)" >> $chemin/Installed.md #echo " " >> Installed.md #appstore["$name"]="${number}" done <<< "$appfrommas" @@ -112,14 +117,14 @@ done <<< "$appfrommas" echo "\`\`\`" echo "" echo '' -} >> Installed.md +} >> $chemin/Installed.md # Extensions PHP PECL echo -e "๐Ÿ˜ Get PECL \033[3m\033[93mPHP extensions\033[0m list" -echo '## ๐Ÿ˜ PECL extensions' >> Installed.md -echo '' >> Installed.md +echo '## ๐Ÿ˜ PECL extensions' >> $chemin/Installed.md +echo '' >> $chemin/Installed.md ext_pecl=$(pecl list | sed '1,3d' | awk '{print $1}') { @@ -128,13 +133,13 @@ echo "$ext_pecl" echo "\`\`\`" echo "" echo '' -} >> Installed.md +} >> $chemin/Installed.md # Python packages (pip) echo -e "๐Ÿ Get pip \033[3m\033[93mPython 3 packages\033[0m installed list" -echo '## ๐Ÿ Python packages' >> Installed.md -echo '' >> Installed.md +echo '## ๐Ÿ Python packages' >> $chemin/Installed.md +echo '' >> $chemin/Installed.md pip_packages=$($pip_version list | sed '1,2d' | awk '{print $1}') { @@ -143,7 +148,7 @@ echo "$pip_packages" echo "\`\`\`" echo "" echo '' -} >> Installed.md +} >> $chemin/Installed.md # atom @@ -163,7 +168,7 @@ done <<< "$atom" echo "\`\`\`" echo "" echo '' -} >> Installed.md +} >> $chemin/Installed.md # Node.js packages (npm) @@ -179,7 +184,7 @@ echo '### Global:' echo "\`\`\`bash" echo "$pkg_global_npm" echo "\`\`\`" -} >> Installed.md +} >> $chemin/Installed.md if [ -d "$local_path" ]; then cd "$local_path" || exit @@ -202,7 +207,26 @@ if [ -d "$local_path" ]; then cd "$chemin" || exit fi -echo "" >> Installed.md +echo "" >> $chemin/Installed.md + +# gem + +echo -e "๐Ÿ’ Get \033[3m\033[93mgem\033[0m installed list" +gems=$(gem list --no-versions) +{ +echo '## ๐Ÿ’ Gem packages' +echo '' +echo "\`\`\`bash" + +while read -r line; do + a=$(echo "$line") + echo "$a" +done <<< "$gems" + +echo "\`\`\`" +echo "" +echo '' +} >> $chemin/Installed.md echo '' @@ -215,10 +239,12 @@ echo '' echo -e "To restore everything listed in that file, run \033[3m\033[93m'$ brew bundle'\033[0m in folder that contains the Brewfile." echo '' +mv Brewfile "$chemin/Brewfile" + #iconv -f macroman -t utf-8 Installed.md > Installed-utf8.md #mv Installed-utf8.md "$filename".md #rm Installed.md -mv Installed.md "$filename".md +mv $chemin/Installed.md "$chemin/$filename".md -open "$filename".md +open "$chemin/$filename".md diff --git a/plugins.d/perl.sh b/plugins.d/perl.sh new file mode 100755 index 0000000..b7268c2 --- /dev/null +++ b/plugins.d/perl.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +# Display info on updated pakages +display_info=true + +# Also add module for prevent to update it. +declare -a do_not_update=('') + + +perl_app=$(which perl) +perl_v=$(perl -v | sed -n '2p') + +echo -e "\033[4mPerl:\033[0m $perl_app" +echo -e "\033[4mVersion:\033[0m $perl_v" +echo "" + +module="App::cpanoutdate" +if ! perl -M$module -e 1 2>/dev/null; then + echo -e "\033[4mRequierement:\033[0m module $module is not installed" + + a=$(echo -e "Do you wanna run \033[1mcpan -i "$module"\033[0m ? (y/n)") + read -p "$a" choice + if [ "$choice" == "y" ]; then + #cpan -i $module + install_ok=true + else + echo "Bye" + exit + fi + +else + echo "$module installed" + install_ok=true +fi + +if [ "$install_ok" == "true" ]; then + echo "$module installed" + + # install with cpan + # % cpan-outdated | xargs cpan -i + + # install with cpanm + # % cpan-outdated | cpanm + # % cpan-outdated -p | cpanm + + outdated=$(cpan-outdated -p) + nb=$(echo $outdated | wc -w) + + a=$(echo -e "Do you wanna update\033[1m "$nb" outdated\033[0m modules ? (y/n)") + read -p "$a" choice + + if [ "$choice" == "y" ]; then + + for i in $outdated + do + FOUND=`echo ${do_not_update[*]} | grep "$i"` + if [ "${FOUND}" = "" ]; then + echo "" + if [ "$display_info" = true ]; then + cpan -D "$i" + fi + echo -e "\033[1m" + echo "$i" | awk '{print $1}' | xargs -p -n 1 cpan -i + echo -e "\033[0m" + #echo "" + fi + done + else + echo "Bye" + exit + fi +fi \ No newline at end of file diff --git a/plugins.d/perlbrew.sh b/plugins.d/perlbrew.sh new file mode 100755 index 0000000..a3cf662 --- /dev/null +++ b/plugins.d/perlbrew.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash + +#Display useful information about the perlbrew installation. +#If a module is given the version and location of the module is displayed. +perlbrew info + +< +# https://github.com/perl11/cperl +perlbrew install [options] cperl- + + Options for "install" command: + + -f --force Force installation + -j $n Parallel building and testing. ex. C + -n --notest Skip testing + + --switch Automatically switch to this Perl once successfully + installed, as if with `perlbrew switch ` + + --as Install the given version of perl by a name. + ex. C + + --noman Skip installation of manpages + + --thread Build perl with usethreads enabled + --multi Build perl with usemultiplicity enabled + --64int Build perl with use64bitint enabled + --64all Build perl with use64bitall enabled + --ld Build perl with uselongdouble enabled + --debug Build perl with DEBUGGING enabled + --clang Build perl using the clang compiler + --no-patchperl + Skip calling patchperl + + -D,-U,-A Switches passed to perl Configure script. + ex. C + + --destdir $path + Install perl as per 'make install DESTDIR=$path' + + --sitecustomize $filename + Specify a file to be installed as sitecustomize.pl + + # Uninstalls the given perl installation. +perlbrew uninstall + +COMMENT diff --git a/plugins.d/_wp.sh b/plugins.d/wp.sh similarity index 100% rename from plugins.d/_wp.sh rename to plugins.d/wp.sh