Skip to content

Commit

Permalink
feat(tools): move station installation from brew to shell script
Browse files Browse the repository at this point in the history
  • Loading branch information
trystan2k committed Aug 8, 2021
1 parent a2cd8dc commit 05aba56
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 3 deletions.
40 changes: 39 additions & 1 deletion lib/functions
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ install() {
;;
snap*)
_snapInstall "${otherArguments[@]}"
;;
;;
dmg*)
_dmgInstall "${otherArguments[@]}"
;;
*)
warn "Unknow Installatin type: '$install_type'"
_errorInstall "${otherArguments[@]}" ;;
Expand Down Expand Up @@ -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
}
7 changes: 7 additions & 0 deletions scripts/tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion tools/linux/station.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion tools/macos/Brewfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ cask "google-chrome"
cask "microsoft-edge"

## Chats
cask "station"
cask "pdf-expert"
cask "rectangle"

Expand Down
53 changes: 53 additions & 0 deletions tools/macos/station.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 05aba56

Please sign in to comment.