fix: Fixed writing command xinitrc, fixed auto-startx script

This commit is contained in:
ngn
2024-02-21 22:42:13 +03:00
parent 70ed2bec08
commit e1b05b3bf2
3 changed files with 30 additions and 43 deletions

View File

@ -26,7 +26,7 @@
#include <curses.h>
#include <stdlib.h>
#include <string.h>
#include <spawn.h>
#include <unistd.h>
#include <stdio.h>
#include <menu.h>
#include "util.h"
@ -169,13 +169,13 @@ int main(int argc, char** argv, char** envp){
.name="XFCE4",
.desc="Lightweight desktop environment for UNIX-like operating systems",
.pkg="xfce4",
.cmd="startxfce4",
.cmd="startxfce4\n",
},
{
.name="bspwm",
.desc="Tiling window manager based on binary space partitioning",
.pkg="bspwm",
.cmd="bspwm"
.cmd="bspwm\n"
}
};
@ -232,45 +232,32 @@ int main(int argc, char** argv, char** envp){
if(autox && !add_startx())
goto FAIL;
char xinitrc[PATH_MAX];
if(!joinhome(xinitrc, ".xinitrc")){
error(_("Failed to get the home directory"));
goto FAIL;
}
FILE* xf = fopen(xinitrc, "w");
if(fwrite(desktops[indx].cmd, 1, strlen(desktops[indx].cmd), xf)<0){
error(_("Failed to write to %s"), xinitrc);
fclose(xf);
goto FAIL;
}
fclose(xf);
success(_("Configuration has been saved!"));
info(_("Installing %s"), desktops[indx].name, mpi_path);
char* args[] = {
doas_path, "mp-install", desktops[indx].pkg, NULL
};
pid_t pid;
if(posix_spawn(&pid, doas_path, NULL, NULL, args, envp) != 0) {
if(execvp(doas_path, args) != 0) {
error(_("Installation failed"));
goto FAIL;
}
int status;
waitpid(pid, &status, 0);
if(status!=0){
error(_("Installation failed"));
goto FAIL;
}
char xinitrc[PATH_MAX];
if(!joinhome(xinitrc, ".xinitrc")){
error(_("Failed to get the home directory"));
goto FAIL;
}
FILE* xf = fopen(xinitrc, "w");
if(fwrite(xinitrc, 1, strlen(desktops[indx].cmd), xf)<0){
error(_("Failed to write to %s"), xinitrc);
fclose(xf);
goto FAIL;
}
success(_("Configuration has been saved!"));
fclose(xf);
free(doas_path);
return EXIT_SUCCESS;
FAIL:
free(doas_path);
return EXIT_FAILURE;

View File

@ -1,4 +1,4 @@
#define AUTOSTARTX "\n#auto-startx \nif [ -z '$DISPLAY' ] && [ '$XDG_VTNR' = 1 ]; then\nexec startx\nfi\n"
#define AUTOSTARTX "\n#auto-startx \nif [[ \"$(tty)\" == \"/dev/tty1\" ]] && [ -z \"$DISPLAY\" ]; then\nexec startx\nfi\n"
struct Desktop {
char* name;