Compare commits

...

2 Commits

Author SHA1 Message Date
Logan Cusano
7d4f48a446 #6 The bones
- Added a module to load addons
- Added an example module that just extends the socketIO connection to add an console log
2024-03-10 04:03:40 -04:00
Logan Cusano
b209a672c6 Improve the client setup script 2024-03-10 03:22:04 -04:00
4 changed files with 113 additions and 7 deletions

View File

@@ -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 # Update the system
echo "Updating system..." apt update
apt update && apt upgrade -y apt upgrade -y
# Install required dependencies: nodejs, ffmpeg # Install the necessary packages
echo "Installing dependencies..." 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 ####------------------- Install and setup node
# Run npm install to install dependencies listed in package.json # 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 # Reload systemd daemon
systemctl daemon-reload systemctl daemon-reload
systemctl enable discord-radio-bot.service
systemctl stop discord-radio-bot.service systemctl stop discord-radio-bot.service
echo "\n\n\t\tDiscord Client Node install completed!\n\n" echo "\n\n\t\tDiscord Client Node install completed!\n\n"
@@ -200,3 +241,21 @@ chown 1000:1000 .env
echo "Permissions set on the client directory!" 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

View 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
});
}

View 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.`);
})
}
});
}

View File

@@ -1,4 +1,5 @@
import { nodeIo, app, server } from './modules/socketServer.mjs'; import { nodeIo, app, server } from './modules/socketServer.mjs';
import { loadAddons } from './modules/addonManager.mjs';
import { serverClient, addEnabledEventListeners } from './discordBot/discordBot.mjs'; import { serverClient, addEnabledEventListeners } from './discordBot/discordBot.mjs';
import dotenv from 'dotenv'; import dotenv from 'dotenv';
@@ -7,3 +8,6 @@ dotenv.config()
// Add objects to the others // Add objects to the others
serverClient.nodeIo = nodeIo; serverClient.nodeIo = nodeIo;
nodeIo.serverClient = serverClient; nodeIo.serverClient = serverClient;
// Load the addons
loadAddons(nodeIo);