Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

Commit

Permalink
Merge pull request #148 from ludeeus/combine-installation-scripts
Browse files Browse the repository at this point in the history
Combine upgrade scripts -dev & -beta
  • Loading branch information
Landrash authored Mar 26, 2018
2 parents cf98ec4 + c97b2ba commit 472efca
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 123 deletions.
4 changes: 3 additions & 1 deletion docs/hassbian_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Optional flags:
- `-Y | --accept` This will accept defaults on scripts that allow this.
- `-F | --force` This will force run an script. This is useful if you need to reinstall a package.
- `-D | --debug` This will output every comand to the console.
- `-B | --beta` This will install the current beta version if implemented.
- `--dev` This will install the current development version if implemented.

Other available commands:
- `-V | --version` This will show you the installed version of `hassbian-config`.
Expand All @@ -38,5 +40,5 @@ $ sudo hassbian-config upgrade hassbian-script

## Upgrade to dev branch
```
$ sudo hassbian-config upgrade hassbian-script-dev
$ sudo hassbian-config upgrade hassbian-script --dev
```
10 changes: 10 additions & 0 deletions docs/homeassistant.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ $ sudo hassbian-config install homeassistant
$ sudo hassbian-config upgrade homeassistant
```

## Upgrade to beta channel
```
$ sudo hassbian-config upgrade homeassistant --beta
```

## Upgrade to dev branch
```
$ sudo hassbian-config upgrade homeassistant --dev
```

## Additional info
Running as: `homeassistant`
Configuration dir: `/home/homeassistant/.homeassistant/`
Expand Down
2 changes: 1 addition & 1 deletion package/etc/bash_completion.d/hassbian-config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ _hassbian-config()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="install upgrade show log share-log --version --help"
altopts="--accept --force --debug --version --help"
altopts="--accept --force --debug --version --help --dev --beta"
inst=$(find /opt/hassbian/suites/ -maxdepth 1 -type f | awk -F'/|_' ' {print $NF}' | awk -F. '{print $1}')

if [[ ${cur} == -* ]] ; then
Expand Down
39 changes: 0 additions & 39 deletions package/opt/hassbian/suites/hassbian-script-dev.sh

This file was deleted.

51 changes: 40 additions & 11 deletions package/opt/hassbian/suites/hassbian-script.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
function hassbian-script-show-short-info {
echo "Hassbian-Script upgrade script for Hassbian"
echo "Hassbian-script upgrade script for Hassbian"
}

function hassbian-script-show-long-info {
Expand All @@ -12,21 +12,50 @@ function hassbian-script-show-copyright-info {
}

function hassbian-script-upgrade-package {
echo "Changing to temporary folder"
cd /tmp || exit

echo "Downloading newest release"
curl https://api.github.com/repos/home-assistant/hassbian-scripts/releases/latest | grep "browser_download_url.*deb" | cut -d : -f 2,3 | tr -d \" | wget -qi -
if [ "$DEV" == "true" ]; then
echo "This script downloads new scripts directly from the dev branch on Github."
echo "you can use this to be on the 'bleeding edge of the development of Hassbian.'"
echo "This is not recommended for daily use."
echo -n "Are you really sure you want to continue? [N/y] : "
read -r RESPONSE
if [ "$RESPONSE" == "y" ] || [ "$RESPONSE" == "Y" ]; then
RESPONSE="Y"
else
echo "Exiting..."
return 0
fi
echo "Creating and changing in to a temporary folder."
cd || exit
sudo mkdir /tmp/hassbian_config_update
cd /tmp/hassbian_config_update || exit

# Setting package name
HASSBIAN_PACKAGE=$(echo hassbian*.deb)
echo "Downloading new scripts from github."
curl -L https://api.github.com/repos/home-assistant/hassbian-scripts/tarball| sudo tar xz --strip=1

echo "Installing newest release"
sudo apt install -y /tmp/"$HASSBIAN_PACKAGE"
echo "Moving scripts to the install folder."
yes | sudo cp -rf /tmp/hassbian_config_update/package/usr/local/bin/hassbian-config /usr/local/bin/hassbian-config
yes | sudo cp -rf /tmp/hassbian_config_update/package/opt/hassbian/suites/* /opt/hassbian/suites/

echo "Cleanup"
rm "$HASSBIAN_PACKAGE"
echo "Removing the temporary folder."
cd || exit
sudo rm -r /tmp/hassbian_config_update
else
echo "Changing to a temporary folder"
cd /tmp || exit

echo "Downloading latest release"
curl https://api.github.com/repos/home-assistant/hassbian-scripts/releases/latest | grep "browser_download_url.*deb" | cut -d : -f 2,3 | tr -d \" | wget -qi -

# Setting package name
HASSBIAN_PACKAGE=$(echo hassbian*.deb)

echo "Installing latest release"
sudo apt install -y /tmp/"$HASSBIAN_PACKAGE"

echo "Cleanup"
rm "$HASSBIAN_PACKAGE"
fi
echo
echo "Upgrade is now done."
echo
Expand Down
60 changes: 0 additions & 60 deletions package/opt/hassbian/suites/homeassistant-dev.sh

This file was deleted.

42 changes: 31 additions & 11 deletions package/opt/hassbian/suites/homeassistant.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,35 @@ return 0
}

function homeassistant-upgrade-package {
echo "Checking current version"
pypiversion=$(curl -s https://pypi.python.org/pypi/homeassistant/json | grep '"version":' | awk -F'"' '{print $4}')

sudo -u homeassistant -H /bin/bash << EOF | grep Version | awk '{print $2}'|while read -r version; do if [[ "${pypiversion}" == "${version}" ]]; then echo "You already have the latest version: $version";exit 1;fi;done
source /srv/homeassistant/bin/activate
pip3 show homeassistant
if [ "$DEV" == "true" ]; then
echo "This script downloads Home Assistant directly from the dev branch on Github."
echo "you can use this to be on the 'bleeding edge of the development of Home Assistant.'"
echo "This is not recommended for daily use."
echo -n "Are you really sure you want to continue? [N/y] : "
read -r RESPONSE
if [ "$RESPONSE" == "y" ] || [ "$RESPONSE" == "Y" ]; then
RESPONSE="Y"
else
echo "Exiting..."
return 0
fi
else
echo "Checking current version"
if [ "$BETA" == "true" ]; then
newversion=$(curl -s https://pypi.python.org/pypi/homeassistant/json | grep '"version":' | awk -F'"' '{print $4}')
else
newversion=$(curl -s https://api.github.com/repos/home-assistant/home-assistant/releases/latest | grep tag_name | awk -F'"' '{print $4}')
fi
sudo -u homeassistant -H /bin/bash << EOF | grep Version | awk '{print $2}'|while read -r version; do if [[ "${newversion}" == "${version}" ]]; then echo "You already have the latest version: $version";exit 1;fi;done
source /srv/homeassistant/bin/activate
pip3 show homeassistant
EOF

if [[ $? == 1 ]]; then
echo "Stopping upgrade"
exit 1
if [[ $? == 1 ]]; then
echo "Stopping upgrade"
exit 1
fi
fi

echo "Stopping Home Assistant"
systemctl stop [email protected]

Expand All @@ -85,7 +101,11 @@ source /srv/homeassistant/bin/activate
echo "Installing latest version of Home Assistant"
pip3 install --upgrade setuptools wheel
pip3 install --upgrade homeassistant
if [ "$DEV" == "true" ]; then
pip3 install git+https://github.com/home-assistant/home-assistant@dev
else
pip3 install --upgrade homeassistant=="$newversion"
fi
echo "Deactivating virtualenv"
deactivate
Expand Down
10 changes: 10 additions & 0 deletions package/usr/local/bin/hassbian-config
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ function help {
printf "%-10s\\t%s\\n" " -Y | --accept" "Accept defaults on scripts that allow this"
printf "%-10s\\t%s\\n" " -F | --force" "Force run an script, this is useful if you need to reinstall a package"
printf "%-10s\\t%s\\n" " -D | --debug" "This will output every comand to the console."
printf "%-10s\\t%s\\n" " -B | --beta" "This will install the current beta version if implemented."
printf "%-10s\\t%s\\n" " --dev" "This will install the current development version if implemented."
printf "\\n"
printf "other [command] available:\\n"
printf "%-10s\\t%s\\n" " -V | --version" "Prints the version of hassbian-config"
Expand Down Expand Up @@ -223,6 +225,14 @@ case $COMMAND in
DEBUG="true"
shift # past argument
;;
"--dev")
DEV="true"
shift # past argument
;;
"-B"|"--beta")
BETA="true"
shift # past argument
;;
"show")
if [ "$SUITE" != "" ]; then
if verify-suite "$SUITE"; then
Expand Down

0 comments on commit 472efca

Please sign in to comment.