generated from SteamDeckHomebrew/decky-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
42 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters