From 05aba56f57856373d8476306b607874b737dcb56 Mon Sep 17 00:00:00 2001 From: Thiago Mendonca Date: Sun, 8 Aug 2021 12:44:13 +0200 Subject: [PATCH] feat(tools): move station installation from brew to shell script --- lib/functions | 40 ++++++++++++++++++++++++++++++- scripts/tools.sh | 7 ++++++ tools/linux/station.sh | 2 +- tools/macos/Brewfile | 1 - tools/macos/station.sh | 53 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+), 3 deletions(-) create mode 100755 tools/macos/station.sh diff --git a/lib/functions b/lib/functions index ba1d81d..de155eb 100755 --- a/lib/functions +++ b/lib/functions @@ -77,7 +77,10 @@ install() { ;; snap*) _snapInstall "${otherArguments[@]}" - ;; + ;; + dmg*) + _dmgInstall "${otherArguments[@]}" + ;; *) warn "Unknow Installatin type: '$install_type'" _errorInstall "${otherArguments[@]}" ;; @@ -193,5 +196,40 @@ _appImageInstall() { sudo sh -c "echo 'Categories=Application;' >> /usr/share/applications/$1.desktop" sudo sh -c "echo 'StartupNotify=true' >> /usr/share/applications/$1.desktop" + return 0 +} + +_dmgInstall() { + + if [ -z "$1" ]; then + warn "The name of the tool to install must be informed." + return 1 + fi + + if [ -z "$2" ]; then + warn "To install .dmg files, a URL must be informed, to obtain the .dmg file from" + return 2 + fi + + info "Installing '$1' via DMG, from $2" + + filename="$HOME"/Downloads/"$1".dmg + + wget -O "$filename" "$2" + listing=$(hdiutil attach "$filename" | grep Volumes) + volume=$(echo "$listing" | cut -f 3) + + appFileCount=$(find "$volume" -name "*.app" 2>/dev/null | wc -l) + pkgFileCount=$(find "$volume" -name "*.pkg" 2>/dev/null | wc -l) + if [ "$appFileCount" != 0 ]; then + cp -rf "$volume"/*.app /Applications + elif [ "$pkgFileCount" != 0 ]; then + package=$(find "$volume" -name "*.pkg" | head -1) + installer -pkg "$volume"/"$package" -target / + fi + + hdiutil unmount "$(echo "$listing" | cut -f 1 | awk '{$1=$1};1')" + rm "$filename" + return 0 } \ No newline at end of file diff --git a/scripts/tools.sh b/scripts/tools.sh index 95b8be8..2e3cbb3 100755 --- a/scripts/tools.sh +++ b/scripts/tools.sh @@ -30,6 +30,13 @@ install() { brew tap homebrew/bundle brew bundle -v --file="$DOTFILES_FOLDER"/tools/macos/Brewfile + info "Install other tools" + + for file in $(/bin/ls "$DOTFILES_FOLDER"/tools/macos/*.sh |grep -v AptSetup.sh); do + #shellcheck source=/dev/null + . "$file" + done + elif [[ $OSTYPE == linux* ]] ; then info "Installing tools for Linux" diff --git a/tools/linux/station.sh b/tools/linux/station.sh index 1991712..2d7f7f6 100755 --- a/tools/linux/station.sh +++ b/tools/linux/station.sh @@ -9,7 +9,7 @@ DOTFILES_FOLDER="$(pwd | grep -o '.*dotfiles')" TOOL_NAME=station # Tool extra information -EXTRA_INFO="https://dl.getstation.com/download/linux_64?filetype=AppImage https://avatars2.githubusercontent.com/u/27734877?s=200&v=4" +EXTRA_INFO="https://github.com/getstation/desktop-app/releases/download/v2.0.9/Station-x86_64.AppImage https://avatars2.githubusercontent.com/u/27734877?s=200&v=4" # Install methods by OS OS_METHODS="linux:appImage" diff --git a/tools/macos/Brewfile b/tools/macos/Brewfile index 990c3c4..63344f2 100644 --- a/tools/macos/Brewfile +++ b/tools/macos/Brewfile @@ -73,7 +73,6 @@ cask "google-chrome" cask "microsoft-edge" ## Chats -cask "station" cask "pdf-expert" cask "rectangle" diff --git a/tools/macos/station.sh b/tools/macos/station.sh new file mode 100755 index 0000000..76f16e9 --- /dev/null +++ b/tools/macos/station.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +# dotfiles folder +DOTFILES_FOLDER="$(pwd | grep -o '.*dotfiles')" + +## Variables definitions + +# Tool name +TOOL_NAME=station + +# Tool extra information +EXTRA_INFO="https://github.com/getstation/desktop-app/releases/download/v2.0.9/Station.dmg" + +# Install methods by OS +OS_METHODS="darwin:dmg" + +## Pre-installation required steps +preInstall() { + info "Pre Install for $1" +} + +## Post-installation required steps +postInstall() { + info "Post Install for $1" +} + +## Installation exeution. +## No need to change from this line on + +execute() { + # Pre install steps + preInstall "$TOOL_NAME" + + # Install tool + install "$OS_METHODS" $TOOL_NAME "$EXTRA_INFO" + + # Post install steps + postInstall "$TOOL_NAME" +} + +_is_func_imported() { + + typeset TYPE_RESULT="$(type -t user)" + + if [ "$TYPE_RESULT" != 'function' ]; then + #shellcheck source=/dev/null + source "$DOTFILES_FOLDER"/lib/functions + fi +} + +_is_func_imported + +execute