🐛 install xcode-select if git is not yet installed

This commit is contained in:
Mentor
2023-02-02 10:54:56 +01:00
parent 2f3a243cc2
commit 6d29e249f1
4 changed files with 36 additions and 11 deletions

View File

@@ -1,3 +1,8 @@
Development notes:
- logo icons are 20px black/white for theme and 100% vs 50% for active inactive (inside bit only.)
- logo icons are 20px black/white for theme and 100% vs 50% for active inactive (inside bit only.)
- deploy new version:
- Update version in `package.json`
- `npm run build`
- Create new [release](https://github.com/actuallymentor/battery/releases)
- Update [brew formula](https://github.com/Homebrew/homebrew-cask/blob/master/Casks/battery.rb)

View File

@@ -67,6 +67,14 @@ const update_or_install_battery = async () => {
try {
// Check if xcode build tools are installed
const xcode_installed = await exec_async( `${ path_fix } which git` ).catch( () => false )
if( !xcode_installed ) {
alert( `The Battery tool needs Xcode to be installed, please accept the terms and conditions for installation` )
await exec_async( `${ path_fix } xcode-select --install` )
alert( `Please restart the Battery app after Xcode finished installing` )
}
// Check if battery is installed
const is_installed = await exec_async( `${ path_fix } which battery` ).catch( () => false )
log( 'Is installed? ', is_installed )

View File

@@ -1,6 +1,6 @@
{
"name": "battery",
"version": "1.0.3",
"version": "1.0.4",
"description": "A battery charge limiter for M1 Mac devices",
"main": "main.js",
"build": {

View File

@@ -17,32 +17,44 @@ configfolder=/Users/$calling_user/.battery
pidfile=$configfolder/battery.pid
logfile=$configfolder/battery.log
# Ask for sudo once, in most systems this will cache the permissions for a bit
sudo echo "🔋 Starting battery installation"
echo -e "\n[ 1/9 ] Superuser permissions acquired."
# Check if git is installed, and if not, install it
if ! which git &> /dev/null; then
echo -e "\n[ 1/10 ] Xcode build tools are not installed, please accept the xcode dialog"
xcode-select --install
if ! which git; then
echo "Build tools not installed, please run this script again"
fi
else
echo -e "\n[ 1/10 ] Xcode build tools are installed, continuing"
fi
echo -e "[ 2/10 ] Superuser permissions acquired."
# Get smc source and build it
smcfolder="$tempfolder/smc"
echo "[ 2/9 ] Cloning fan control version of smc"
echo "[ 3/10 ] Cloning fan control version of smc"
rm -rf $smcfolder
git clone --depth 1 https://github.com/hholtmann/smcFanControl.git $smcfolder &> /dev/null
cd $smcfolder/smc-command
echo "[ 3/9 ] Building smc from source"
echo "[ 4/10 ] Building smc from source"
make &> /dev/null
# Move built file to bin folder
echo "[ 4/9 ] Move smc to executable folder"
echo "[ 5/10 ] Move smc to executable folder"
sudo mkdir -p $binfolder
sudo mv $smcfolder/smc-command/smc $binfolder
sudo chmod u+x $binfolder/smc
# Write battery function as executable
batteryfolder="$tempfolder/battery"
echo "[ 5/9 ] Cloning battery repository"
echo "[ 6/10 ] Cloning battery repository"
git clone --depth 1 https://github.com/actuallymentor/battery.git $batteryfolder &> /dev/null
echo "[ 6/9 ] Writing script to $binfolder/battery for user $calling_user"
echo "[ 7/10 ] Writing script to $binfolder/battery for user $calling_user"
sudo cp $batteryfolder/battery.sh $binfolder/battery
# Set permissions for battery executables
@@ -65,12 +77,12 @@ sudo chmod 755 $pidfile
sudo chown $calling_user $binfolder/battery
sudo bash $batteryfolder/battery.sh visudo
echo "[ 7/9 ] Set up visudo declarations"
echo "[ 8/10 ] Set up visudo declarations"
# Remove tempfiles
cd ../..
echo "[ 8/9 ] Removing temp folder $tempfolder"
echo "[ 9/10 ] Removing temp folder $tempfolder"
rm -rf $tempfolder
echo "[ 9/9 ] Removed temporary build files"
echo "[ 10/10 ] Removed temporary build files"
echo -e "\n🎉 Battery tool installed. Type \"battery help\" for instructions.\n"