Files
mcde/programs/dtsystemsettings/update.c
T
lotherkandClaude Opus 5.5 8ab668c689 mcde: Accounts and Software Update, in dtsystemsettings and McdeSys
McdeSys: mcde_sys_users/user_add/user_delete (users.c, POSIX getpwent and
useradd/userdel), user_set_password and user_set_admin per system (NetBSD:
pw_gensalt+crypt for usermod -p, wheel; a group member removed by rewriting
the group's line as user.c does, since usermod -G only appends -- measured;
Linux: chpasswd on stdin, gpasswd, sudo), mcde_sys_update_check/apply
(NetBSD: /etc/makronix/update, RELEASE, sysupgrade, pkg_add -uu; Linux:
apt-get).  A secret goes through a pipe, never on a command line.
Tests: test_sysinfo refuses a bad login and, not as root, adding (PASS on
Linux and NetBSD); as root in the NetBSD VM add/admin on/off/password/delete
pass and /etc/group is as before.

dtsystemsettings: Accounts (list, Add/Delete/Password/Administrator,
Unlock... through su -m root in a terminal, password fields show stars),
Software Update (running, available, new packages, source, Check Now,
Update Now... runs -apply-update as root in a terminal; the check runs
after the pane shows: apt took 21 s here).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 12:38:21 +00:00

146 lines
3.7 KiB
C

/*
* update.c -- dtsystemsettings: Software Update
*
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
*
* What runs, what the update source has, how many packages are new
* (mcde_sys_update_check); "Update Now..." brings the system and the
* packages up to date with one click and the administrator's password: a
* terminal opens, su(1) asks for the password, and dtsystemsettings
* -apply-update runs mcde_sys_update_apply there, where its progress shows.
*
* C99, POSIX, Xt and Motif only (ext/src/mcde/AGENTS.md).
*/
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/RowColumn.h>
#include <Mcde/McdeSys.h>
#include "ui.h"
static Widget values[4], note, updateButton;
static void
Check(void)
{
McdeSysUpdate u;
char packages[64];
if (mcde_sys_update_check(&u) != MCDE_SYS_OK) {
SetText(note, mcde_sys_error());
XtSetSensitive(updateButton, False);
return;
}
SetText(values[0], u.current[0] != '\0' ? u.current : "unknown");
SetText(values[1], u.available[0] != '\0' ? u.available : "-");
if (u.packages < 0)
snprintf(packages, sizeof packages, "-");
else
snprintf(packages, sizeof packages, "%d", u.packages);
SetText(values[2], packages);
SetText(values[3], u.source[0] != '\0' ? u.source : "none");
SetText(note, u.note[0] != '\0' ? u.note : "There is something new.");
/* nothing to do: no source, or up to date */
XtSetSensitive(updateButton, u.source[0] != '\0' &&
strstr(u.note, "up to date") == NULL);
}
static void
CheckNow(Widget w, XtPointer data, XtPointer call)
{
(void) w;
(void) data;
(void) call;
SetText(note, "Checking...");
XmUpdateDisplay(note);
Check();
}
static void
UpdateNow(Widget w, XtPointer data, XtPointer call)
{
char cmd[512];
(void) w;
(void) data;
(void) call;
if (geteuid() == 0)
snprintf(cmd, sizeof cmd, "dtterm -title 'Software Update' "
"-geometry 90x24 -e dtsystemsettings -apply-update");
else
AsRoot("Software Update", "dtsystemsettings -apply-update", cmd,
sizeof cmd);
Spawn(cmd);
}
static void
CheckLater(XtPointer data, XtIntervalId *id)
{
(void) data;
(void) id;
if (note != NULL)
Check();
}
static void
PaneGone(Widget w, XtPointer data, XtPointer call)
{
(void) w;
(void) data;
(void) call;
note = NULL;
}
Widget
MakeUpdate(Widget parent)
{
Widget box = XtVaCreateWidget("update", xmRowColumnWidgetClass, parent,
XmNspacing, 10, NULL);
Widget row;
const char *rows[8] = {
"Running", "", "Available", "", "New packages", "", "Source", ""
};
Table(box, rows, 4, values);
note = Text(box, "note", "");
XtAddCallback(box, XmNdestroyCallback, PaneGone, NULL);
row = XtVaCreateManagedWidget("buttons", xmRowColumnWidgetClass, box,
XmNorientation, XmHORIZONTAL, XmNmarginWidth, 0, NULL);
Button(row, "Check Now", CheckNow, NULL);
updateButton = Button(row, "Update Now...", UpdateNow, NULL);
XtSetSensitive(updateButton, False);
/* the check can take seconds (a package tool asks its sources): the
* pane shows first, then it checks */
SetText(note, "Checking...");
XtAppAddTimeOut(app, 200, CheckLater, NULL);
return box;
}
/* dtsystemsettings -apply-update, in the terminal of "Update Now" */
int
ApplyUpdate(void)
{
int r;
printf("Software Update: the system and the packages.\n\n");
fflush(stdout);
r = mcde_sys_update_apply();
if (r == MCDE_SYS_OK)
printf("\nThe computer is up to date. Restart it if the system "
"was updated.\n");
else
printf("\nThe update did not succeed: %s\n", mcde_sys_error());
printf("\nPress Return to close this window.\n");
fflush(stdout);
(void) getchar();
return r == MCDE_SYS_OK ? 0 : 1;
}