Skip to content

Commit

Permalink
Initial preperations for GitLab hosted repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Jun 25, 2018
1 parent 47e03a2 commit 98cc9e4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 55 deletions.
30 changes: 30 additions & 0 deletions .gitlab-ci.yml
@@ -0,0 +1,30 @@
stages:
- build
- test
- deploy
build-package:
stage: build
image: debian
script:
- apt update
- apt -y upgrade
- apt install -y curl
- curl -sL https://gitlab.com/hassbian/CI/raw/master/hassbian-scripts/build_and_test.sh | bash -s ${CI_COMMIT_REF_NAME}
test-package:
stage: test
image: debian
script:
- apt update
- apt -y upgrade
- apt install -y curl
- curl -sL https://gitlab.com/hassbian/CI/raw/master/hassbian-scripts/build_and_test.sh | bash -s ${CI_COMMIT_REF_NAME}
- apt -y install ${CI_PROJECT_DIR}/package.deb

deploy-to-repo:
stage: deploy
image: debian
script:
- apt update
- apt -y upgrade
- apt install -y curl git
- curl -sL https://gitlab.com/hassbian/CI/raw/master/hassbian-scripts/distribute.sh | bash -s ${CI_COMMIT_REF_NAME}
5 changes: 0 additions & 5 deletions docs/hassbian_config.md
Expand Up @@ -48,11 +48,6 @@ $ sudo apt install -y ./hassbian*
$ sudo hassbian-config upgrade hassbian-script
```

## Upgrade to prerelease
```
$ sudo hassbian-config upgrade hassbian-script --beta
```

## Upgrade to dev branch
```
$ sudo hassbian-config upgrade hassbian-script --dev
Expand Down
70 changes: 20 additions & 50 deletions package/opt/hassbian/suites/hassbian-script.sh
Expand Up @@ -12,68 +12,38 @@ function hassbian-script-show-copyright-info {
}

function hassbian-script-upgrade-package {

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"
devbranch="-dev"
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

echo "Downloading new scripts from github."
curl -L https://api.github.com/repos/home-assistant/hassbian-scripts/tarball| sudo tar xz --strip=1

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 "Removing the temporary folder."
cd || exit
sudo rm -r /tmp/hassbian_config_update
fi
echo "Updating apt information..."
echo "deb [trusted=yes] https://gitlab.com/hassbian/repository$devbranch/raw/master stretch main" | sudo tee /etc/apt/sources.list.d/hassbian.list
apt update

echo "Checking installed version..."
current_version=$(apt list hassbian-scripts | tail -1 | awk -F'[' '{print $NF}' | awk -F']' '{print $1}')
if [ "$current_version" != "installed" ]; then
echo "Removing old version of hassbian-scripts..."
apt purge -y hassbian-scripts
apt clean

echo "Installing newest version of hassbian-scripts..."
echo "deb [trusted=yes] https://gitlab.com/hassbian/repository$devbranch/raw/master stretch main" | sudo tee /etc/apt/sources.list.d/hassbian.list
apt update
apt install -y hassbian-scripts
else
echo "Changing to a temporary folder"
cd /tmp || exit

echo "Downloading latest release"
if [ "$BETA" == "true" ]; then
echo "Checking if there is an prerelease available..."
prerelease=$(curl https://api.github.com/repos/home-assistant/hassbian-scripts/releases | grep '"prerelease": true')
if [ ! -z "${prerelease}" ]; then
echo "Prerelease found..."
curl https://api.github.com/repos/home-assistant/hassbian-scripts/releases | grep "browser_download_url.*deb" | head -1 | cut -d : -f 2,3 | tr -d \" | wget -qi -
else
echo "Prerelease not found..."
echo "Downloading latest stable version..."
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 -
fi
else
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 -
fi

HASSBIAN_PACKAGE=$(echo hassbian*.deb)

echo "Installing latest release"
downloadedversion=$(echo "$HASSBIAN_PACKAGE" | awk -F'_' '{print $2}' | cut -d . -f 1,2,3)
currentversion=$(hassbian-config -V)
if [[ "$currentversion" > "$downloadedversion" ]]; then
apt install -y /tmp/"$HASSBIAN_PACKAGE" --allow-downgrades
else
apt install -y /tmp/"$HASSBIAN_PACKAGE" --reinstall
fi
echo "Cleanup"
rm "$HASSBIAN_PACKAGE"
echo "Installed version is up to date, exiting..."
return 0
fi

systemctl daemon-reload

echo
Expand All @@ -82,4 +52,4 @@ echo
return 0
}

[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead"
[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead"

0 comments on commit 98cc9e4

Please sign in to comment.