スナップを使用してGimpをインストールして実行する方法[閉じる]

スナップを使用してGimpをインストールして実行する方法[閉じる]

私が欲しい:

  1. ユーザーにsnapがインストールされているかどうか尋ねます。スナップショットをインストールして終了するスクリプトを実行しない場合は、続行します。
  2. gimpをインストールした後、gimpのインストールが完了したことを知らせるメッセージが表示されます。
  3. ユーザーにGIMPを実行するかどうか尋ねます。その場合はgimpを実行し、そうでない場合はスクリプトを終了してください。

ベストアンサー1

これはsh互換性のあるスクリプトです。スクリプトの他の部分が実行するアクションを説明するコメントを提供します。

snapaptOPがインストール方法を指定していないので、パッケージマネージャを使用してインストールしても大丈夫だと思いますsnap

#!/usr/bin/env sh

# Exit early if any command fails
set -e

installSnap() {
    # Assumption: This script is run only on Debian-based Linux distributions
    echo 'snap not installed, installing snap...'
    sudo apt update
    sudo apt install snapd
    echo 'snap installed. Log out and back in again before using snap.'
}

# If snap is not installed, install snap and exit
command -v snap || { installSnap && echo 'Exiting install script.' && exit 0; }

# Install GIMP
echo 'Installing GIMP...'
snap install gimp
echo 'GIMP installed.'

# Prompt user for input, and store input in answer
printf 'Would you like to run GIMP (y/n)? '
read -r answer

# If answer begins with 'Y' or 'y', start gimp
# Run gimp in background with nohup so gimp will continue running after
# this script terminates
# We likely aren't interested in gimp's output, so redirect it to /dev/null
[ "$answer" != "${answer#[Yy]}" ] && nohup gimp > /dev/null 2>&1 &

おすすめ記事