From 0d5603ae7f096093fb7f68f7921cc026b81ceb42 Mon Sep 17 00:00:00 2001 From: honjow Date: Fri, 1 Mar 2024 09:03:38 +0800 Subject: [PATCH] update install scripts --- README.md | 2 +- README_en.md | 1 + install.sh | 71 +++++++++++++++++++++++++++++----------------------- package.json | 2 +- 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index f7f56e2..64f1bba 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[English](https://github.com/mengmeet/PowerControl/blob/main/README_en.md) +[English](./README_en.md) | 简体中文 # PowerControl 用于[decky-loader](https://github.com/SteamDeckHomebrew/decky-loader)的插件 为安装了[holoiso](https://github.com/theVakhovskeIsTaken/holoiso)的手持设备提供性能设置调整 diff --git a/README_en.md b/README_en.md index d10e485..ca0328d 100755 --- a/README_en.md +++ b/README_en.md @@ -1,3 +1,4 @@ +English | [简体中文](./README.md) # PowerControl Plugin for [decky-loader](https://github.com/SteamDeckHomebrew/decky-loader) Provide performance settings adjustments for handheld installed with [holoiso](https://github.com/theVakhovskeIsTaken/holoiso) diff --git a/install.sh b/install.sh index 2003188..640f374 100755 --- a/install.sh +++ b/install.sh @@ -1,50 +1,57 @@ -#!/bin/bash +#!/usr/bin/bash -# check if jq is installed -if ! [ -x "$(command -v jq)" ]; then - echo 'Error: jq is not installed.' >&2 - exit 1 +set -e + +if [ "$EUID" -eq 0 ]; then + echo "Please do not run as root" + exit fi +github_api_url="https://api.github.com/repos/mengmeet/PowerControl/releases/latest" +package="PowerControl" + +echo "installing $package" + temp=$(mktemp -d) -# Download latest release -RELEASE=$(curl -s 'https://api.github.com/repos/mengmeet/PowerControl/releases/latest') -MESSAGE=$(echo "$RELEASE" | jq -r '.message') +plugin_dir="${HOME}/homebrew/plugins/${package}" +mkdir -p $plugin_dir -if [[ "$MESSAGE" != "null" ]]; then - echo "$MESSAGE" >&2 - exit 1 +use_jq=false +if [ -x "$(command -v jq)" ]; then + use_jq=true fi -RELEASE_VERSION=$(echo "$RELEASE" | jq -r '.tag_name') -RELEASE_URL=$(echo "$RELEASE" | jq -r '.assets[0].browser_download_url') +RELEASE=$(curl -s "$github_api_url") + +if [[ $use_jq == true ]]; then + echo "Using jq" + MESSAGE=$(echo "$RELEASE" | jq -r '.message') + RELEASE_VERSION=$(echo "$RELEASE" | jq -r '.tag_name') + RELEASE_URL=$(echo "$RELEASE" | jq -r '.assets[0].browser_download_url') +else + MESSAGE=$(echo $RELEASE | grep "message" | cut -d '"' -f 4) + RELEASE_URL=$(echo $RELEASE | grep "browser_download_url" | cut -d '"' -f 4) + RELEASE_VERSION=$(echo $RELEASE | grep "tag_name" | cut -d '"' -f 4) +fi -if [ -z "$RELEASE_VERSION" ] || [ -z "$RELEASE_URL" ]; then - echo "Failed to get latest release info" >&2 +if [[ "$MESSAGE" != "null" ]]; then + echo "error: $MESSAGE" >&2 exit 1 fi - -curl -L -o ${temp}/PowerControl.tar.gz "${github_prefix}${RELEASE_URL}" - -echo "Installing PowerControl $RELEASE_VERSION" - -if [ ! -f ${temp}/PowerControl.tar.gz ]; then - echo "Failed to download PowerControl $RELEASE_VERSION" >&2 +if [ -z "$RELEASE_URL" ]; then + echo "Failed to get latest release" >&2 exit 1 fi -# remove old version -chmod +w ${HOME}/homebrew/plugins -chmod -R +w ${HOME}/homebrew/plugins/PowerControl - -rm -rf ${HOME}/homebrew/plugins/PowerControl || true +temp_file="${temp}/${package}.tar.gz" -# Extract and restart plugin_loader -tar -xzf ${temp}/PowerControl.tar.gz -C ${HOME}/homebrew/plugins && sudo systemctl restart plugin_loader.service +echo "Downloading $package $RELEASE_VERSION" +curl -L "$RELEASE_URL" -o "$temp_file" -# Cleanup -rm -f ${temp}/PowerControl.tar.gz +sudo tar -xzf "$temp_file" -C $temp +sudo rsync -av "${temp}/${package}/" $plugin_dir --delete -echo "PowerControl $RELEASE_VERSION installed" \ No newline at end of file +rm "$temp_file" +sudo systemctl restart plugin_loader.service diff --git a/package.json b/package.json index 4201fe9..647ab49 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "PowerControl", - "version": "2.3.0", + "version": "2.3.2", "description": "PowerControl plugin.", "scripts": { "build": "shx rm -rf dist && rollup -c",