mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
For #27267. Below is what's shown immediately after selecting an EXE: <img width="1254" alt="image" src="https://github.com/user-attachments/assets/a28d8565-de88-448a-bdbc-92aefc34ad55" /> TODO: * Tests * GitOps requirements changes * Disabling add button/adding errors when required scripts aren't specified # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files) for more information. - [x] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [x] Added/updated automated tests - [x] A detailed QA plan exists on the associated ticket (if it isn't there, work with the product group's QA engineer to add it) - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Luke Heath <luke@fleetdm.com> Co-authored-by: Noah Talerman <47070608+noahtalerman@users.noreply.github.com> Co-authored-by: RachelElysia <rachel@fleetdm.com>
187 lines
5.3 KiB
TypeScript
187 lines
5.3 KiB
TypeScript
import React, { useState } from "react";
|
|
import { noop } from "lodash";
|
|
|
|
import { LEARN_MORE_ABOUT_BASE_LINK } from "utilities/constants";
|
|
|
|
import {
|
|
isPackageType,
|
|
isWindowsPackageType,
|
|
isFleetMaintainedPackageType,
|
|
PackageType,
|
|
} from "interfaces/package_type";
|
|
|
|
import CustomLink from "components/CustomLink";
|
|
import RevealButton from "components/buttons/RevealButton";
|
|
|
|
import { IPackageFormData } from "../PackageForm/PackageForm";
|
|
import AdvancedOptionsFields from "../AdvancedOptionsFields";
|
|
|
|
const getSupportedScriptTypeText = (pkgType: PackageType) => {
|
|
return `Currently, ${
|
|
isWindowsPackageType(pkgType) ? "PowerS" : "s"
|
|
}hell scripts are supported.`;
|
|
};
|
|
|
|
const PKG_TYPE_TO_ID_TEXT = {
|
|
pkg: "package IDs",
|
|
deb: "package name",
|
|
rpm: "package name",
|
|
msi: "product code",
|
|
exe: "software name",
|
|
} as const;
|
|
|
|
const getInstallHelpText = (pkgType: PackageType) => {
|
|
if (pkgType === "exe") {
|
|
return (
|
|
<>
|
|
For Windows, Fleet only creates install scripts for .msi packages. Use
|
|
the $INSTALLER_PATH variable to point to the installer.{" "}
|
|
{getSupportedScriptTypeText(pkgType)}{" "}
|
|
<CustomLink
|
|
url={`${LEARN_MORE_ABOUT_BASE_LINK}/exe-install-scripts`}
|
|
text="Learn more"
|
|
newTab
|
|
/>
|
|
</>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<>
|
|
Use the $INSTALLER_PATH variable to point to the installer.{" "}
|
|
{getSupportedScriptTypeText(pkgType)}{" "}
|
|
<CustomLink
|
|
url={`${LEARN_MORE_ABOUT_BASE_LINK}/install-scripts`}
|
|
text="Learn more about install scripts"
|
|
newTab
|
|
/>
|
|
</>
|
|
);
|
|
};
|
|
|
|
const getPostInstallHelpText = (pkgType: PackageType) => {
|
|
return getSupportedScriptTypeText(pkgType);
|
|
};
|
|
|
|
const getUninstallHelpText = (pkgType: PackageType) => {
|
|
if (isFleetMaintainedPackageType(pkgType)) {
|
|
return "Currently, shell scripts are supported.";
|
|
}
|
|
|
|
if (pkgType === "exe") {
|
|
return (
|
|
<>
|
|
For Windows, Fleet only creates uninstall scripts for .msi packages.
|
|
$PACKAGE_ID will be populated with the software name from the .exe file
|
|
after it's added.
|
|
{getSupportedScriptTypeText(pkgType)}{" "}
|
|
<CustomLink
|
|
url={`${LEARN_MORE_ABOUT_BASE_LINK}/exe-install-scripts`}
|
|
text="Learn more"
|
|
newTab
|
|
/>
|
|
</>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<>
|
|
$PACKAGE_ID will be populated with the {PKG_TYPE_TO_ID_TEXT[pkgType]} from
|
|
the .{pkgType} file after the software is added.{" "}
|
|
{getSupportedScriptTypeText(pkgType)}{" "}
|
|
<CustomLink
|
|
url={`${LEARN_MORE_ABOUT_BASE_LINK}/uninstall-scripts`}
|
|
text="Learn more about uninstall scripts"
|
|
newTab
|
|
/>
|
|
</>
|
|
);
|
|
};
|
|
|
|
const baseClass = "package-advanced-options";
|
|
|
|
interface IPackageAdvancedOptionsProps {
|
|
errors: { preInstallQuery?: string; postInstallScript?: string };
|
|
selectedPackage: IPackageFormData["software"];
|
|
preInstallQuery?: string;
|
|
installScript: string;
|
|
postInstallScript?: string;
|
|
uninstallScript?: string;
|
|
showSchemaButton?: boolean;
|
|
onClickShowSchema?: () => void;
|
|
onChangePreInstallQuery: (value?: string) => void;
|
|
onChangeInstallScript: (value: string) => void;
|
|
onChangePostInstallScript: (value?: string) => void;
|
|
onChangeUninstallScript: (value?: string) => void;
|
|
}
|
|
|
|
const PackageAdvancedOptions = ({
|
|
showSchemaButton = false,
|
|
errors,
|
|
selectedPackage,
|
|
preInstallQuery,
|
|
installScript,
|
|
postInstallScript,
|
|
uninstallScript,
|
|
onClickShowSchema = noop,
|
|
onChangePreInstallQuery,
|
|
onChangeInstallScript,
|
|
onChangePostInstallScript,
|
|
onChangeUninstallScript,
|
|
}: IPackageAdvancedOptionsProps) => {
|
|
const [showAdvancedOptions, setShowAdvancedOptions] = useState(false);
|
|
const name = selectedPackage?.name || "";
|
|
const ext = name.split(".").pop() as PackageType;
|
|
|
|
const renderAdvancedOptions = () => {
|
|
if (!isPackageType(ext)) {
|
|
// this should never happen
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<AdvancedOptionsFields
|
|
className={`${baseClass}__input-fields`}
|
|
showSchemaButton={showSchemaButton}
|
|
installScriptHelpText={getInstallHelpText(ext)}
|
|
postInstallScriptHelpText={getPostInstallHelpText(ext)}
|
|
uninstallScriptHelpText={getUninstallHelpText(ext)}
|
|
errors={errors}
|
|
preInstallQuery={preInstallQuery}
|
|
installScript={installScript}
|
|
postInstallScript={postInstallScript}
|
|
uninstallScript={uninstallScript}
|
|
onClickShowSchema={onClickShowSchema}
|
|
onChangePreInstallQuery={onChangePreInstallQuery}
|
|
onChangeInstallScript={onChangeInstallScript}
|
|
onChangePostInstallScript={onChangePostInstallScript}
|
|
onChangeUninstallScript={onChangeUninstallScript}
|
|
/>
|
|
);
|
|
};
|
|
|
|
return (
|
|
<div className={baseClass}>
|
|
<RevealButton
|
|
className={`${baseClass}__accordion-title`}
|
|
isShowing={showAdvancedOptions}
|
|
showText="Advanced options"
|
|
hideText="Advanced options"
|
|
caretPosition="after"
|
|
onClick={() => setShowAdvancedOptions(!showAdvancedOptions)}
|
|
disabled={!selectedPackage}
|
|
disabledTooltipContent={
|
|
<>
|
|
Choose a file to modify <br />
|
|
advanced options.
|
|
</>
|
|
}
|
|
/>
|
|
{(showAdvancedOptions || ext === "exe") &&
|
|
!!selectedPackage &&
|
|
renderAdvancedOptions()}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default PackageAdvancedOptions;
|