Избегайте дублирования кода в сценарии в зависимости от доступа к sudo

netstat -plan

или, для любого конкретного порта,

netstat -plan | grep :<portno.>
0
20.12.2020, 22:12
1 ответ

Вот один из подходов:

#!/bin/bash

## make a temp dir
tmpDir=$(mktemp -d)

## Download the files to it
SauceCodePro="https://github.com/ryanoasis/nerd-fonts/blob/master/patched-fonts/SourceCodePro"
curl -L -o "$tmpDir/Sauce Code Pro Nerd Font Regular.ttf" "$SauceCodePro/Regular/complete/Sauce%20Code%20Pro%20Nerd%20Font%20Complete.ttf"
curl -L -o "$tmpDir/Sauce Code Pro Nerd Font Bold.ttf"    "$SauceCodePro/Bold/complete/Sauce%20Code%20Pro%20Bold%20Nerd%20Font%20Complete.ttf"
curl -L -o "$tmpDir/Sauce Code Pro Nerd Font Italic.ttf"  "$SauceCodePro/Italic/complete/Sauce%20Code%20Pro%20Italic%20Nerd%20Font%20Complete.ttf"

## Check for sudo access using whatever "have_sudo_access" is supposed to be
if have_sudo_access; then
  echo "Installing system wide"
  sudo mkdir -p "/usr/share/fonts/.local/share/fonts/"
  sudo mv "$tmpDir"/* "/usr/share/fonts/.local/share/fonts/"
else
  echo "Installing font for local user"
  mkdir -p "$HOME/.local/share/fonts/"
  mv "$tmpDir"/* "$HOME/.local/share/fonts/"
fi

## delete the now empty tmp dir
rmdir "$tmpDir"
2
18.03.2021, 22:41

Теги

Похожие вопросы