### Start UpSnap Frontend (pnpm) Source: https://github.com/seriousm4x/upsnap/blob/master/README.md This snippet demonstrates how to start the UpSnap frontend development server. It includes installing dependencies using pnpm and running the development script. ```sh cd frontend pnpm i pnpm run dev ``` -------------------------------- ### Docker Compose: Install Additional Packages Source: https://github.com/seriousm4x/upsnap/blob/master/README.md This Docker Compose entrypoint shows how to install additional packages within the UpSnap container using Alpine Linux's apk package manager. It updates the package list, installs the specified package, and then cleans up the cache before starting the UpSnap server. ```yaml entrypoint: /bin/sh -c "apk update && apk add --no-cache && rm -rf /var/cache/apk/* && ./upsnap serve --http 0.0.0.0:8090" ``` -------------------------------- ### Start UpSnap Backend (Go) Source: https://github.com/seriousm4x/upsnap/blob/master/README.md This snippet shows how to start the UpSnap backend service. It involves navigating to the backend directory, tidying Go modules, and running the main application. ```sh cd backend go mod tidy go run main.go serve ``` -------------------------------- ### Install UpSnap from AUR Source: https://github.com/seriousm4x/upsnap/blob/master/README.md This command uses the `yay` AUR helper to install the `upsnap-bin` package on an Arch Linux system. It synchronizes package databases and then installs the specified package. ```bash yay -Sy upsnap-bin ``` -------------------------------- ### Develop Svelte Project Source: https://github.com/seriousm4x/upsnap/blob/master/frontend/README.md Commands to start the development server for a Svelte project after installing dependencies. Includes an option to automatically open the app in a browser. ```bash npm run dev # or start the server and open the app in a new browser tab npm run dev -- --open ``` -------------------------------- ### Run UpSnap Binary (Root) Source: https://github.com/seriousm4x/upsnap/blob/master/README.md This command starts the UpSnap server with root privileges, making it accessible on all network interfaces on port 8090. Ensure the binary is executable. ```bash sudo ./upsnap serve --http=0.0.0.0:8090 ``` -------------------------------- ### Bash Script: Wake, Rsync, Shutdown Device Source: https://github.com/seriousm4x/upsnap/wiki/Rest-API An example bash script demonstrating a full device management workflow. It authenticates with the Upsnap API, wakes a specified device, waits for it to come online, performs an rsync operation, and then shuts down the device. ```bash #!/bin/bash # Configurations UPSNAP_URL="http://localhost" UPSNAP_USER="YOUR_EMAIL" UPSNAP_PASSWORD="YOUR_PASSWORD" UPSNAP_DEVICE_ID="YOUR_DEVICE_ID" TIMEOUT=120 # Get authentication token AUTH_TOKEN=$(curl -s -X POST "$UPSNAP_URL/api/collections/_superusers/auth-with-password" \ -H "Content-Type: application/json" \ -d "{\"identity\": \"$UPSNAP_USER\", \"password\": \"$UPSNAP_PASSWORD\"}" | jq -r '.token') if [[ -z "$AUTH_TOKEN" ]]; then echo "Auth token is empty. Failed to authenticate. Exiting." exit 1 fi echo "Authentication successful. Token acquired." # Wake up the device curl -s "$UPSNAP_URL/api/upsnap/wake/$UPSNAP_DEVICE_ID" \ -H "Authorization: Bearer $AUTH_TOKEN" echo "Wake request sent. Waiting $TIMEOUT seconds for the device to come online..." # Wait until the device is online START_TIME=$(date +%s) while true; do STATUS=$(curl -s "$UPSNAP_URL/api/collections/devices/records/$UPSNAP_DEVICE_ID" \ -H "Authorization: Bearer $AUTH_TOKEN" | jq -r '.status') if [[ "$STATUS" == "online" ]]; then echo "Device is online!" break fi CURRENT_TIME=$(date +%s) ELAPSED_TIME=$((CURRENT_TIME - START_TIME)) if [[ $ELAPSED_TIME -ge $TIMEOUT ]]; then echo "Timeout reached. Device did not come online. Exiting." exit 1 fi sleep 1 done # Perform rsync rsync -avz --progress src/ target/ # Shutdown the device curl -s "$UPSNAP_URL/api/upsnap/shutdown/$UPSNAP_DEVICE_ID" \ -H "Authorization: Bearer $AUTH_TOKEN" echo "Shutdown request sent." ``` -------------------------------- ### Run UpSnap Binary (Non-root) Source: https://github.com/seriousm4x/upsnap/blob/master/README.md This snippet shows how to run UpSnap as a non-root user. It first grants raw socket capabilities to the binary using setcap, allowing it to perform network operations. Then, it starts the server on port 8090. ```bash sudo setcap cap_net_raw=+ep ./upsnap # only once after downloading ./upsnap serve --http=0.0.0.0:8090 ``` -------------------------------- ### Shutdown Windows Computer using net rpc Source: https://github.com/seriousm4x/upsnap/wiki/How-to-use-shutdowns This example demonstrates how to shut down a Windows computer using the `net rpc` command. It requires specifying the IP address, username, and password for the target machine. ```shell net rpc shutdown -I 192.168.1.13 -U "user%password" ``` -------------------------------- ### Add Custom Alpine Packages to Docker Container Source: https://github.com/seriousm4x/upsnap/wiki/How-to-use-shutdowns This snippet shows how to add custom packages to the UpSnap Docker container by modifying the `docker-compose.yml` file. It involves updating the package list, installing the desired package, cleaning the cache, and then starting the UpSnap server. ```yaml entrypoint: /bin/sh -c "apk update && apk add --no-cache && rm -rf /var/cache/apk/* && ./upsnap serve --http 0.0.0.0:8090" ``` -------------------------------- ### Shutdown Linux Computer using sshpass Source: https://github.com/seriousm4x/upsnap/wiki/How-to-use-shutdowns This example shows how to shut down a Linux computer remotely using `sshpass` for password authentication and `ssh` to execute the `poweroff` command. It includes disabling strict host key checking for convenience. ```shell sshpass -p your_password ssh -o "StrictHostKeyChecking=no" user@hostname "sudo poweroff" ``` -------------------------------- ### Shutdown Linux Computer using sshpass (root) Source: https://github.com/seriousm4x/upsnap/wiki/How-to-use-shutdowns This example demonstrates shutting down a Linux computer using `sshpass` with root credentials. It connects via SSH to the specified IP address and executes the `poweroff` command, disabling strict host key checking. ```shell sshpass -p password1234 ssh -o "StrictHostKeyChecking=no" root@192.168.0.50 "sudo poweroff" ``` -------------------------------- ### Build Svelte Project Source: https://github.com/seriousm4x/upsnap/blob/master/frontend/README.md Command to create a production-ready build of the Svelte application. Also mentions the command to preview the production build. ```bash npm run build You can preview the production build with `npm run preview`. ``` -------------------------------- ### Caddy Reverse Proxy Configuration Source: https://github.com/seriousm4x/upsnap/blob/master/README.md This Caddyfile configuration sets up a reverse proxy for UpSnap. It directs all traffic for 'upsnap.example.com' to the UpSnap service running on 'localhost:8090'. ```caddyfile upsnap.example.com { reverse_proxy localhost:8090 } ``` -------------------------------- ### Create Svelte Project Source: https://github.com/seriousm4x/upsnap/blob/master/frontend/README.md Commands to create a new Svelte project using npm. You can create a project in the current directory or specify a project name. ```bash npm create svelte@latest # create a new project in my-app npm create svelte@latest my-app ``` -------------------------------- ### SvelteKit Theme Management Source: https://github.com/seriousm4x/upsnap/blob/master/frontend/src/app.html Manages theme switching by reading from local storage or system preferences. It applies the theme to the document's root element and listens for changes in system preference to update the theme accordingly. ```javascript const darkTheme = 'dim'; const lightTheme = 'silk'; const preferesDark = window.matchMedia('(prefers-color-scheme: dark)').matches; const theme = localStorage.getItem('theme') ? localStorage.getItem('theme') : preferesDark ? darkTheme : lightTheme; document.documentElement.setAttribute('data-theme', theme); window.matchMedia('(prefers-color-scheme: dark)') .addEventListener('change', ({ matches }) => { matches ? document.documentElement.setAttribute('data-theme', darkTheme) : document.documentElement.setAttribute('data-theme', lightTheme); }); ``` -------------------------------- ### Format and Lint Project Source: https://github.com/seriousm4x/upsnap/wiki/How-to-add-languages These commands are used to format the project's code according to predefined style guidelines and to run linters to check for potential errors or code quality issues. This ensures consistency and helps maintain a healthy codebase. ```zsh pnpm run format pnpm run lint ``` -------------------------------- ### PocketBase API Endpoints for Devices Source: https://github.com/seriousm4x/upsnap/wiki/Rest-API Provides common PocketBase API endpoints for managing 'devices' records. These include fetching all devices, a single device by ID, updating a device, and deleting a device. ```json [GET] /api/collections/devices/records ``` ```json [GET] /api/collections/devices/records/:id ``` ```json [PATCH] /api/collections/devices/records/:id ``` ```json [DELETE] /api/collections/devices/records/:id ``` -------------------------------- ### Docker Compose: Change Port Source: https://github.com/seriousm4x/upsnap/blob/master/README.md This YAML configuration demonstrates how to change the default port for UpSnap when running via Docker Compose. It updates the entrypoint to serve on port 5000 and adjusts the healthcheck to match the new port. ```yaml entrypoint: /bin/sh -c "./upsnap serve --http 0.0.0.0:5000" healthcheck: test: curl -fs "http://localhost:5000/api/health" || exit 1 ``` -------------------------------- ### Authenticate with PocketBase API Source: https://github.com/seriousm4x/upsnap/wiki/Rest-API This snippet shows how to authenticate with the PocketBase API using a username/email and password to obtain a JWT token. It's a prerequisite for accessing protected API routes. ```json { "identity": "username or email", "password": "password" } ``` -------------------------------- ### Upsnap Custom API Endpoints Source: https://github.com/seriousm4x/upsnap/wiki/Rest-API Details the custom API endpoints provided by the Upsnap project for device control. These include actions like waking, sleeping, rebooting, shutting down, and network scanning. ```json [GET] /api/upsnap/wake/:id ``` ```json [GET] /api/upsnap/wakegroup/:id ``` ```json [GET] /api/upsnap/sleep/:id ``` ```json [GET] /api/upsnap/reboot/:id ``` ```json [GET] /api/upsnap/shutdown/:id ``` ```json [GET] /api/upsnap/scan ``` -------------------------------- ### Create New Branch for i18n Source: https://github.com/seriousm4x/upsnap/wiki/How-to-add-languages This command creates a new Git branch specifically for adding internationalization (i18n) support for a given language. Replace 'LANG' with the desired language code (e.g., 'en' for English). ```zsh git switch -c add-i18n-en ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.