Skip to content

Commit

Permalink
update install scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
honjow committed Mar 1, 2024
1 parent 4c3af22 commit 0d5603a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)的手持设备提供性能设置调整
Expand Down
1 change: 1 addition & 0 deletions README_en.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
71 changes: 39 additions & 32 deletions install.sh
Original file line number Diff line number Diff line change
@@ -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"
rm "$temp_file"
sudo systemctl restart plugin_loader.service
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 0d5603a

Please sign in to comment.