-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: unbuffer sideload + validate (#72)
* add: side-load expect durin runtime * feat: declare not_ready on missing dependencies
- Loading branch information
1 parent
4614952
commit dfc1ae7
Showing
6 changed files
with
62 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
import type {Socket} from 'socket.io-client'; | ||
import {scopedLogger} from '../lib/logger.js'; | ||
import type {ProbeLocation} from '../types.js'; | ||
import {hasRequired as hasRequiredDeps} from '../lib/dependencies.js'; | ||
|
||
const logger = scopedLogger('api:connect'); | ||
|
||
export const apiConnectLocationHandler = (data: ProbeLocation): void => { | ||
export const apiConnectLocationHandler = (socket: Socket) => async (data: ProbeLocation): Promise<void> => { | ||
logger.info(`connected from (${data.city}, ${data.country}, ${data.continent}) (lat: ${data.latitude} long: ${data.longitude})`); | ||
|
||
if (await hasRequiredDeps()) { | ||
console.log('yup its all here'); | ||
socket.emit('probe:status:ready', {}); | ||
} else { | ||
socket.emit('probe:status:not_ready', {}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import path, {dirname} from 'node:path'; | ||
import {fileURLToPath} from 'node:url'; | ||
import {execa} from 'execa'; | ||
|
||
const appDir = path.join(dirname(fileURLToPath(import.meta.url)), '..'); | ||
|
||
export const loadAll = async () => { | ||
await loadUnbuffer(); | ||
}; | ||
|
||
export const loadUnbuffer = async () => { | ||
await execa(path.join(appDir, 'sh', 'unbuffer.sh')); | ||
}; | ||
|
||
export const hasRequired = async () => isUnbufferAvailable(); | ||
|
||
export const isUnbufferAvailable = async () => { | ||
try { | ||
await execa('which', ['unbuffer']); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
# temp code that installs unbuffer without the need to pull the container again | ||
# remove this code in about 3-4 months when all probes should have the container pulled | ||
ARCHLOCAL=$(dpkg --print-architecture) | ||
|
||
if [[ ! -f "/usr/bin/unbuffer" ]]; then | ||
|
||
curl "http://ftp.nl.debian.org/debian/pool/main/e/expect/tcl-expect_5.45.4-2+b1_${ARCHLOCAL}.deb" -o "/tmp/tcl-expect.deb" | ||
dpkg --extract "/tmp/tcl-expect.deb" / | ||
|
||
curl "http://ftp.nl.debian.org/debian/pool/main/t/tcl8.6/libtcl8.6_8.6.11+dfsg-1_${ARCHLOCAL}.deb" -o "/tmp/libtcl.deb" | ||
dpkg --extract "/tmp/libtcl.deb" / | ||
|
||
curl "http://ftp.nl.debian.org/debian/pool/main/t/tcl8.6/tcl8.6_8.6.11+dfsg-1_${ARCHLOCAL}.deb" -o "/tmp/tcl.deb" | ||
dpkg --extract "/tmp/tcl.deb" / | ||
|
||
curl "http://ftp.nl.debian.org/debian/pool/main/e/expect/expect_5.45.4-2+b1_${ARCHLOCAL}.deb" -o "/tmp/expect.deb" | ||
dpkg --extract "/tmp/expect.deb" / | ||
|
||
fi | ||
# end temp code |