Below is the software stack this script was tested on. This script should work on any Linux-based distribution, but your mileage may vary.
Software | Version |
---|---|
NodeJS | 17.3.0 |
Ubuntu | 20.04 LTS |
etherwake | 1.09 |
This tool requires that you setup passwordless sudo on the device used to start the computer because a raw Wake-On-Lan (WoL) network packet needs to be made and sent to be broadcasted.
It should be possible to only give a user permission to run the WoL tool with root although I haven't had any success with it.
🚨 Make sure that passwordless sudo has been setup 🚨
This tool uses etherwake to send WoL packets
on Ubuntu/Debian
sudo apt update
sudo apt install etherwake
The nodejs packages tend to be out dated on distros so one should use a tool like the node version manager (nvm) to install a spesifice version of node.
install nvm on Ubuntu/Debian
sudo apt update
sudo apt install curl curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
source ~/.bashrc
nvm install 17
nvm use 17
once in the repository directory run the following to install the needed dependencies
npm install
Rename the exmaple.env file to .env and change the mac address to the mac address of the computer you want to start and change the discord token to your discord token.
You can obtain a discord bot token by following this tutorial
Only if you want the discord bot to start on system startup.
In the computer-starter.service file one should change the User and group to that of their current user. the current user can be determined by running the whoami
command
after the user has been set change the WorkingDirectory to the location of the cloned repo this can be done by running the pwd
command while in the repo directory
The last config change that needs to be made is the ExecStart start line. "node" needs to be changed to the actual path of the node executable. you can find the path to the executable by running the which node
command.
change the owner of the service file to root and copy it to the systemd directory
sudo cp computer-starter.service /etc/systemd/system
sudo chown root:root /etc/systemd/system/computer-starter.service
sudo systemctl enable computer-starter --now
To use the bot invite it to a discord server, preferably with just yourself, one can then either direct message the bot or in a guild with .start
to start the computer or .ping
to test if it works.
Command | Description |
---|---|
.start | sends a WoL packet |
.ping | used to test if the discord bot is running |