s-bit-agent
Version:
s.BitAgent is a simple Bitwarden CLI wrapper which provides a SSH2 Key Agent solution for Bitwarden.
88 lines • 3.56 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.XinitrcAutostartService = void 0;
const common_1 = require("@nestjs/common");
const fs = require("fs");
let XinitrcAutostartService = class XinitrcAutostartService {
constructor() {
this.name = 'Xinitrc Autostart';
}
async canActivate() {
const homeDir = process.env.HOME;
if (!homeDir) {
return false;
}
return fs.existsSync(`${homeDir}/.xinitrc`);
}
async install(command, name, marker) {
try {
const homeDir = process.env.HOME;
if (!homeDir) {
throw new Error('Could not determine user home directory');
}
const xinitrcPath = `${homeDir}/.xinitrc`;
const currentContent = fs.existsSync(xinitrcPath)
? fs.readFileSync(xinitrcPath, 'utf-8')
: '';
if (currentContent.includes(marker)) {
console.warn('Autostart entry already exists in .xinitrc');
return false;
}
const newContent = currentContent + `${command} # ${marker}\n`;
fs.writeFileSync(xinitrcPath, newContent);
return true;
}
catch (error) {
console.error('Error installing Xinitrc autostart:', error);
return false;
}
}
async uninstall(marker) {
try {
const homeDir = process.env.HOME;
if (!homeDir) {
throw new Error('Could not determine user home directory');
}
const xinitrcPath = `${homeDir}/.xinitrc`;
const currentContent = fs.readFileSync(xinitrcPath, 'utf-8');
const newContent = currentContent
.split('\n')
.filter((line) => !line.includes(marker))
.join('\n');
fs.writeFileSync(xinitrcPath, newContent);
return true;
}
catch (error) {
console.error('Error uninstalling Xinitrc autostart:', error);
return false;
}
}
async isInstalled(marker) {
try {
const homeDir = process.env.HOME;
if (!homeDir) {
throw new Error('Could not determine user home directory');
}
const xinitrcPath = `${homeDir}/.xinitrc`;
const currentContent = fs.existsSync(xinitrcPath)
? fs.readFileSync(xinitrcPath, 'utf-8')
: '';
return currentContent.includes(marker);
}
catch (error) {
console.error('Error checking if Xinitrc autostart is installed:', error);
return false;
}
}
};
exports.XinitrcAutostartService = XinitrcAutostartService;
exports.XinitrcAutostartService = XinitrcAutostartService = __decorate([
(0, common_1.Injectable)()
], XinitrcAutostartService);
//# sourceMappingURL=xinitrc.service.js.map