From 839b9ff101f71303ac3ac7851c0f3d7ed0a34a69 Mon Sep 17 00:00:00 2001 From: Shawn Bruce Date: Thu, 25 Mar 2021 22:41:52 -0400 Subject: [PATCH] Use docker to build packages Build deb w/ debhelper instead of electron-builder Remove ratpoison as OctoDash is the sole window. Create systemd service to launch OctoDash directly without a tty shell. Set systemd target to graphical. Incorperate xinit script into package. Create symlink for /usr/bin/octodash -> /opt/OctoDash/octodash Modify install/remove scripts to re-execute self with sudo. Deprecate using remove.sh. Removing via apt should be sufficient now. Add --version switch to octodash. Move release URL to environment variable Disable security when in dev mode (Bypass CORS checks) Remove update.sh Prevent remove.sh from running on newer installs --- Dockerfile | 46 +++++ Makefile | 19 ++ distribution/debian.sh | 44 +++++ distribution/debian/changelog | 5 + distribution/debian/compat | 1 + distribution/debian/control | 18 ++ distribution/debian/copyright | 22 +++ .../debian/local/etc/X11/xinit/octodash.xinit | 6 + .../debian/local/etc/default/octodash | 4 + distribution/debian/octodash.install | 1 + distribution/debian/octodash.links | 1 + distribution/debian/octodash.postinst | 63 ++++++ distribution/debian/octodash.postrm | 4 + distribution/debian/octodash.preinst | 20 ++ distribution/debian/octodash.service | 20 ++ distribution/debian/octodash.templates | 13 ++ distribution/debian/rules | 14 ++ helper/update.js | 179 +++++++++++------- main.js | 7 + package.json | 13 +- scripts/install.sh | 89 ++------- scripts/remove.sh | 43 ++++- scripts/update.sh | 22 --- src/app/app.service.ts | 3 +- src/environments/environment.prod.ts | 1 + src/environments/environment.ts | 1 + 26 files changed, 488 insertions(+), 171 deletions(-) create mode 100644 Dockerfile create mode 100644 Makefile create mode 100755 distribution/debian.sh create mode 100644 distribution/debian/changelog create mode 100644 distribution/debian/compat create mode 100644 distribution/debian/control create mode 100644 distribution/debian/copyright create mode 100755 distribution/debian/local/etc/X11/xinit/octodash.xinit create mode 100644 distribution/debian/local/etc/default/octodash create mode 100644 distribution/debian/octodash.install create mode 100644 distribution/debian/octodash.links create mode 100755 distribution/debian/octodash.postinst create mode 100755 distribution/debian/octodash.postrm create mode 100755 distribution/debian/octodash.preinst create mode 100644 distribution/debian/octodash.service create mode 100644 distribution/debian/octodash.templates create mode 100755 distribution/debian/rules mode change 100644 => 100755 scripts/remove.sh delete mode 100644 scripts/update.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..2146a2263 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,46 @@ +FROM debian:latest + +#TODO: Use version from package.json? +ENV NODE_VERSION 14.15.4 +ENV NVM_DIR /usr/local/nvm + + +RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections + +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + devscripts \ + debhelper \ + dh-systemd \ + jq \ + python3-pip \ + apt-transport-https \ + build-essential \ + ca-certificates \ + curl \ + git \ + libssl-dev \ + wget \ + rsync + + +RUN pip3 install yq + +RUN rm /bin/sh && ln -s /bin/bash /bin/sh + +RUN mkdir $NVM_DIR + +RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash \ + && . $NVM_DIR/nvm.sh \ + && nvm install $NODE_VERSION \ + && nvm alias default $NODE_VERSION \ + && nvm use default + +ENV NODE_PATH $NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules +ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH + +CMD rsync -av /src/ /build --exclude "package/" \ + && cd /build \ + && make build-internal \ + && BUILD_TIMESTAMP=$(date +%s) \ + && cp -rv "/build/package" "/package/${BUILD_TIMESTAMP}" diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..1069a3b59 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +SHELL := /bin/bash + +DOCKER_IMAGE_NAME="octodash/build" + +export + +all: + mkdir -p package && \ + docker build \ + -t ${DOCKER_IMAGE_NAME} . && \ + docker run -it --rm \ + -v "${PWD}":/src:ro \ + -v "${PWD}/package":/package \ + ${DOCKER_IMAGE_NAME} + +build-internal: + npm run pack + +clean: diff --git a/distribution/debian.sh b/distribution/debian.sh new file mode 100755 index 000000000..d57ef928d --- /dev/null +++ b/distribution/debian.sh @@ -0,0 +1,44 @@ +#!/bin/bash +set -e + +cd "$(dirname "$0")" + + +VERSION=$(yq -c -M .version ../package.json | tr -d \") +ARCHS=$(jq ".build.linux.target[0].arch[]" ../package.json | tr -d \") + +#hack for amd64 +ARCHS=$(echo "${ARCHS}" | sed 's/x64/amd64/g') +if [[ ( ! -L ../package/linux-amd64-unpacked ) && ( -d ../package/linux-unpacked ) ]] +then + ln -s ../package/linux-unpacked ../package/linux-amd64-unpacked +fi + + +for ARCH in `echo ${ARCHS}` +do + PACKAGE="linux-${ARCH}-unpacked" + + TMP_DIR=$(mktemp -d) + BUILD_DIR="${TMP_DIR}/build" + + mkdir -p "${BUILD_DIR}" + + + cp -prv debian "${BUILD_DIR}/debian" + cp -prv "../package/${PACKAGE}/" "${BUILD_DIR}/" + mv "${BUILD_DIR}/${PACKAGE}" "${BUILD_DIR}/package" + + pushd $BUILD_DIR + + sed -i "s:{version}:$VERSION:g;" debian/changelog + #sed -i "s:{arch}:$ARCH:g;" debian/control + + #debuild -b + debuild -b -uc -us + + popd + find "${TMP_DIR}" -maxdepth 1 -type f -name "*.deb" -exec cp -f "{}" "../package/octodash-${VERSION}-${ARCH}.deb" \; + rm -rf "${TMP_DIR}" + +done diff --git a/distribution/debian/changelog b/distribution/debian/changelog new file mode 100644 index 000000000..60a3eef43 --- /dev/null +++ b/distribution/debian/changelog @@ -0,0 +1,5 @@ +octodash ({version}) stable; urgency=low + + * Automatic Release. + + -- Name Sun, 01 Jan 1970 00:00:00 -0000 \ No newline at end of file diff --git a/distribution/debian/compat b/distribution/debian/compat new file mode 100644 index 000000000..f599e28b8 --- /dev/null +++ b/distribution/debian/compat @@ -0,0 +1 @@ +10 diff --git a/distribution/debian/control b/distribution/debian/control new file mode 100644 index 000000000..48443b644 --- /dev/null +++ b/distribution/debian/control @@ -0,0 +1,18 @@ +Source: octodash +Section: x11 +Priority: optional +Maintainer: Name +Homepage: https://github.com/UnchartedBull/OctoDash +Vcs-Git: https://github.com/UnchartedBull/OctoDash.git +Vcs-Browser: https://github.com/UnchartedBull/OctoDash +Build-Depends: debhelper (>= 9), + dh-systemd (>= 1.5) + +Package: octodash +Architecture: all +Depends: bc, desktop-file-utils, libappindicator3-1, libatspi2.0-0, libavahi-compat-libdnssd1, libgtk-3-0, libgtk-3-0, libnotify4, libnss3, libpam0g-dev, libsecret-1-0, libuuid1, libx11-dev, libxss1, libxtst6, rsync, x11-xserver-utils, xdg-utils, xinit, xserver-xorg +Description: OctoDash is a User Interface for OctoPrint, it utilizes the OctoPrint API + but tries to use modern design principles in order to fully enable the power of your + Raspberry Pi attached to your 3D Printer. OctoDash works best with a Touchscreen and + will support almost all functions that OctoPrint offers just in a nicer format. + diff --git a/distribution/debian/copyright b/distribution/debian/copyright new file mode 100644 index 000000000..0ef1b5082 --- /dev/null +++ b/distribution/debian/copyright @@ -0,0 +1,22 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: octodash +Source: https://github.com/UnchartedBull/OctoDash + +Files: * +Copyright: 20XX-20XX OctoDash + +License: Apache-2.0 + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + On Debian systems, the complete text of the Apache version 2.0 license + can be found in `/usr/share/common-licenses/Apache-2.0'. diff --git a/distribution/debian/local/etc/X11/xinit/octodash.xinit b/distribution/debian/local/etc/X11/xinit/octodash.xinit new file mode 100755 index 000000000..6d9906e22 --- /dev/null +++ b/distribution/debian/local/etc/X11/xinit/octodash.xinit @@ -0,0 +1,6 @@ +#!/bin/sh +xset s off +xset s noblank +xset -dpms + +octodash diff --git a/distribution/debian/local/etc/default/octodash b/distribution/debian/local/etc/default/octodash new file mode 100644 index 000000000..b298dd438 --- /dev/null +++ b/distribution/debian/local/etc/default/octodash @@ -0,0 +1,4 @@ +# Configuration for OctoDash + +# User to run OctoDash as. This will generally will be the same as OctoPrint +OCTODASH_USER= diff --git a/distribution/debian/octodash.install b/distribution/debian/octodash.install new file mode 100644 index 000000000..2fb9f609d --- /dev/null +++ b/distribution/debian/octodash.install @@ -0,0 +1 @@ +debian/local/* / diff --git a/distribution/debian/octodash.links b/distribution/debian/octodash.links new file mode 100644 index 000000000..dcafb1614 --- /dev/null +++ b/distribution/debian/octodash.links @@ -0,0 +1 @@ +/opt/OctoDash/octodash /usr/bin/octodash diff --git a/distribution/debian/octodash.postinst b/distribution/debian/octodash.postinst new file mode 100755 index 000000000..e9cad6600 --- /dev/null +++ b/distribution/debian/octodash.postinst @@ -0,0 +1,63 @@ +#!/bin/sh +set -e + +. /usr/share/debconf/confmodule + +db_get octodash/owning_user +USER="$RET" +db_get octodash/owning_group +GROUP="$RET" + + +THIS_PACKAGE=octodash +DEFAULT_DISPLAY_MANAGER_FILE=/etc/X11/default-display-manager +DEFAULT_SERVICE=/etc/systemd/system/display-manager.service + +# debconf is not a registry, so we only fiddle with the default file if +# the configure script requested an update +if [ -e $DEFAULT_DISPLAY_MANAGER_FILE.debconf-update ]; then + rm -f $DEFAULT_DISPLAY_MANAGER_FILE.debconf-update + if db_get shared/default-x-display-manager; then + # workaround debconf passthru bug (#379198) + if [ -z "$RET" ]; then + RET="$THIS_PACKAGE" + fi + if [ "$THIS_PACKAGE" != "$RET" ]; then + echo "Please be sure to run \"dpkg --configure $RET\"." + fi + if db_get "$RET"/daemon_name; then + echo "$RET" > $DEFAULT_DISPLAY_MANAGER_FILE + fi + fi +fi + + +if [ $1 = "configure" ]; then + if [ -d /etc/systemd/system/ ]; then + if [ -e "$DEFAULT_DISPLAY_MANAGER_FILE" ]; then + SERVICE=/lib/systemd/system/$(basename $(cat "$DEFAULT_DISPLAY_MANAGER_FILE") | awk '{print tolower($0)}').service + echo "Installing service $SERVICE" + if [ -h "$DEFAULT_SERVICE" ] && [ $(readlink "$DEFAULT_SERVICE") = /dev/null ]; then + echo "Display manager service is masked" >&2 + elif [ -e "$SERVICE" ]; then + ln -sf "$SERVICE" "$DEFAULT_SERVICE" + else + echo "WARNING: $SERVICE is the selected default display manager but does not exist" >&2 + rm -f "$DEFAULT_SERVICE" + fi + else + rm -f "$DEFAULT_SERVICE" + fi + fi + + + chown -R $USER:$GROUP /opt/OctoDash + chmod -R 775 /opt/OctoDash + + sed -i "s/OCTODASH_USER=\w*/OCTODASH_USER=${USER}/g" /etc/default/octodash + sed -i "s/^#*allowed_users=\w*$/allowed_users=anybody/g" /etc/X11/Xwrapper.config + + systemctl set-default graphical.target +fi + +exit 0 diff --git a/distribution/debian/octodash.postrm b/distribution/debian/octodash.postrm new file mode 100755 index 000000000..541a41f53 --- /dev/null +++ b/distribution/debian/octodash.postrm @@ -0,0 +1,4 @@ +#!/bin/sh +set -e + +exit 0 diff --git a/distribution/debian/octodash.preinst b/distribution/debian/octodash.preinst new file mode 100755 index 000000000..2b73b380d --- /dev/null +++ b/distribution/debian/octodash.preinst @@ -0,0 +1,20 @@ +#!/bin/sh +set -e + +. /usr/share/debconf/confmodule + +db_get octodash/owning_user +USER="$RET" +db_get octodash/owning_group +GROUP="$RET" + +if [ $1 = "install" ]; then + if ! getent group "$GROUP" >/dev/null; then + groupadd "$GROUP" + fi + if ! getent passwd "$USER" >/dev/null; then + adduser --system --no-create-home --ingroup "$GROUP" "$USER" + fi +fi + +exit 0 diff --git a/distribution/debian/octodash.service b/distribution/debian/octodash.service new file mode 100644 index 000000000..4504204b5 --- /dev/null +++ b/distribution/debian/octodash.service @@ -0,0 +1,20 @@ +[Unit] +Description=OctoDash +After=octoprint.service +Requires=graphical.target +Wants=network-online.target + +[Service] +Type=simple +EnvironmentFile=-/etc/default/octodash +Environment=DISPLAY=:0.0 +Environment=XINITRC=/etc/X11/xinit/octodash.xinit +ExecStart=/bin/su $OCTODASH_USER -w DISPLAY,XINITRC -l -c '/usr/bin/xinit -- -nocursor' +ExecStop=/bin/kill -TERM $MAINPID +TimeoutStopSec=30 +Restart=always +RestartSec=2 +StartLimitInterval=0 + +[Install] +WantedBy=graphical.target diff --git a/distribution/debian/octodash.templates b/distribution/debian/octodash.templates new file mode 100644 index 000000000..0e2e98161 --- /dev/null +++ b/distribution/debian/octodash.templates @@ -0,0 +1,13 @@ +Template: octodash/owning_user +Type: string +Default: pi +Description: octodash user: + Specify the user that is used to run octodash. The user will be created if it does not already exist. + The default 'pi' should work fine for most users. You can specify the user group next. + +Template: octodash/owning_group +Type: string +Default: pi +Description: octodash group: + Specify the group that is used to run octodash. The group will be created if it does not already exist. + If the user doesn't already exist then this group will be used as the user's primary group. diff --git a/distribution/debian/rules b/distribution/debian/rules new file mode 100755 index 000000000..105a62977 --- /dev/null +++ b/distribution/debian/rules @@ -0,0 +1,14 @@ +#!/usr/bin/make -f + +# Uncomment this to turn on verbose mode. +export DH_VERBOSE=1 + +%: + dh $@ --with=systemd + +# No init script, only systemd +override_dh_installinit: + true + +override_dh_install: + dh_install package/* /opt/OctoDash diff --git a/helper/update.js b/helper/update.js index 5807df602..cc27e5dfe 100644 --- a/helper/update.js +++ b/helper/update.js @@ -9,94 +9,139 @@ const stream = require('stream'); const { promisify } = require('util'); const progress = require('progress-stream'); +const args = process.argv.slice(1); +const dev = args.some(val => val === '--serve'); + const exec = require('child_process').exec; +if (dev) { + var rootPath = '/opt/OctoDash'; +} else { + //TODO : Detect app path + var rootPath = '/opt/OctoDash'; +} + function downloadUpdate(updateInfo, window) { - const downloadPath = '/tmp/octodash.deb'; + const tempPath = '/tmp'; const archMapping = { armv7l: 'armv7l', aarch64: 'arm64', x86_64: 'amd64', }; - exec('arch', (err, stdout, stderr) => { - if (err || stderr) { + fs.access(rootPath, fs.constants.W_OK, function(err) { + if (err) { window.webContents.send('updateError', { - error: err || { message: stderr }, + error: { + message: `${rootPath} is not writable!`, + }, }); - } - got(updateInfo.assetsURL) - .then(releaseFiles => { - const reducer = (accumulator, currentValue) => accumulator + currentValue; - const averageETA = []; - let downloadURL; - let packageSize; - for (const package of JSON.parse(releaseFiles.body)) { - if (package.name.includes(archMapping[stdout.trim()])) { - downloadURL = package.browser_download_url; - packageSize = package.size; - } - } - if (downloadURL) { - const downloadPipeline = promisify(stream.pipeline); - const downloadProgress = progress({ - length: packageSize, - time: 300, + } else { + exec('arch', (err, stdout, stderr) => { + if (err || stderr) { + window.webContents.send('updateError', { + error: err || { message: stderr }, }); + } + got(updateInfo.assetsURL) + .then(releaseFiles => { + const reducer = (accumulator, currentValue) => accumulator + currentValue; + const averageETA = []; + let downloadURL; + let packageSize; + let downloadPath; + let downloadFilename; + let packageName; + for (const package of JSON.parse(releaseFiles.body)) { + if (package.name.includes(archMapping[stdout.trim()]) && + package.name.endsWith(".tar.gz")) { + downloadURL = package.browser_download_url; + packageSize = package.size; + downloadFilename = package.name; - downloadProgress.on('progress', progress => { - averageETA.push(progress.eta); - if (averageETA.length > 4) averageETA.shift(); - window.webContents.send('updateDownloadProgress', { - percentage: progress.percentage, - transferred: (progress.transferred / 100000).toFixed(1), - total: (progress.length / 1000000).toFixed(1), - remaining: (progress.remaining / 100000).toFixed(1), - eta: new Date(averageETA.reduce(reducer) * 1000).toISOString().substr(14, 5), - runtime: new Date(progress.runtime * 1000).toISOString().substr(14, 5), - delta: (progress.delta / 100000).toFixed(1), - speed: (progress.speed / 1000000).toFixed(2), - }); - }); + downloadPath = tempPath + '/' + downloadFilename; - try { - if (fs.existsSync(downloadPath)) fs.unlinkSync(downloadPath); - } catch { - // no need to handle this properly - } + packageName = downloadFilename.replace('.tar.gz','').replace(/_/g,'-'); + } + } + if (downloadURL) { + const downloadPipeline = promisify(stream.pipeline); + const downloadProgress = progress({ + length: packageSize, + time: 300, + }); - downloadPipeline(got.stream(downloadURL), downloadProgress, fs.createWriteStream(downloadPath)) - .catch(error => { - window.webContents.send('updateError', { - error: { - message: `Can't download package! ${error.message}.`, - }, + downloadProgress.on('progress', progress => { + averageETA.push(progress.eta); + if (averageETA.length > 4) averageETA.shift(); + window.webContents.send('updateDownloadProgress', { + percentage: progress.percentage, + transferred: (progress.transferred / 100000).toFixed(1), + total: (progress.length / 1000000).toFixed(1), + remaining: (progress.remaining / 100000).toFixed(1), + eta: new Date(averageETA.reduce(reducer) * 1000).toISOString().substr(14, 5), + runtime: new Date(progress.runtime * 1000).toISOString().substr(14, 5), + delta: (progress.delta / 100000).toFixed(1), + speed: (progress.speed / 1000000).toFixed(2), + }); }); - }) - .then(() => { - window.webContents.send('updateDownloadFinished'); - exec('sudo ~/scripts/update-octodash', (err, _, stderr) => { - if (err || stderr) { + + try { + if (fs.existsSync(downloadPath)) fs.unlinkSync(downloadPath); + } catch { + // no need to handle this properly + } + + downloadPipeline(got.stream(downloadURL), downloadProgress, fs.createWriteStream(downloadPath)) + .catch(error => { window.webContents.send('updateError', { - error: err || { message: stderr }, + error: { + message: `Can't download package! ${error.message}.`, + }, }); - } else { - window.webContents.send('updateInstalled'); - } + }) + .then(() => { + window.webContents.send('updateDownloadFinished'); + exec(`tar zxvf ${downloadPath} -C ${tempPath}`, (err, _, stderr) => { + if (err || stderr) { + window.webContents.send('updateError', { + error: err || { message: stderr }, + }); + } else { + exec(`rsync -av --delete "${tempPath}/${packageName}/" "${rootPath}"`, (err, _, stderr) => { + if (err || stderr) { + window.webContents.send('updateError', { + error: err || { message: stderr }, + }); + } else { + exec(`rm -rf "${downloadPath}" "${tempPath}/${packageName}"`, (err, _, stderr) => { + if (err || stderr) { + window.webContents.send('updateError', { + error: err || { message: stderr }, + }); + } else { + window.webContents.send('updateInstalled'); + } + }); + } + }); + } + }); + }); + } else { + window.webContents.send('updateError', { + error: { + message: `Can't find matching package for architecture ${stdout}.`, + }, }); - }); - } else { - window.webContents.send('updateError', { - error: { - message: `Can't find matching package for architecture ${stdout}.`, - }, + } + }) + .catch(error => { + error.message = `Can't load releases. ${error.message}`; + window.webContents.send('updateError', { error }); }); - } - }) - .catch(error => { - error.message = `Can't load releases. ${error.message}`; - window.webContents.send('updateError', { error }); }); + } }); } diff --git a/main.js b/main.js index 2d04185cc..d1752a2c6 100644 --- a/main.js +++ b/main.js @@ -29,6 +29,12 @@ if (!dev) { app.commandLine.appendSwitch('touch-events', 'enabled'); +if (app.commandLine.hasSwitch('version')) { + console.log(app.getVersion()); + app.quit(); +} + + function createWindow() { const _store = new Store(); @@ -56,6 +62,7 @@ function createWindow() { enableRemoteModule: true, worldSafeExecuteJavaScript: true, contextIsolation: false, + webSecurity: !dev }, icon: path.join(__dirname, 'dist', 'assets', 'icon', 'icon.png'), }); diff --git a/package.json b/package.json index 7c9f3a657..3ed171671 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,15 @@ "linux": { "target": [ { - "target": "deb", + "target": "dir", + "arch": [ + "armv7l", + "arm64", + "x64" + ] + }, + { + "target": "tar.gz", "arch": [ "armv7l", "arm64", @@ -65,7 +73,7 @@ "electron:serve": "wait-on http-get://localhost:4200/ && electron . --serve", "electron:serve:big": "wait-on http-get://localhost:4200/ && electron . --serve --big", "electron:pack": "electron-builder build -l", - "pack": "npm run ng:build && npm run electron:pack", + "pack": "npm run ng:build && npm run electron:pack && ./distribution/debian.sh", "pack:mac": "npm run ng:build && electron-builder build -m", "ng:serve": "ng serve $npm_config_serve", "ng:build": "ng build --prod", @@ -94,6 +102,7 @@ "bonjour": "^3.5.0", "compare-versions": "^3.6.0", "electron-store": "^8.0.0", + "electron-root-path": "^1.0.16", "got": "^11.8.2", "lodash-es": "^4.17.21", "lottie-web": "^5.7.8", diff --git a/scripts/install.sh b/scripts/install.sh index 5d1eaecdc..0b286bf42 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -666,7 +666,12 @@ text_input() { ################## INQUIRER.SH ################## - +echo "This script requires root privileges. Please enter your sudo password when prompted." +sudo true +if [ $? -ne 0 ] +then + exit 1 +fi arch=$(uname -m) if [[ $arch == x86_64 ]]; then @@ -676,15 +681,11 @@ elif [[ $arch == aarch64 ]]; then elif [[ $arch == arm* ]]; then releaseURL=$(curl -s "https://api.github.com/repos/UnchartedBull/OctoDash/releases/latest" | grep "browser_download_url.*armv7l.deb" | cut -d '"' -f 4) fi -dependencies="libgtk-3-0 libnotify4 libnss3 libxss1 libxtst6 xdg-utils libatspi2.0-0 libuuid1 libappindicator3-1 libsecret-1-0 xserver-xorg ratpoison x11-xserver-utils xinit libgtk-3-0 bc desktop-file-utils libavahi-compat-libdnssd1 libpam0g-dev libx11-dev" + IFS='/' read -ra version <<< "$releaseURL" echo "Installing OctoDash "${version[7]}, $arch"" -echo "Installing Dependencies ..." -sudo apt -qq update -sudo apt -qq install $dependencies -y - if [ -d "/home/pi/OctoPrint/venv" ]; then DIRECTORY="/home/pi/OctoPrint/venv" elif [ -d "/home/pi/oprint" ]; then @@ -739,75 +740,21 @@ if [ $DIRECTORY != "-" ]; then fi; fi; -echo "Installing OctoDash "${version[7]}, $arch" ..." -cd ~ -wget -O octodash.deb $releaseURL -q --show-progress - -sudo dpkg -i octodash.deb - -rm octodash.deb - -yes_no=( 'yes' 'no' ) - -list_input "Should I setup OctoDash to automatically start on boot?" yes_no auto_start -echo $auto_start -if [ $auto_start == 'yes' ]; then - echo "Setting up Autostart ..." - cat < ~/.xinitrc -#!/bin/sh +echo "Downloading package..." +DEB_FILE=$(mktemp) +sudo wget "${releaseURL}" -O "${DEB_FILE}" -q --show-progress -xset s off -xset s noblank -xset -dpms -ratpoison& -octodash -EOF - - cat <> ~/.bashrc -if [ -z "\$SSH_CLIENT" ] || [ -z "\$SSH_TTY" ]; then - xinit -- -nocursor -fi -EOF - - echo "Setting up Console Autologin ..." - sudo systemctl set-default multi-user.target - sudo ln -fs /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty1.service - sudo bash -c 'cat > /etc/systemd/system/getty@tty1.service.d/autologin.conf' << EOF -[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin $USER --noclear %I \$TERM -EOF - - echo "Setting Permissions ..." - sudo chmod +x ~/.xinitrc - sudo chmod ug+s /usr/lib/xorg/Xorg - - echo "OctoDash will start automatically on next reboot. Please ensure that auto-login is enabled!" -fi - -list_input "Should I setup the update script? This will allow installing '~/tmp/octodash.deb' without sudo or root access. For more info visit the Update section of the wiki. " yes_no update -if [ $update == 'yes' ]; then - mkdir -p ~/scripts - echo "Setting up update script ..." - cat < ~/scripts/update-octodash -#!/bin/bash - -dpkg -i /tmp/octodash.deb -rm /tmp/octodash.deb -EOF +echo "Installing Dependencies ..." +dependencies=$(dpkg -I "${DEB_FILE}" | grep '^ Depends: ' | awk -F'Depends: ' ' { print $2 } ' | sed 's/,//g') +sudo apt -qq update +sudo apt -qq install $dependencies -y - sudo chmod +x ~/scripts/update-octodash - sudo bash -c 'cat >> /etc/sudoers.d/update-octodash' </dev/null| grep '^Version' | awk ' { print $2 } ') + +if [ -z "${VERSION}" ] +then + echo "Not installed" + exit 1 +fi + +VER_MAJOR=$(echo "${VERSION} | awk -F'.' ' { print $1 } '") +VER_MINOR=$(echo "${VERSION} | awk -F'.' ' { print $2 } '") +VER_PATCH=$(echo "${VERSION} | awk -F'.' ' { print $3 } '") + +if ![[ $VER_MAJOR -le 2 && $VER_MINOR -le 1 && $VER_PATCH -le 2 ]] +then + echo "This script is intended for OctoDash 2.1.2 and earlier. To remove execute the following commands:" + echo -e "\t systemctl stop octodash" + echo -e "\t apt remove octodash" + exit 1 +fi + echo "Removing OctoDash ..." + killall octodash -sudo dpkg -P octodash +dpkg -P octodash -rm -rf ~/.config/octodash/ +rm -rf /home/pi/.config/octodash/ -sed -i '/xset s off/d' ~/.xinitrc -sed -i '/xset s noblank/d' ~/.xinitrc -sed -i '/xset -dpms/d' ~/.xinitrc -sed -i '/ratpoison&/d' ~/.xinitrc -sed -i '/octodash/d' ~/.xinitrc +sed -i '/xset s off/d' /home/pi/.xinitrc +sed -i '/xset s noblank/d' /home/pi/.xinitrc +sed -i '/xset -dpms/d' /home/pi/.xinitrc +sed -i '/ratpoison&/d' /home/pi/.xinitrc +sed -i '/octodash/d' /home/pi/.xinitrc -echo "OctoDash has been removed :(. Please review your ~/.xinitrc and ~/.bashrc files to make sure everything got removed properly!" +echo "OctoDash has been removed :(. Please review your /home/pi/.xinitrc and /home/pi/.bashrc files to make sure everything got removed properly!" diff --git a/scripts/update.sh b/scripts/update.sh deleted file mode 100644 index c277141d8..000000000 --- a/scripts/update.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -arch=$(uname -m) -if [[ $arch == x86_64 ]]; then - releaseURL=$(curl -s "https://api.github.com/repos/UnchartedBull/OctoDash/releases/latest" | grep "browser_download_url.*amd64.deb" | cut -d '"' -f 4) -elif [[ $arch == aarch64 ]]; then - releaseURL=$(curl -s "https://api.github.com/repos/UnchartedBull/OctoDash/releases/latest" | grep "browser_download_url.*arm64.deb" | cut -d '"' -f 4) -elif [[ $arch == arm* ]]; then - releaseURL=$(curl -s "https://api.github.com/repos/UnchartedBull/OctoDash/releases/latest" | grep "browser_download_url.*armv7l.deb" | cut -d '"' -f 4) -fi - -echo "Updating OctoDash" - -cd ~ - -wget -O octodash.deb $releaseURL -q --show-progress - -sudo dpkg -i octodash.deb - -rm octodash.deb - -echo "Done. Restart your Raspberry Pi to start the newest version!" diff --git a/src/app/app.service.ts b/src/app/app.service.ts index 52fa92781..905c17a4c 100644 --- a/src/app/app.service.ts +++ b/src/app/app.service.ts @@ -3,6 +3,7 @@ import { Injectable } from '@angular/core'; import _ from 'lodash-es'; import { ElectronService } from 'ngx-electron'; +import { environment } from '../environments/environment'; import { Config } from './config/config.model'; import { ConfigService } from './config/config.service'; import { NotificationService } from './notification/notification.service'; @@ -53,7 +54,7 @@ export class AppService { } private checkUpdate(): void { - this.http.get('https://api.github.com/repos/UnchartedBull/OctoDash/releases/latest').subscribe( + this.http.get(environment.releaseCheckUrl).subscribe( (data: GitHubReleaseInformation): void => { if (this.version !== data.name.replace('v', '')) { this.updateAvailable = true; diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 6599b060a..77c1408a0 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,4 +1,5 @@ export const environment = { production: true, config: 'assets/config.json', + releaseCheckUrl: 'https://api.github.com/repos/UnchartedBull/OctoDash/releases/latest' }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 825adee70..5cea34cd9 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -5,6 +5,7 @@ export const environment = { production: false, config: 'assets/config.testing.json', + releaseCheckUrl: 'http://127.0.0.1:8888/latest' }; /*