Skip to content

Commit ae4b4ac

Browse files
authored
Installation fix, wind in knots, etc. (#56)
* Added option to display wind speed in knots, in combination with either imperial or metric units. * Fixed build error possibly triggered by some unknown security update. * Fixed possible out-of-memory error during installation on Raspberry Pi with only 1 GB RAM. * Fixed Settings dialog layout when indoor/outdoor temperature options are disabled.
1 parent c612319 commit ae4b4ac

25 files changed

Lines changed: 8783 additions & 15244 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# compiled output
44
/dist
5+
/tsc-out
56
/server/dist
67
/server/tsc-out
78
/tmp

CHANGELOG.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
## 2.10.0
2+
3+
* Added option to display wind speed in knots, in combination with either imperial or metric units.
4+
* Fixed build error possibly triggered by some unknown security update.
5+
* Fixed possible out-of-memory error during installation on Raspberry Pi with only 1 GB RAM.
6+
* Fixed Settings dialog layout when indoor/outdoor temperature options are disabled.
7+
18
## 2.9.3
29

310
* Moved settings button into lower right corner.
411
* Improved retrieval and display of ΔTAI/ΔUT1.
5-
* Fix browser Reload button.
12+
* Fixed browser Reload button.
613
* Provided option to disable kiosk mode for auto-start browser.
714
* Server stability improvements.
8-
* Reduce calls to Google geocoding API.
15+
* Reduced calls to Google geocoding API.
916

1017
## 2.9.2
1118

@@ -30,9 +37,9 @@
3037

3138
## 2.8.2
3239

33-
* Update timezones to 2020d.
34-
* Fix and improve ephemeris rise/set tracks.
35-
* Fix Raspbian detection.
40+
* Updated timezones to 2020d.
41+
* Fixed and improve ephemeris rise/set tracks.
42+
* Fixed Raspbian detection.
3643

3744
## 2.8.0
3845

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ When connecting the 433 MHz receiver module follow the same precautions as speci
107107

108108
<img src="https://shetline.com/readme/aw-clock/2.8.0/wind_barbs.png" width=820 height=55 alt="wind barbs">
109109

110-
Wind speed is displayed using *wind barbs*. When using imperial units, the wind barbs represent wind speed in knots, rounded to the nearest multiple of 5 knots, up to a maximum of 100 knots. In metric mode the wind barbs represent wind speed in meters per second, in increments of 2.5 m/s (in the diagram above, divide the captions by 2 for m/s).
110+
Wind speed is displayed using *wind barbs*. When using imperial units, the wind barbs represent wind speed in knots, rounded to the nearest multiple of 5 knots, up to a maximum of 100 knots. In metric mode the wind barbs, by default, represent wind speed in meters per second, in increments of 2.5 m/s (in the diagram above, divide the captions by 2 for m/s).
111+
112+
In the Settings dialog, however, you can choose to display wind speed in knots while still using metric (°C, cm) for temperature and precipitation. When using imperial units (°F, in) wind speed (apart from wind barbs) is by default shown in mph, but you can optionally use knots for the textual display of wind speed as well.
111113

112114
| &nbsp; | Imperial | Metric |
113115
| --------- | -------- | ------- |
@@ -326,3 +328,5 @@ For reference, here’s a break down of the steps performed by a full installati
326328
To greatly improve the speed and reliability of automated installations and updates, the often troublesome node-sass has been moved into a separate `sass` directory. To set up node-sass, `cd` into the `sass` directory and enter `npm i`. This prepares you for translating the source file `styles.scss` into `styles.css`.
327329

328330
Once this is set up, you can use `npm run build:sass` to make sure any changes you make to `styles.scss` are carried over into `styles.css`. `styles.css` is also automatically updated any time you use `npm start`.
331+
332+
To update any changes made to `build.ts`, use `npm run build:build`

build.js

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ if [ -f "node_path.txt" ]; then
2323
if [ "$path" == "failed" ]; then
2424
exit;
2525
elif [ -n "$path" ]; then
26-
echo "here"
2726
args=(--path \""$path"\")
2827
path="${args[*]}"
2928
fi
3029
fi
3130

3231
echo "Starting main installer..."
3332
# shellcheck disable=SC2090,SC2048,SC2086
34-
npm run build:prod -- $path --bash $*
33+
node build.js -p $path --bash $*

build.ts

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as Chalk from 'chalk';
22
import { exec } from 'child_process';
3-
import * as copyfiles from 'copyfiles';
43
import * as fs from 'fs';
4+
import * as os from 'os';
55
import * as readline from 'readline';
66
import { Key } from 'readline';
77
import { asLines, isFunction, isNumber, isObject, isString, processMillis, toBoolean, toNumber } from '@tubular/util';
@@ -10,6 +10,14 @@ import { convertPinToGpio } from './server/src/rpi-pin-conversions';
1010
import { ErrorMode, getSudoUser, getUserHome, monitorProcess, monitorProcessLines, sleep, spawn } from './server/src/process-util';
1111
import { promisify } from 'util';
1212

13+
const enoughRam = os.totalmem() / 0x40000000 > 1.5;
14+
15+
// Deal with weird issue where 'copyfiles' gets imported in an inconsistent manner.
16+
let copyfiles: any = require('copyfiles');
17+
18+
if (copyfiles.default)
19+
copyfiles = copyfiles.default;
20+
1321
readline.emitKeypressEvents(process.stdin);
1422
process.stdin.setRawMode(true);
1523

@@ -452,7 +460,18 @@ function getWebpackSummary(s: string): string {
452460

453461
async function npmInit(): Promise<void> {
454462
if (!npmInitDone) {
455-
await monitorProcess(spawn('npm', ['init', '--yes'], { cwd: path.join(__dirname, 'server', 'dist') }), spin);
463+
const file = path.join(__dirname, 'server', 'dist', 'package.json');
464+
const packageJson = {
465+
name: 'aw-clock-server',
466+
version: '0.0.0',
467+
description: 'AW-Clock Server',
468+
main: 'app.js',
469+
license: 'MIT',
470+
dependencies: {}
471+
};
472+
473+
fs.writeFileSync(file, JSON.stringify(packageJson, null, 2));
474+
await monitorProcess(spawn('chown', [user, file]), spin, ErrorMode.ANY_ERROR);
456475
npmInitDone = true;
457476
}
458477
}
@@ -882,7 +901,12 @@ async function doClientBuild(): Promise<void> {
882901
await monitorProcess(spawn('rm', uid, ['-Rf', 'dist']), spin);
883902

884903
const opts = { shell: true, env: process.env };
885-
const output = getWebpackSummary(await monitorProcess(spawn('webpack', uid, prod ? ['--env', 'mode=prod'] : [], opts), spin));
904+
const args = ['run', 'build:client' + (enoughRam ? '' : ':tiny')];
905+
906+
if (prod)
907+
args.push('--', '--env', 'mode=prod');
908+
909+
const output = getWebpackSummary(await monitorProcess(spawn('npm', uid, args, opts), spin));
886910

887911
stepDone();
888912

@@ -905,26 +929,32 @@ async function doServerBuild(): Promise<void> {
905929
await monitorProcess(spawn('rm', uid, ['-Rf', 'server/dist']), spin);
906930

907931
const opts = { shell: true, cwd: path.join(__dirname, 'server'), env: process.env };
908-
const output = getWebpackSummary(await monitorProcess(spawn('npm', uid, ['run', isWindows ? 'build-win' : 'build'], opts), spin));
932+
const output = getWebpackSummary(await monitorProcess(spawn('npm', uid,
933+
['run', isWindows ? 'build-win' : 'build' + (enoughRam ? '' : ':tiny')], opts), spin));
909934

910935
stepDone();
911936

912937
if (output?.trim())
913938
console.log(chalk.mediumGray(output));
914939

915-
if (doAcu) {
940+
if (doAcu || doDht) {
916941
showStep();
917-
write('Adding Acu-Rite wireless temperature/humidity sensor support' + trailingSpace);
918-
await npmInit();
919-
await monitorProcess(spawn('npm', uid, ['i', 'rpi-acu-rite-temperature@2.x'], { cwd: path.join(__dirname, 'server', 'dist') }), spin);
920-
stepDone();
921-
}
922942

923-
if (doDht) {
924-
showStep();
925-
write('Adding DHT wired temperature/humidity sensor support' + trailingSpace);
943+
const args = ['i', '-P', 'rpi-acu-rite-temperature@2', 'node-dht-sensor@0.4'];
944+
945+
if (doAcu && doDht)
946+
write('Adding wireless and wired temp/humidity sensor support' + trailingSpace);
947+
else if (doAcu) {
948+
args.splice(3, 1);
949+
write('Adding Acu-Rite wireless temperature/humidity sensor support' + trailingSpace);
950+
}
951+
else {
952+
args.splice(2, 1);
953+
write('Adding DHT wired temperature/humidity sensor support' + trailingSpace);
954+
}
955+
926956
await npmInit();
927-
await monitorProcess(spawn('npm', uid, ['i', 'node-dht-sensor@0.4.x'], { cwd: path.join(__dirname, 'server', 'dist') }), spin);
957+
await monitorProcess(spawn('npm', uid, args, { cwd: path.join(__dirname, 'server', 'dist') }), spin);
928958
stepDone();
929959
}
930960
}
@@ -1053,8 +1083,7 @@ async function doServiceDeployment(): Promise<void> {
10531083
totalSteps += noStop ? 0 : 1;
10541084
totalSteps += (doNpmI || !fs.existsSync('node_modules') || !fs.existsSync('package-lock.json')) ? 1 : 0;
10551085
totalSteps += (doNpmI || !fs.existsSync('server/node_modules') || !fs.existsSync('server/package-lock.json')) ? 1 : 0;
1056-
totalSteps += doAcu ? 1 : 0;
1057-
totalSteps += doDht ? 1 : 0;
1086+
totalSteps += doAcu || doDht ? 1 : 0;
10581087
totalSteps += (doStdDeploy || doDedicated ? 1 : 0);
10591088
totalSteps += (doLaunch || doReboot ? 1 : 0);
10601089

@@ -1068,6 +1097,14 @@ async function doServiceDeployment(): Promise<void> {
10681097
totalSteps += 9 + (doUpdateUpgrade ? 1 : 0);
10691098
console.log(chalk.cyan(sol + '- Dedicated device setup -'));
10701099

1100+
if (doUpdateUpgrade) {
1101+
showStep();
1102+
write('Updating/upgrading packages' + trailingSpace);
1103+
await monitorProcess(spawn('apt-get', ['update', '-y']), spin, ErrorMode.NO_ERRORS);
1104+
await monitorProcess(spawn('apt-get', ['upgrade', '-y']), spin, ErrorMode.NO_ERRORS);
1105+
stepDone();
1106+
}
1107+
10711108
if (!noStop) {
10721109
showStep();
10731110
write('Stopping weatherService if currently running' + trailingSpace);
@@ -1083,7 +1120,7 @@ async function doServiceDeployment(): Promise<void> {
10831120
console.log(backspace + trailingSpace);
10841121
console.error(err);
10851122
console.log('\npolkit is requiring interactive authentication to stop weatherService.');
1086-
console.log('Please enter "sudo service stop weatherService" at the prompt below.');
1123+
console.log('Please enter "sudo service weatherService stop" at the prompt below.');
10871124
console.log('\nWhen that is done, restart this installation with either: ');
10881125
console.log(' sudo ./build.sh --nostop -i (for interactive set-up)');
10891126
console.log(' sudo ./build.sh --nostop -ddev (for automated set-up)');
@@ -1096,14 +1133,6 @@ async function doServiceDeployment(): Promise<void> {
10961133
stepDone();
10971134
}
10981135

1099-
if (doUpdateUpgrade) {
1100-
showStep();
1101-
write('Updating/upgrading packages' + trailingSpace);
1102-
await monitorProcess(spawn('apt-get', ['update', '-y']), spin, ErrorMode.NO_ERRORS);
1103-
await monitorProcess(spawn('apt-get', ['upgrade', '-y']), spin, ErrorMode.NO_ERRORS);
1104-
stepDone();
1105-
}
1106-
11071136
await install('pigpio', false, true);
11081137
await install(chromium);
11091138
await install('unclutter');

build_node_check.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ current_node_version() {
3333
printf %s "$version"
3434
}
3535

36+
current_npm_version() {
37+
local version=0
38+
39+
if [ "$(command -v npm)" ]; then
40+
version=$(npm --version 2>&1)
41+
42+
if [[ $version =~ "No such file" ]]; then
43+
version=-1
44+
else
45+
local pattern='([0-9]+)'
46+
[[ $version =~ $pattern ]]
47+
version="${BASH_REMATCH[1]}"
48+
fi
49+
fi
50+
51+
printf %s "$version"
52+
}
53+
3654
# shellcheck disable=SC2155
3755
export NVM_DIR="$(nvm_install_dir)"
3856
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
@@ -161,6 +179,13 @@ if [ ! -f ".first-time-install" ] || [ ! -d "node_modules/@tubular/util" ] || [
161179
touch .first-time-install
162180
fi
163181

182+
npm_version="$(current_npm_version)"
183+
184+
if (( npm_version < 7 )); then
185+
echo "Updating npm to at least version 7"
186+
sudo npm i -g "npm@>=7"
187+
fi
188+
164189
pattern='^(.*\/\.nvm\/[^:]*):'
165190
[[ $PATH =~ $pattern ]]
166191
echo "${BASH_REMATCH[1]}" > node_path.txt

0 commit comments

Comments
 (0)