pinggy 0.6.11 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +28 -18
- package/CLAUDE.md +5 -4
- package/README.md +20 -4
- package/dist/{chunk-RYO5T2JT.js → chunk-2IPBK3RG.js} +139 -115
- package/dist/{chunk-3IPMFCEF.js → chunk-QUVQ7ODD.js} +1 -0
- package/dist/{chunk-W47AYOH2.js → chunk-ZSED6OIR.js} +276 -33
- package/dist/{configStore-6LCHFPQX.js → configStore-VDPOPFLJ.js} +1 -1
- package/dist/{daemonChild-GGG34AOT.js → daemonChild-5HZFQLQR.js} +3 -3
- package/dist/index.cjs +416 -150
- package/dist/index.js +4 -4
- package/dist/{main-FCIOVX5I.js → main-M4BTDE2A.js} +3 -3
- package/dist/{updateChild-RNCLN24C.js → updateChild-CEVYCBED.js} +1 -1
- package/package.json +2 -1
- package/scripts/install/install.ps1 +9 -8
- package/scripts/install/install.sh +8 -7
|
@@ -795,7 +795,18 @@ function autostartFilePath(platform, home) {
|
|
|
795
795
|
}
|
|
796
796
|
|
|
797
797
|
// src/daemon/lifecycle/serviceInstaller.ts
|
|
798
|
+
var AUTOSTART_ON_COMMAND = "pinggy autostart on";
|
|
799
|
+
var AUTOSTART_OFF_COMMAND = "pinggy autostart off";
|
|
798
800
|
var SERVICE_ANY_LOCATION_ENV = "PINGGY_SERVICE_ANY_LOCATION";
|
|
801
|
+
function machineServiceInstallContext() {
|
|
802
|
+
return {
|
|
803
|
+
platform: os3.platform(),
|
|
804
|
+
isPkg: "pkg" in process,
|
|
805
|
+
execPath: process.execPath,
|
|
806
|
+
home: os3.homedir(),
|
|
807
|
+
env: process.env
|
|
808
|
+
};
|
|
809
|
+
}
|
|
799
810
|
function realPath(p) {
|
|
800
811
|
try {
|
|
801
812
|
return fs6.realpathSync(p);
|
|
@@ -825,25 +836,25 @@ function isInstallerBinary(ctx) {
|
|
|
825
836
|
}
|
|
826
837
|
function installerFix(platform) {
|
|
827
838
|
return [
|
|
828
|
-
"
|
|
839
|
+
"Autostart works only for pinggy installed with the Pinggy installer.",
|
|
829
840
|
"Install it, then run this command again:",
|
|
830
841
|
` ${installCommandFor(platform)}`,
|
|
831
|
-
|
|
842
|
+
` ${AUTOSTART_ON_COMMAND}`
|
|
832
843
|
].join("\n");
|
|
833
844
|
}
|
|
834
845
|
function npmInstallerFix(platform) {
|
|
835
846
|
return [
|
|
836
|
-
"The npm version of pinggy cannot
|
|
847
|
+
"The npm version of pinggy cannot turn on autostart.",
|
|
837
848
|
"Remove it, install pinggy with the Pinggy installer, then run this command again:",
|
|
838
849
|
` ${NPM_UNINSTALL_COMMAND}`,
|
|
839
850
|
` ${installCommandFor(platform)}`,
|
|
840
|
-
|
|
851
|
+
` ${AUTOSTART_ON_COMMAND}`
|
|
841
852
|
].join("\n");
|
|
842
853
|
}
|
|
843
854
|
function installedCopyFix(installedPath) {
|
|
844
855
|
return [
|
|
845
856
|
"This pinggy is not the installed one. Run this command with the installed copy:",
|
|
846
|
-
` ${installedPath}
|
|
857
|
+
` ${installedPath} autostart on`
|
|
847
858
|
].join("\n");
|
|
848
859
|
}
|
|
849
860
|
function serviceInstallRefusal(ctx, fileExists = fs6.existsSync) {
|
|
@@ -853,20 +864,48 @@ function serviceInstallRefusal(ctx, fileExists = fs6.existsSync) {
|
|
|
853
864
|
if (fileExists(installedPath)) return installedCopyFix(installedPath);
|
|
854
865
|
return installerFix(ctx.platform);
|
|
855
866
|
}
|
|
856
|
-
function printInstalled() {
|
|
857
|
-
printer_default.success("pinggy now starts automatically when this computer starts.");
|
|
858
|
-
}
|
|
859
|
-
function printUninstalled() {
|
|
860
|
-
printer_default.success("pinggy no longer starts automatically when this computer starts.");
|
|
861
|
-
}
|
|
862
|
-
function printNotInstalled() {
|
|
863
|
-
printer_default.print("pinggy is not set to start automatically.");
|
|
864
|
-
}
|
|
865
867
|
var QUIET = { stdio: ["ignore", "ignore", "pipe"] };
|
|
866
868
|
function toolError(err) {
|
|
867
869
|
const stderr = err.stderr?.toString().trim();
|
|
868
870
|
return stderr ? stderr.replace(/^ERROR:\s*/i, "") : errorMessage(err);
|
|
869
871
|
}
|
|
872
|
+
var NO_BOOT_ENTRY = { present: false, program: null };
|
|
873
|
+
function unescapeXml(value) {
|
|
874
|
+
return value.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/&/g, "&");
|
|
875
|
+
}
|
|
876
|
+
function bootEntryProgram(platform, text) {
|
|
877
|
+
let match = null;
|
|
878
|
+
if (platform === "linux") {
|
|
879
|
+
match = /^ExecStart=(.+) --_daemon-child\s*$/m.exec(text);
|
|
880
|
+
} else if (platform === "darwin") {
|
|
881
|
+
match = /<key>ProgramArguments<\/key>\s*<array>\s*<string>([^<]+)<\/string>/.exec(text);
|
|
882
|
+
} else if (platform === "win32") {
|
|
883
|
+
match = /<Command>([^<]+)<\/Command>/.exec(text);
|
|
884
|
+
}
|
|
885
|
+
return match ? unescapeXml(match[1].trim()) : null;
|
|
886
|
+
}
|
|
887
|
+
function sameProgram(platform, left, right) {
|
|
888
|
+
return platform === "win32" ? left.toLowerCase() === right.toLowerCase() : left === right;
|
|
889
|
+
}
|
|
890
|
+
function readBootEntry(platform = os3.platform()) {
|
|
891
|
+
if (platform === "win32") {
|
|
892
|
+
return readWindowsTask();
|
|
893
|
+
}
|
|
894
|
+
const entryPath = platform === "linux" ? getSystemdServicePath() : platform === "darwin" ? getLaunchdPlistPath() : null;
|
|
895
|
+
if (!entryPath || !fs6.existsSync(entryPath)) {
|
|
896
|
+
return NO_BOOT_ENTRY;
|
|
897
|
+
}
|
|
898
|
+
let text = "";
|
|
899
|
+
try {
|
|
900
|
+
text = fs6.readFileSync(entryPath, "utf-8");
|
|
901
|
+
} catch (err) {
|
|
902
|
+
logger.debug("Could not read the boot entry", { entryPath, error: errorMessage(err) });
|
|
903
|
+
}
|
|
904
|
+
return { present: true, program: bootEntryProgram(platform, text) };
|
|
905
|
+
}
|
|
906
|
+
function startsBeforeSignIn(platform = os3.platform()) {
|
|
907
|
+
return platform === "linux" && lingerEnabled(os3.userInfo().username);
|
|
908
|
+
}
|
|
870
909
|
function getSystemdServicePath() {
|
|
871
910
|
return systemdServicePath(os3.homedir());
|
|
872
911
|
}
|
|
@@ -896,7 +935,6 @@ function installSystemd(program) {
|
|
|
896
935
|
execSync(`systemctl --user enable ${SYSTEMD_SERVICE_NAME}`, QUIET);
|
|
897
936
|
execSync(`systemctl --user start ${SYSTEMD_SERVICE_NAME}`, QUIET);
|
|
898
937
|
logger.info("systemd user service installed", { servicePath });
|
|
899
|
-
printInstalled();
|
|
900
938
|
enableLinger(os3.userInfo().username);
|
|
901
939
|
}
|
|
902
940
|
function lingerEnabled(username) {
|
|
@@ -917,24 +955,22 @@ function enableLinger(username) {
|
|
|
917
955
|
logger.info("systemd lingering enabled", { username });
|
|
918
956
|
} catch (err) {
|
|
919
957
|
logger.warn("loginctl enable-linger failed", { error: errorMessage(err) });
|
|
920
|
-
printer_default.print(`pinggy starts when ${username} signs in. To start it before anyone signs in, run: loginctl enable-linger ${username}`);
|
|
921
958
|
}
|
|
922
959
|
}
|
|
923
|
-
function
|
|
960
|
+
function removeSystemd() {
|
|
924
961
|
const servicePath = getSystemdServicePath();
|
|
925
962
|
try {
|
|
926
|
-
execSync(`systemctl --user
|
|
927
|
-
|
|
928
|
-
|
|
963
|
+
execSync(`systemctl --user disable ${SYSTEMD_SERVICE_NAME}`, QUIET);
|
|
964
|
+
} catch (err) {
|
|
965
|
+
logger.debug("systemctl disable failed", { error: toolError(err) });
|
|
929
966
|
}
|
|
930
|
-
|
|
931
|
-
|
|
967
|
+
fs6.rmSync(servicePath, { force: true });
|
|
968
|
+
try {
|
|
932
969
|
execSync("systemctl --user daemon-reload", QUIET);
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
} else {
|
|
936
|
-
printNotInstalled();
|
|
970
|
+
} catch (err) {
|
|
971
|
+
logger.debug("systemctl daemon-reload failed", { error: toolError(err) });
|
|
937
972
|
}
|
|
973
|
+
logger.info("systemd user service removed", { servicePath });
|
|
938
974
|
}
|
|
939
975
|
function getLaunchdPlistPath() {
|
|
940
976
|
return launchdPlistPath(os3.homedir());
|
|
@@ -961,48 +997,45 @@ ${programArgs}
|
|
|
961
997
|
</plist>
|
|
962
998
|
`;
|
|
963
999
|
}
|
|
1000
|
+
function launchdUid() {
|
|
1001
|
+
return process.getuid?.() ?? 501;
|
|
1002
|
+
}
|
|
1003
|
+
function launchdJobLoaded(uid) {
|
|
1004
|
+
try {
|
|
1005
|
+
execFileSync2("launchctl", ["print", `gui/${uid}/${SERVICE_LABEL}`], QUIET);
|
|
1006
|
+
return true;
|
|
1007
|
+
} catch {
|
|
1008
|
+
return false;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
964
1011
|
function installLaunchd(program) {
|
|
965
1012
|
const plistPath = getLaunchdPlistPath();
|
|
966
1013
|
const dir = path6.dirname(plistPath);
|
|
967
1014
|
fs6.mkdirSync(dir, { recursive: true });
|
|
968
1015
|
fs6.writeFileSync(plistPath, generateLaunchdPlist(program), "utf-8");
|
|
969
|
-
const uid =
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
1016
|
+
const uid = launchdUid();
|
|
1017
|
+
if (launchdJobLoaded(uid)) {
|
|
1018
|
+
try {
|
|
1019
|
+
execFileSync2("launchctl", ["kickstart", `gui/${uid}/${SERVICE_LABEL}`], QUIET);
|
|
1020
|
+
} catch (err) {
|
|
1021
|
+
logger.debug("launchctl kickstart failed", { error: toolError(err) });
|
|
1022
|
+
}
|
|
1023
|
+
} else {
|
|
1024
|
+
loadLaunchdPlist(uid, plistPath);
|
|
973
1025
|
}
|
|
974
|
-
loadLaunchdPlist(uid, plistPath);
|
|
975
1026
|
logger.info("launchd agent installed", { plistPath });
|
|
976
|
-
printInstalled();
|
|
977
1027
|
}
|
|
978
1028
|
function loadLaunchdPlist(uid, plistPath) {
|
|
979
1029
|
try {
|
|
980
|
-
|
|
1030
|
+
execFileSync2("launchctl", ["bootstrap", `gui/${uid}`, plistPath], QUIET);
|
|
981
1031
|
} catch {
|
|
982
|
-
|
|
983
|
-
execSync(`launchctl load -w ${plistPath}`);
|
|
984
|
-
} catch {
|
|
985
|
-
}
|
|
1032
|
+
execFileSync2("launchctl", ["load", "-w", plistPath], QUIET);
|
|
986
1033
|
}
|
|
987
1034
|
}
|
|
988
|
-
function
|
|
1035
|
+
function removeLaunchd() {
|
|
989
1036
|
const plistPath = getLaunchdPlistPath();
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
execSync(`launchctl bootout gui/${uid}/${SERVICE_LABEL} 2>/dev/null || true`);
|
|
993
|
-
} catch {
|
|
994
|
-
try {
|
|
995
|
-
execSync(`launchctl unload ${plistPath} 2>/dev/null || true`);
|
|
996
|
-
} catch {
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
if (fs6.existsSync(plistPath)) {
|
|
1000
|
-
fs6.unlinkSync(plistPath);
|
|
1001
|
-
logger.info("launchd agent removed", { plistPath });
|
|
1002
|
-
printUninstalled();
|
|
1003
|
-
} else {
|
|
1004
|
-
printNotInstalled();
|
|
1005
|
-
}
|
|
1037
|
+
fs6.rmSync(plistPath, { force: true });
|
|
1038
|
+
logger.info("launchd agent removed", { plistPath });
|
|
1006
1039
|
}
|
|
1007
1040
|
var WINDOWS_TASK_NAME = "PinggyDaemon";
|
|
1008
1041
|
function escapeXml(value) {
|
|
@@ -1070,6 +1103,18 @@ function windowsTaskExists() {
|
|
|
1070
1103
|
return false;
|
|
1071
1104
|
}
|
|
1072
1105
|
}
|
|
1106
|
+
function readWindowsTask() {
|
|
1107
|
+
try {
|
|
1108
|
+
const xml = execFileSync2("schtasks", ["/Query", "/TN", WINDOWS_TASK_NAME, "/XML"], {
|
|
1109
|
+
encoding: "utf-8",
|
|
1110
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
1111
|
+
windowsHide: true
|
|
1112
|
+
});
|
|
1113
|
+
return { present: true, program: bootEntryProgram("win32", xml) };
|
|
1114
|
+
} catch {
|
|
1115
|
+
return NO_BOOT_ENTRY;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1073
1118
|
function isElevated() {
|
|
1074
1119
|
try {
|
|
1075
1120
|
return /S-1-16-(12288|16384)\b/.test(execFileSync2("whoami", ["/groups"], { encoding: "utf-8" }));
|
|
@@ -1088,29 +1133,17 @@ function installWindows(program) {
|
|
|
1088
1133
|
createWindowsTask(program);
|
|
1089
1134
|
execFileSync2("schtasks", ["/Run", "/TN", WINDOWS_TASK_NAME], QUIET);
|
|
1090
1135
|
} catch (err) {
|
|
1091
|
-
|
|
1092
|
-
process.exit(1);
|
|
1136
|
+
throw new Error(windowsTaskError("turn on autostart", "change it", err));
|
|
1093
1137
|
}
|
|
1094
1138
|
logger.info("Scheduled task installed", { task: WINDOWS_TASK_NAME });
|
|
1095
|
-
printInstalled();
|
|
1096
1139
|
}
|
|
1097
|
-
|
|
1098
|
-
if (!windowsTaskExists()) {
|
|
1099
|
-
printNotInstalled();
|
|
1100
|
-
return;
|
|
1101
|
-
}
|
|
1140
|
+
function removeWindows() {
|
|
1102
1141
|
try {
|
|
1103
1142
|
execFileSync2("schtasks", ["/Delete", "/TN", WINDOWS_TASK_NAME, "/F"], QUIET);
|
|
1104
1143
|
} catch (err) {
|
|
1105
|
-
|
|
1106
|
-
process.exit(1);
|
|
1144
|
+
throw new Error(windowsTaskError("turn off autostart", "turn it off", err));
|
|
1107
1145
|
}
|
|
1108
1146
|
logger.info("Scheduled task removed", { task: WINDOWS_TASK_NAME });
|
|
1109
|
-
if (isDaemonRunning()) {
|
|
1110
|
-
const result = await stopDaemon();
|
|
1111
|
-
if (!result.ok) console.log(`Could not stop the daemon: ${result.error}`);
|
|
1112
|
-
}
|
|
1113
|
-
printUninstalled();
|
|
1114
1147
|
}
|
|
1115
1148
|
function readServiceEntryText() {
|
|
1116
1149
|
const platform = os3.platform();
|
|
@@ -1141,51 +1174,34 @@ function serviceRestartInstruction(info, platform = os3.platform(), query = runS
|
|
|
1141
1174
|
}
|
|
1142
1175
|
return null;
|
|
1143
1176
|
}
|
|
1144
|
-
function
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
}
|
|
1158
|
-
const program = serviceProgramPath(context);
|
|
1159
|
-
switch (platform) {
|
|
1160
|
-
case "linux":
|
|
1161
|
-
installSystemd(program);
|
|
1162
|
-
break;
|
|
1163
|
-
case "darwin":
|
|
1164
|
-
installLaunchd(program);
|
|
1165
|
-
break;
|
|
1166
|
-
case "win32":
|
|
1167
|
-
installWindows(program);
|
|
1168
|
-
break;
|
|
1169
|
-
default:
|
|
1170
|
-
console.error(`Unsupported platform: ${platform}`);
|
|
1171
|
-
process.exit(1);
|
|
1177
|
+
function installBootEntry(program, platform = os3.platform()) {
|
|
1178
|
+
if (platform === "win32") {
|
|
1179
|
+
installWindows(program);
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
if (platform !== "linux" && platform !== "darwin") {
|
|
1183
|
+
throw new Error(`Autostart is not supported on ${platform}.`);
|
|
1184
|
+
}
|
|
1185
|
+
try {
|
|
1186
|
+
if (platform === "linux") installSystemd(program);
|
|
1187
|
+
else installLaunchd(program);
|
|
1188
|
+
} catch (err) {
|
|
1189
|
+
throw new Error(`Could not turn on autostart: ${toolError(err)}`);
|
|
1172
1190
|
}
|
|
1173
1191
|
}
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
console.error(`Unsupported platform: ${platform}`);
|
|
1188
|
-
process.exit(1);
|
|
1192
|
+
function removeBootEntry(platform = os3.platform()) {
|
|
1193
|
+
if (platform === "win32") {
|
|
1194
|
+
removeWindows();
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
if (platform !== "linux" && platform !== "darwin") {
|
|
1198
|
+
throw new Error(`Autostart is not supported on ${platform}.`);
|
|
1199
|
+
}
|
|
1200
|
+
try {
|
|
1201
|
+
if (platform === "linux") removeSystemd();
|
|
1202
|
+
else removeLaunchd();
|
|
1203
|
+
} catch (err) {
|
|
1204
|
+
throw new Error(`Could not turn off autostart: ${toolError(err)}`);
|
|
1189
1205
|
}
|
|
1190
1206
|
}
|
|
1191
1207
|
|
|
@@ -1324,7 +1340,7 @@ async function ensureDaemonRunning() {
|
|
|
1324
1340
|
return info;
|
|
1325
1341
|
}
|
|
1326
1342
|
if (process.versions.electron) {
|
|
1327
|
-
const { runDaemonChild } = await import("./daemonChild-
|
|
1343
|
+
const { runDaemonChild } = await import("./daemonChild-5HZFQLQR.js");
|
|
1328
1344
|
const handle = await runDaemonChild({
|
|
1329
1345
|
installSignalHandlers: false,
|
|
1330
1346
|
exitOnFailure: false,
|
|
@@ -1901,8 +1917,16 @@ export {
|
|
|
1901
1917
|
createInstallProbe,
|
|
1902
1918
|
installerBinaryPath,
|
|
1903
1919
|
autostartFilePath,
|
|
1904
|
-
|
|
1905
|
-
|
|
1920
|
+
AUTOSTART_ON_COMMAND,
|
|
1921
|
+
AUTOSTART_OFF_COMMAND,
|
|
1922
|
+
machineServiceInstallContext,
|
|
1923
|
+
serviceProgramPath,
|
|
1924
|
+
serviceInstallRefusal,
|
|
1925
|
+
sameProgram,
|
|
1926
|
+
readBootEntry,
|
|
1927
|
+
startsBeforeSignIn,
|
|
1928
|
+
installBootEntry,
|
|
1929
|
+
removeBootEntry,
|
|
1906
1930
|
currentBootId,
|
|
1907
1931
|
startedInEarlierBoot,
|
|
1908
1932
|
resolveLatestTag,
|
|
@@ -37,6 +37,7 @@ var Subcommand = {
|
|
|
37
37
|
Restart: "restart",
|
|
38
38
|
Device: "device",
|
|
39
39
|
Update: "update",
|
|
40
|
+
Autostart: "autostart",
|
|
40
41
|
// The old spelling, refused with a hint. As a subcommand it never reaches tunnel mode, where `--token` is the
|
|
41
42
|
// tunnel token and a device token would go to the tunnel server.
|
|
42
43
|
Devices: "devices"
|