From e7578e49054eb3d540da3bd74ac21247bee70548 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Wed, 10 May 2023 02:07:27 +0300 Subject: [PATCH] Chore(scripts): Simplification and documentation --- local/bin/x-quota-usage.php | 8 ++++ scripts/install-composer.sh | 29 ++++++------ scripts/install-gh-extensions.sh | 76 ++++++++++++++++---------------- scripts/install-go-packages.sh | 61 +++++++++++++------------ scripts/install-npm-packages.sh | 67 ++++++++++++++-------------- scripts/install-ntfy.sh | 47 ++++++++++---------- 6 files changed, 147 insertions(+), 141 deletions(-) diff --git a/local/bin/x-quota-usage.php b/local/bin/x-quota-usage.php index 87d422b..116adc0 100755 --- a/local/bin/x-quota-usage.php +++ b/local/bin/x-quota-usage.php @@ -10,6 +10,14 @@ $fsCharLenght = 0; $quota = shell_exec("quota -w"); +/** + * Pad string + * + * @param string $i Input string + * @param int $n Length + * @param string $p Padding string + * @return string + */ function pad($i, $n = 3, $p = ' ') { return str_pad($i, $n, $p, STR_PAD_LEFT); diff --git a/scripts/install-composer.sh b/scripts/install-composer.sh index 1680db0..ab6dcd9 100755 --- a/scripts/install-composer.sh +++ b/scripts/install-composer.sh @@ -4,20 +4,21 @@ # shellcheck source="shared.sh" source "$HOME/.dotfiles/scripts/shared.sh" -have php && { - EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')" - php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" - ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")" +! have php && msg_err "PHP Not Available, cannot install composer" && exit 0; - if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]; then - echo >&2 'ERROR: Invalid installer checksum' - rm composer-setup.php - exit 1 - fi +EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')" +php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")" - php composer-setup.php --quiet - RESULT=$? +if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]; then + echo >&2 'ERROR: Invalid installer checksum' rm composer-setup.php - mv composer.phar ~/.local/bin/composer - exit $RESULT -} || msg_err "PHP Not Available, cannot install composer" + exit 1 +fi + +php composer-setup.php --quiet +RESULT=$? +rm composer-setup.php +mv composer.phar ~/.local/bin/composer +exit $RESULT + diff --git a/scripts/install-gh-extensions.sh b/scripts/install-gh-extensions.sh index ffba0bf..3ef9625 100755 --- a/scripts/install-gh-extensions.sh +++ b/scripts/install-gh-extensions.sh @@ -4,42 +4,42 @@ # shellcheck source="shared.sh" source "$HOME/.dotfiles/scripts/shared.sh" -have gh && { - extensions=( - # GitHub CLI extension for generating a report on repository dependencies. - andyfeller/gh-dependency-report - # GitHub CLI extension to generate montage from GitHub user avatars - andyfeller/gh-montage - # An opinionated GitHub Cli extension for creating - # changelogs that adhere to the keep a changelog specification. - chelnak/gh-changelog - # Safely deletes local branches with no upstream and no un-pushed commits - davidraviv/gh-clean-branches - # A beautiful CLI dashboard for GitHub 🚀 - dlvhdr/gh-dash - # A github-cli extension script to clone all repositories - # in an organization, optionally filtering by topic. - matt-bartel/gh-clone-org - # being an extension to view the overall health of - # an organization's use of actions - rsese/gh-actions-status - ) - - msg "Starting to install GitHub CLI extensions..." - - for ext in "${extensions[@]}"; do - # Trim spaces - ext=${ext// /} - # Skip comments - if [[ ${ext:0:1} == "#" ]]; then continue; fi - - msg_run "Installing $ext" - gh extensions install "$ext" - echo "" - done - - msg_ok "Done" -} - ! have gh \ - && msg_err "gh (GitHub Client) could not be found, please install it first" + && msg_err "gh (GitHub Client) could not be found, please install it first" \ + && exit 0; + +extensions=( + # GitHub CLI extension for generating a report on repository dependencies. + andyfeller/gh-dependency-report + # GitHub CLI extension to generate montage from GitHub user avatars + andyfeller/gh-montage + # An opinionated GitHub Cli extension for creating + # changelogs that adhere to the keep a changelog specification. + chelnak/gh-changelog + # Safely deletes local branches with no upstream and no un-pushed commits + davidraviv/gh-clean-branches + # A beautiful CLI dashboard for GitHub 🚀 + dlvhdr/gh-dash + # A github-cli extension script to clone all repositories + # in an organization, optionally filtering by topic. + matt-bartel/gh-clone-org + # being an extension to view the overall health of + # an organization's use of actions + rsese/gh-actions-status +) + +msg "Starting to install GitHub CLI extensions..." + +for ext in "${extensions[@]}"; do + # Trim spaces + ext=${ext// /} + # Skip comments + if [[ ${ext:0:1} == "#" ]]; then continue; fi + + msg_run "Installing $ext" + gh extensions install "$ext" + echo "" +done + +msg_ok "Done" + diff --git a/scripts/install-go-packages.sh b/scripts/install-go-packages.sh index 587991d..d6347bc 100755 --- a/scripts/install-go-packages.sh +++ b/scripts/install-go-packages.sh @@ -4,38 +4,37 @@ # shellcheck source=shared.sh source "$HOME/.dotfiles/scripts/shared.sh" -have go && { - packages=( - # sysadmin/scripting utilities, distributed as a single binary - github.com/skx/sysbox@latest - # Git Profile allows you to switch between user profiles in git repos - github.com/dotzero/git-profile@latest - # An extensible command line tool or library to format yaml files. - github.com/google/yamlfmt/cmd/yamlfmt@latest - # Parsing HTML at the command line - github.com/ericchiang/pup@latest - # HTML to Markdown converter - github.com/suntong/html2md@latest - # cheat allows you to create and view interactive cheatsheets on the cli. - github.com/cheat/cheat/cmd/cheat@latest - # Render markdown on the CLI, with pizzazz! 💅 - github.com/charmbracelet/glow@latest - # Static checker for GitHub Actions workflow files - github.com/rhysd/actionlint/cmd/actionlint@latest - ) +! have go && msg "go hasn't been installed yet." && exit 0; - for pkg in "${packages[@]}"; do - # Trim spaces - pkg=${pkg// /} - # Skip comments - if [[ ${pkg:0:1} == "#" ]]; then continue; fi +packages=( + # sysadmin/scripting utilities, distributed as a single binary + github.com/skx/sysbox@latest + # Git Profile allows you to switch between user profiles in git repos + github.com/dotzero/git-profile@latest + # An extensible command line tool or library to format yaml files. + github.com/google/yamlfmt/cmd/yamlfmt@latest + # Parsing HTML at the command line + github.com/ericchiang/pup@latest + # HTML to Markdown converter + github.com/suntong/html2md@latest + # cheat allows you to create and view interactive cheatsheets on the cli. + github.com/cheat/cheat/cmd/cheat@latest + # Render markdown on the CLI, with pizzazz! 💅 + github.com/charmbracelet/glow@latest + # Static checker for GitHub Actions workflow files + github.com/rhysd/actionlint/cmd/actionlint@latest +) - msg_run "Installing go package:" "$pkg" - go install "$pkg" - echo "" - done +for pkg in "${packages[@]}"; do + # Trim spaces + pkg=${pkg// /} + # Skip comments + if [[ ${pkg:0:1} == "#" ]]; then continue; fi - msg_ok "Done" -} + msg_run "Installing go package:" "$pkg" + go install "$pkg" + echo "" +done + +msg_ok "Done" -! have go && msg "go hasn't been installed yet." diff --git a/scripts/install-npm-packages.sh b/scripts/install-npm-packages.sh index 89943b0..ab141a5 100755 --- a/scripts/install-npm-packages.sh +++ b/scripts/install-npm-packages.sh @@ -4,42 +4,41 @@ # shellcheck source=shared.sh source "$HOME/.dotfiles/scripts/shared.sh" -have npm && { - packages=( - # This is a tool to check if your files consider your .editorconfig rules. - "editorconfig-checker" - # Node module to create a release or a changelog from - # a tag and uses issues or commits to creating the release notes. - "github-release-notes" - "neovim" - "prettier" - "corepack" - "standardjs" - # CLI and local web plain text note‑taking, bookmarking, and archiving - # with linking, tagging, filtering, search, Git versioning & syncing, - # Pandoc conversion, + more, in a single portable script. - "nb.sh" - ) +! have npm && msg_err "npm could not be found." && exit 0; - for pkg in "${packages[@]}"; do - # Trim spaces - pkg=${pkg// /} - # Skip comments - if [[ ${pkg:0:1} == "#" ]]; then continue; fi +packages=( + # This is a tool to check if your files consider your .editorconfig rules. + "editorconfig-checker" + # Node module to create a release or a changelog from + # a tag and uses issues or commits to creating the release notes. + "github-release-notes" + "neovim" + "prettier" + "corepack" + "standardjs" + # CLI and local web plain text note‑taking, bookmarking, and archiving + # with linking, tagging, filtering, search, Git versioning & syncing, + # Pandoc conversion, + more, in a single portable script. + "nb.sh" +) - if [[ $(npm ls -g -p "$pkg") != "" ]]; then - msg_run_done "$pkg" "already installed" - else - msg_run "Installing npm package:" "$pkg" - npm install -g --no-fund --no-progress --no-timing "$pkg" - fi +for pkg in "${packages[@]}"; do + # Trim spaces + pkg=${pkg// /} + # Skip comments + if [[ ${pkg:0:1} == "#" ]]; then continue; fi - echo "" - done + if [[ $(npm ls -g -p "$pkg") != "" ]]; then + msg_run_done "$pkg" "already installed" + else + msg_run "Installing npm package:" "$pkg" + npm install -g --no-fund --no-progress --no-timing "$pkg" + fi - msg_run "Upgrading all global packages" - npm -g --no-progress --no-timing --no-fund outdated - npm -g --no-timing --no-fund upgrade -} + echo "" +done + +msg_run "Upgrading all global packages" +npm -g --no-progress --no-timing --no-fund outdated +npm -g --no-timing --no-fund upgrade -! have npm && msg_err "npm could not be found." diff --git a/scripts/install-ntfy.sh b/scripts/install-ntfy.sh index be10d93..3c4f248 100755 --- a/scripts/install-ntfy.sh +++ b/scripts/install-ntfy.sh @@ -6,32 +6,31 @@ source "$HOME/.dotfiles/scripts/shared.sh" set -e -have ntfy && msg "ntfy already installed" +have ntfy && msg "ntfy already installed" && exit 0; -! have ntfy && { - case $(dfm check arch) in - Linux) - NTFY_ARCH="linux_$(arch)" - ;; - Darwin) - NTFY_ARCH="macOS_all" - ;; - esac +case $(dfm check arch) in + Linux) + NTFY_ARCH="linux_$(arch)" + ;; + Darwin) + NTFY_ARCH="macOS_all" + ;; +esac - NTFY_VERSION=2.2.0 - NTFY_URL="https://github.com/binwiederhier/ntfy" - NTFY_DEST="ntfy_${NTFY_VERSION}_${NTFY_ARCH}" +NTFY_VERSION=2.2.0 +NTFY_URL="https://github.com/binwiederhier/ntfy" +NTFY_DEST="ntfy_${NTFY_VERSION}_${NTFY_ARCH}" - curl -L "$NTFY_URL/releases/download/v${NTFY_VERSION}/${NTFY_DEST}.tar.gz" \ - > "${NTFY_DEST}.tar.gz" - tar zxvf "${NTFY_DEST}.tar.gz" - cp -a "${NTFY_DEST}/ntfy" ~/.local/bin/ntfy - mkdir -p ~/.config/ntfy +curl -L "$NTFY_URL/releases/download/v${NTFY_VERSION}/${NTFY_DEST}.tar.gz" \ + > "${NTFY_DEST}.tar.gz" +tar zxvf "${NTFY_DEST}.tar.gz" +cp -a "${NTFY_DEST}/ntfy" ~/.local/bin/ntfy +mkdir -p ~/.config/ntfy - # copy config only if it does not exist - if [ ! -f "$HOME/.config/ntfy/client.yml" ]; then - cp "${NTFY_DEST}/client/client.yml" ~/.config/ntfy/client.yml - fi +# copy config only if it does not exist +if [ ! -f "$HOME/.config/ntfy/client.yml" ]; then + cp "${NTFY_DEST}/client/client.yml" ~/.config/ntfy/client.yml +fi + +rm -rf "${NTFY_DEST}" "${NTFY_DEST}.tar.gz" - rm -rf "${NTFY_DEST}" "${NTFY_DEST}.tar.gz" -}