Skip to content

Commit

Permalink
Test 2 Main -> New Autostart Features (#3) 47 commits
Browse files Browse the repository at this point in the history
* Update deskthing-pi-installer.sh in test

* Update deskthing-pi-installer.sh test2

* Update deskthing-pi-installer.sh

* Update deskthing-pi-installer.sh

* Update deskthing-pi-installer.sh

* Update deskthing-pi-installer.sh

* Update deskthing-pi-installer.sh

* Update deskthing-pi-installer.sh

* Update deskthing-pi-installer.sh

* Update and install vite

* change order of statements

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Update deskthing-pi-installer.sh

* Update README.md

* Autostart feature added

* retry cd home

* path magic

* next try

* hochkomma

* realpath

* nextry

* ohnegleich?

* new try i guess

* anfuehrungszeichen

* .

* chattie

* wihtout

* hoch

* fixed

* installed

* try with usr/bin

* /usr/bin added

* usr/bin added 2

* retry document structure

* sudo

* new sudo commit

* changed service writing

* nvm npm optimization

* bash completion

* some permission changes now user service AGAIN

* nxt try

* test1

* sane?
  • Loading branch information
TIMBLOCKER authored Jan 15, 2025
1 parent 455dbf6 commit b607ac9
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 29 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@



<p align="center">
<img width="500" src="https://github.com/TIMBLOCKER/DeskThing-Pi/blob/ac63a235907ffbdf23b503e45caf5946f0584b99/readme_images/deskthing-PI.png" alt="DeskThing-Pi logo">
</p>
Expand Down Expand Up @@ -39,6 +36,7 @@ If you've set everything according up correctly you should be able to SSH into y
### Starting DeskThingClient
After the Setup has completed you should have one fullsize white window and the DeskThingServer Console running. Now you can install the client via the Server App. Just go to `Clients > Download Client`. After the download is completed just click `Refresh Client` and press `ESC`. This will trigger the Pi to restart the browser for the Client App. This will open the DeskThingPi in Kioskmode.


> Attention: You can always exit the Client App and go back to the DeskThingServer Settings by pressing ``ESC`` on the keyboard. The Client App will restart automatically after 10 Seconds.
## Current Limitations
Expand Down
182 changes: 156 additions & 26 deletions deskthing-pi-installer.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/bash
. $HOME

#Execute on ~/
#This installer will download and create all neccessary components to run DeskThing on Rapsberry Pi 4

Expand All @@ -23,48 +26,175 @@ echo "........... .......................................................
echo "................................................................................................................................."
echo "Step 1: Update/Upgrade Pi to newest Version"
echo "................................................................................................................................."
apt update
apt full-upgrade -y

sudo apt update
sudo apt full-upgrade -y


echo "................................................................................................................................."
echo "Step 2: Check and install dependencies (node/npm/electron/electron-vite)"
echo "................................................................................................................................."

#Check and Install nvm as a base for the deskthing-server
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

nvm install node


nvm install-latest-npm

#Check and Install node as a base for the deskthing-server
if which nodejs > /dev/null
then
echo "nodejs is installed - No installation needed"
else
echo "................................................................................................................................."
echo "Installing nodejs"
echo "................................................................................................................................."
apt install nodejs -y
fi

#Check and Install npm as a package manager for downloading repo
if which npm > /dev/null
then
echo "npm is installed - No installation needed"
else
echo "................................................................................................................................."
echo "Installing npm"
echo "................................................................................................................................."
apt install npm -y
fi


echo "................................................................................................................................."
echo "Step 3: Clone ItsRiprod/DeskThing and add dependencies"
echo "................................................................................................................................."

#Git clone DeskThing
git clone https://github.com/ItsRiprod/DeskThing DeskThing
git clone https://github.com/ItsRiprod/DeskThing $HOME/DeskThing

chmod 777 -R $HOME/DeskThing

cd DeskThing/DeskThingServer
cd $HOME/DeskThing/DeskThingServer

#Check and Install dependencies for running deskthing-client locally
npm install electron electron-vite @vitejs/plugin-react tailwindcss postcss autoprefixer vite

node -v > .nvmrc

nvm use

echo "................................................................................................................................."
echo "Step 4: Autostart DeskThing"
echo "................................................................................................................................."


cd ..

mkdir client_sandbox

cd client_sandbox

node -v > .nvmrc

nvm use

cat <<EOF > package.json
{
"name": "client_sandbox",
"version": "1.0.0",
"description": "",
"main": "starter.js",
"scripts": {
"start": "electron starter.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"electron": "^33.3.1"
}
}
EOF

cat <<EOF > starter.js
const { app, BrowserWindow, globalShortcut } = require('electron');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 1920, // Set the width of the window
height: 1080, // Set the height of the window
fullscreen: true, // Set the window to fullscreen
webPreferences: {
nodeIntegration: true, // Enable node integration (if needed)
},
});
mainWindow.loadURL("http://localhost:8891/"); // Load the URL
// Close the window if the 'Esc' key is pressed
mainWindow.webContents.on('keydown', (event) => {
if (event.key === 'Escape') {
app.quit(); // Close the application when the 'Esc' key is pressed
}
});
mainWindow.on('closed', () => {
mainWindow = null; // Cleanup when the window is closed
});
}
app.whenReady().then(() => {
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow(); // Recreate the window if all windows are closed (macOS)
}
});
// Register global shortcut (optional) to close the app on 'Esc'
globalShortcut.register('Esc', () => {
app.quit(); // Close the application when 'Esc' is pressed
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit(); // Quit the app if all windows are closed (except macOS)
}
});
EOF

npm init -y

npm install electron

cat <<EOF > /$HOME/.config/systemd/user/deskthing.service
[Unit]
Description=DeskThing Server Starter
After=network.target
[Service]
Type=simple
WorkingDirectory=$HOME/DeskThing/DeskThingServer
ExecStart=$HOME/.nvm/nvm-exec npm start
Restart=always
RestartSec=10
[Install]
WantedBy=default.target
EOF

cat <<EOF > /$HOME/.config/systemd/user/sandbox.service
[Unit]
Description=DeskThing Client Starter
After=deskthing.service
Requires=deskthing.service
[Service]
Type=simple
WorkingDirectory=$HOME/DeskThing/client_sandbox
ExecStart=$HOME/.nvm/nvm-exec npm start
Restart=always
RestartSec=10
[Install]
WantedBy=default.target
EOF

systemctl --user daemon-reload

systemctl --user enable deskthing.service
systemctl --user enable sandbox.service

systemctl --user start deskthing.service
systemctl --user start sandbox.service


echo "Setup finished!"

0 comments on commit b607ac9

Please sign in to comment.