LICENSE at the root; the 103 files new in ext/src/mcde (none was in the CDE import) carry the CNCL line instead of the LGPL notice. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
146 lines
3.7 KiB
C
146 lines
3.7 KiB
C
/*
|
|
* update.c -- dtsystemsettings: Software Update
|
|
*
|
|
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
*
|
|
* 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;
|
|
}
|