Compare commits
2 Commits
7983670c81
...
7d4f48a446
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d4f48a446 | ||
|
|
b209a672c6 |
@@ -56,15 +56,55 @@ prompt_nearby_system() {
|
||||
},"
|
||||
}
|
||||
|
||||
####------------------- Initial Prereqs and init steps
|
||||
# Install Node Repo
|
||||
# Get the CPU architecture
|
||||
cpu_arch=$(uname -m)
|
||||
|
||||
# Print the CPU architecture for verification
|
||||
echo "Detected CPU Architecture: $cpu_arch"
|
||||
|
||||
# Check if the architecture is ARMv6
|
||||
if [[ "$cpu_arch" == "armv6"* ]]; then
|
||||
echo "----- CPU Architecture is ARMv6 or compatible. -----"
|
||||
echo "----- CPU Architectre is not compatible with dependencies of this project, please use a newer CPU architecture -----"
|
||||
exit
|
||||
|
||||
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
|
||||
|
||||
# Update the system
|
||||
echo "Updating system..."
|
||||
apt update && apt upgrade -y
|
||||
apt update
|
||||
apt upgrade -y
|
||||
|
||||
# Install required dependencies: nodejs, ffmpeg
|
||||
# Install the necessary packages
|
||||
echo "Installing dependencies..."
|
||||
apt install -y nodejs ffmpeg git
|
||||
apt install -y nodejs portaudio19-dev libportaudio2 libpulse-dev pulseaudio apulse git ffmpeg git
|
||||
|
||||
echo "Setting up Pulse Audio"
|
||||
|
||||
# Ensure pulse audio is running as system so the service can see the audio device
|
||||
systemctl --global disable pulseaudio.service pulseaudio.socket
|
||||
|
||||
# Update the PulseAudio config to disable autospawning
|
||||
sed -i 's/autospawn = .*$/autospawn = no/' /etc/pulse/client.conf
|
||||
|
||||
# Add the system PulseAudio service
|
||||
echo "[Unit]
|
||||
Description=PulseAudio system server
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
ExecStart=pulseaudio --daemonize=no --system --realtime --log-target=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target" >> /etc/systemd/system/PulseAudio.service
|
||||
|
||||
# Add the root user to the pulse-access group
|
||||
usermod -aG pulse-access root
|
||||
usermod -aG pulse-access pi
|
||||
|
||||
# Enable the PulseAudio service
|
||||
systemctl enable PulseAudio.service
|
||||
systemctl stop PulseAudio.service
|
||||
|
||||
####------------------- Install and setup node
|
||||
# Run npm install to install dependencies listed in package.json
|
||||
@@ -142,6 +182,7 @@ echo "$service_content" > /etc/systemd/system/discord-radio-bot.service
|
||||
|
||||
# Reload systemd daemon
|
||||
systemctl daemon-reload
|
||||
systemctl enable discord-radio-bot.service
|
||||
systemctl stop discord-radio-bot.service
|
||||
|
||||
echo "\n\n\t\tDiscord Client Node install completed!\n\n"
|
||||
@@ -199,4 +240,22 @@ chown -R 1000:1000 ./*
|
||||
chown 1000:1000 .env
|
||||
echo "Permissions set on the client directory!"
|
||||
|
||||
echo "\n\n\t\tNode installation Complete!"
|
||||
echo "\n\n\t\tNode installation Complete!"
|
||||
|
||||
# Prompt the user for reboot confirmation
|
||||
read -p "This script has installed all required components for the DRB client. Are you okay with rebooting? If not, you will have to reboot later before running the applications to finish the installation. (Reboot?: y/n): " confirm
|
||||
|
||||
# Convert user input to lowercase for case-insensitive comparison
|
||||
confirm="${confirm,,}"
|
||||
|
||||
#echo "To configure the app, please go to http://$nodeIP:$nodePort" # TODO - uncomment when webapp is built
|
||||
echo "Thank you for joining the network!"
|
||||
|
||||
if [[ "$confirm" != "y" && "$confirm" != "yes" ]]; then
|
||||
# Prompt user to press any key before rebooting
|
||||
read -rsp $'System will now reboot, press any key to continue or Ctrl+C to cancel...\n' -n1 key
|
||||
echo "Rebooting..."
|
||||
reboot
|
||||
else
|
||||
echo "Please restart your device to complete the installation"
|
||||
fi
|
||||
17
server/addons/example/index.js.ex
Normal file
17
server/addons/example/index.js.ex
Normal file
@@ -0,0 +1,17 @@
|
||||
// Function called by the main application to initialize the addon
|
||||
export function initialize(io) {
|
||||
console.log('Initializing addon1');
|
||||
|
||||
// Call other functions within the addon module
|
||||
registerSocketEvents(io);
|
||||
// Call additional initialization functions if needed
|
||||
}
|
||||
|
||||
// Function to register Socket.IO event handlers
|
||||
function registerSocketEvents(io) {
|
||||
io.on('connection', (socket) => {
|
||||
console.log('A client connected from addon1');
|
||||
|
||||
// Add more event handlers if needed
|
||||
});
|
||||
}
|
||||
26
server/modules/addonManager.mjs
Normal file
26
server/modules/addonManager.mjs
Normal file
@@ -0,0 +1,26 @@
|
||||
import { fileURLToPath } from 'url';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
// Function to load addons from the addons directory
|
||||
export const loadAddons = async (nodeIo) => {
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const addonsDir = path.join(__dirname, '../addons');
|
||||
|
||||
// Read the directory containing addon modules
|
||||
const addonDirectories = await fs.readdirSync(addonsDir, { withFileTypes: true });
|
||||
|
||||
addonDirectories.forEach(addonDir => {
|
||||
if (addonDir.isDirectory()) {
|
||||
const addonPath = path.join(addonsDir, addonDir.name, 'index.js');
|
||||
|
||||
import(`file://${addonPath}`).then(addon => {
|
||||
console.log("Loading addon: ", addon);
|
||||
addon.initialize(nodeIo);
|
||||
console.log(`Addon ${addonDir.name} loaded.`);
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { nodeIo, app, server } from './modules/socketServer.mjs';
|
||||
import { loadAddons } from './modules/addonManager.mjs';
|
||||
import { serverClient, addEnabledEventListeners } from './discordBot/discordBot.mjs';
|
||||
|
||||
import dotenv from 'dotenv';
|
||||
@@ -6,4 +7,7 @@ dotenv.config()
|
||||
|
||||
// Add objects to the others
|
||||
serverClient.nodeIo = nodeIo;
|
||||
nodeIo.serverClient = serverClient;
|
||||
nodeIo.serverClient = serverClient;
|
||||
|
||||
// Load the addons
|
||||
loadAddons(nodeIo);
|
||||
Reference in New Issue
Block a user