Skip to content

Commit

Permalink
chore: update error message in install script; do not use pipe when u…
Browse files Browse the repository at this point in the history
…sing install script as it will conflict with user input

Signed-off-by: Charlie Chiang <[email protected]>
  • Loading branch information
charlie0129 committed Sep 28, 2023
1 parent ac86188 commit d45e18b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Yes, macOS have optimized battery charging. It will try to find out your chargin

> Currently, it is command-line only. Some knowledge of the command-line is recommended. A native GUI is possible but not planned. If you want to build a GUI, you can ask me to put a link here to your project
1. (Optional) If you are lazy, there is an installation script to help you get the first 3 steps done (Internet connection required). Put this in your terminal: `curl -fsSL https://github.com/charlie0129/batt/raw/master/hack/install.sh | bash`. You may need to provide your password (to control charging). This will download and install the latest _stable_ version for you, then you can skip to step 5.
1. (Optional) If you are lazy, there is an installation script to help you get the first 3 steps done (Internet connection required). Put this in your terminal: `bash <(curl -fsSL https://github.com/charlie0129/batt/raw/master/hack/install.sh)`. You may need to provide your password (to control charging). This will download and install the latest _stable_ version for you, then you can skip to step 5.
2. Get the binary. For _stable_ and _beta_ releases, you can find the download link in the [release page](https://github.com/charlie0129/batt/releases). If you want development versions with the latest features and bug fixes, you can download prebuilt binaries from [GitHub Actions](https://github.com/charlie0129/batt/actions/workflows/build-test-binary.yml) (has a retention period of 3 months and you need to `chmod +x batt` after extracting the archive) or [build it yourself](#building) .
3. Put the binary somewhere safe. You don't want to move it after installation :). It is recommended to save it in your `$PATH`, e.g., `/usr/local/bin`, so you can directly call `batt` on the command-line. In this case, the binary location will be `/usr/local/bin/batt`.
4. Install daemon using `sudo batt install`. If you do not want to use `sudo` every time after installation, add the `--allow-non-root-access` flag: `sudo batt install --allow-non-root-access`. To uninstall: please refer to [How to uninstall?](#how-to-uninstall)
Expand Down Expand Up @@ -177,7 +177,7 @@ Automatic:
> Updates to the latest _stable_ version. If you want to use other versions (_beta_, _development_), please use the manual method.
```bash
curl -fsSL https://github.com/charlie0129/batt/raw/master/hack/install.sh | bash
bash <(curl -fsSL https://github.com/charlie0129/batt/raw/master/hack/install.sh)
```

Manual:
Expand Down
7 changes: 5 additions & 2 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,13 @@ One thing to note: this option is purely cosmetic. batt will still function even
}

func bool2Text(b bool) string {
var c string
if b {
return color.New(color.Bold, color.FgGreen).Sprint("✔")
c = "✔"
} else {
c = "✘"
}
return bold("✘")
return bold(c)
}

func bold(format string, a ...interface{}) string {
Expand Down
18 changes: 6 additions & 12 deletions hack/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,15 @@ confirm() {
echo -n "$1 [y/n]: "
read -r -n 1 REPLY
case $REPLY in
[y])
[yY])
echo
return 0
;;
[n])
[nN])
echo
return 1
;;
[Y])
echo
return 0
;;
[N])
echo
return 1
;;
*) printf "invalid input" ;;
*) printf " is invalid. Press 'y' to continue; 'n' to exit. \n" ;;
esac
done
}
Expand All @@ -43,6 +35,8 @@ launch_daemon="/Library/LaunchDaemons/cc.chlc.batt.plist"

# Uninstall old versions (if present)
if [[ -f "$launch_daemon" ]]; then
echo "You have old versions of batt installed, which need to be uninstalled before installing the latest version. We will uninstall it for you now."
confirm "Is this OK?" || exit 0
info "Stopping old versions of batt..."
sudo launchctl unload "$launch_daemon"
sudo rm -f "$launch_daemon"
Expand Down Expand Up @@ -70,7 +64,7 @@ if [[ -z "$PREFIX" ]]; then
fi

echo "Will install batt ${version} to $PREFIX (to change install location, set \$PREFIX environment variable)."
confirm "Continue?" || exit 0
confirm "Ready to install?" || exit 0
info "Downloading batt ${version} from $tarball_url and installing to $PREFIX..."
sudo mkdir -p "$PREFIX"
curl -fsSL "$tarball_url" | sudo tar -xzC "$PREFIX"
Expand Down

0 comments on commit d45e18b

Please sign in to comment.