diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..ff5e7893 --- /dev/null +++ b/.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} \ No newline at end of file diff --git a/docs/hassbian_config.md b/docs/hassbian_config.md index 86880a15..3f92f3ca 100644 --- a/docs/hassbian_config.md +++ b/docs/hassbian_config.md @@ -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 diff --git a/package/opt/hassbian/suites/hassbian-script.sh b/package/opt/hassbian/suites/hassbian-script.sh index aa9bf6ad..77b567f0 100644 --- a/package/opt/hassbian/suites/hassbian-script.sh +++ b/package/opt/hassbian/suites/hassbian-script.sh @@ -12,7 +12,6 @@ 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.'" @@ -20,60 +19,31 @@ if [ "$DEV" == "true" ]; then 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