このスクリプトをより効率的にするにはどうすればよいですか? [閉鎖]

このスクリプトをより効率的にするにはどうすればよいですか? [閉鎖]

私はgnome-tweak-toolを使ってNumixテーマを体系的にインストールするスクリプトを書いています。

すでにインストールされているプロジェクトを再インストールしていないことを確認したいwhich [name of item] > /dev/null

これは私の現在のスクリプトです。

function installNumix() {
    echo "Checking if Numix is installed ..."
    if ! which gnome-tweak-tool > /dev/null; then
        if ! which numix-gtk-theme > /dev/null; then
            if ! which numix-icon-theme-circle > /dev/null; then
                echo "Installing Numix ..."
                sudo add-apt-repository ppa:numix/ppa
                sudo apt-get update
                sudo apt-get install numix-gtk-theme numix-icon-theme-circle -y
                sudo apt-get install gnome-tweak-tool -y
                echo "Configuring Numix:"
                echo "===================================================================="
                echo "Please use the 'tweak-tool' to change your theme to 'Numix'."
                echo "[GTK+]: Numix."
                echo "[icons]: Numix-Circle."
                echo "===================================================================="
                gnome-tweak-tool
                echo "Numix has been manually configured."
                source ~/.profile
                changeBackground backgrounds/background.png
                changeProfilePicture $(whoami) profile_pictures/profile_picture.png
                echo "The Numix has been installed."
                sleep 5
            fi
        fi
    else
        echo "Numix has already been installed."
        sleep 5
    fi
}

私の.profileファイル:

#Change desktop background f(x)
#Ex. changeBackground  /path/to/image.png
function changeBackground() {
    FILE="file://$(readlink -f "$1")"
    fileName="${FILE##*/}" # baseName + fileExtension

    echo "Changing desktop background to: '$fileName' ..."
    dconf write "/org/gnome/desktop/background/picture-uri" "'$FILE'"
    echo "Desktop background has been changed."
    sleep 5
}

#Change profile picture f(x)
#Ex. changeProfilePicture username /path/to/image.png
function changeProfilePicture() {
    FILE="$(readlink -f "$2")"
    fileName="${FILE##*/}" # baseName + fileExtension

    echo "Checking if 'imagemagick' is installed ..."
    if ! command brew ls --versions imagemagick >/dev/null 2>&1; then
        echo "Installing 'imagemagick' ..."
        brew install imagemagick -y
        echo "'Imagemagick' has been installed."
        sleep 5
    else
        echo "'Imagemagick' has already been installed."
        sleep 5
    fi

    echo "Changing profile picture to: '$fileName' ..."
    sudo mkdir -p '/var/lib/AccountsService/icons/'"$1"
    sudo convert "$2" -set filename:f '/var/lib/AccountsService/icons/'"$1/%t" -resize 96x96 '%[filename:f].png'
    echo "Profile picture has been changed."
    sleep 5
}

ベストアンサー1

gnome-tweak-toolユーザーが手動で実行するのではなく、スクリプトでgtkとウィンドウマネージャのテーマとアイコンのテーマを設定するために使用できますgsettings。例えば

gsettings set org.gnome.desktop.interface gtk-theme Numix
gsettings set org.gnome.desktop.wm.preferences theme Numix
gsettings set org.gnome.desktop.interface icon-theme Numix-Circle

ちなみに、PATHディレクトリのどこかに実行可能ファイルがnumix-gtk-themeない場合、実行しても必要な操作は実行されません。numix-icon-theme-circlewhich

代わりに、特定のファイルまたはディレクトリが存在することを確認してください。例えば

if [ ! -d /usr/share/themes/Numix ] ; then ... fi

Numixテーマがインストールされていないため、これが正しいディレクトリかどうかはわかりません。検索する正しいディレクトリを使用しdpkg -L numix-gtk-themeて検索します。dpkg -L numix-icon-theme-circle

または、パッケージがインストールされていることを確認する必要はありません。速く走る:

apt-get -y install numix-gtk-theme numix-icon-theme-circle gnome-tweak-tool

(stdoutとstderrを/ dev / nullにリダイレクトするオプション)

これらのパッケージの最新バージョンがすでにインストールされている場合は、apt-get何もしません。それ以外の場合はインストールまたはアップグレードされます。

最後に、sudo add-apt-repository -y ppa:numix/ppa使用時にユーザーにメッセージを表示しないでください。リポジトリが追加されても害はありません。ファイルの前のエントリをコメントアウトし、/etc/sources.list.d/numix-ubuntu-ppa-yakkety.listファイルの先頭にppaを追加します。

おすすめ記事