Merge branch 'master' into docs

This commit is contained in:
javalsai 2024-07-27 21:52:45 +02:00 committed by GitHub
commit df38990d8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
33 changed files with 377 additions and 59 deletions

11
.SRCINFO Normal file
View File

@ -0,0 +1,11 @@
pkgbase = lidm
pkgdesc = A ✨fully✨ colorful cutomizable TUI display manager made in C for simplicity.
pkgver = 0.0.0
pkgrel = 1
url = https://github.com/javalsai/lidm
arch = any
license = GPL
source = lidm::https://github.com/javalsai/lidm/releases/download/0.0.0/lidm
sha256sums = 2771ca603fb02520cb1ea2dac10400fd4f512d7a8883a7ecffefe6595a93dcf5
pkgname = lidm

View File

@ -19,5 +19,5 @@ jobs:
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: lidm
asset_name: lidm
asset_name: lidm-x86_64 # will compile for more archs other day
tag: ${{ github.ref }}

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
lidm
/lidm
dist/
.cache/

View File

@ -4,7 +4,9 @@ IDIR=include
ODIR=dist
CC=gcc
CFLAGS=-O3 -I$(IDIR)
CFLAGS?=-O3
_CFLAGS=-I$(DIR)
ALLFLAGS=$(CFLAGS) -I$(IDIR)
LIBS=-lm -lpam -lpam_misc
@ -16,11 +18,32 @@ OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
$(ODIR)/%.o: $(CDIR)/%.c $(DEPS)
@mkdir -p $(ODIR)
$(CC) -c -o $@ $< $(CFLAGS)
$(CC) -c -o $@ $< $(ALLFLAGS)
lidm: $(OBJ)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
$(CC) -o $@ $^ $(ALLFLAGS) $(LIBS)
.PHONY: clean
clean:
rm -f $(ODIR)/*.o *- li $(INCDIR)/*-
# Copy lidm to /usr/bin
install: lidm
install -m755 ./lidm /usr/bin
install -m755 ./themes/default.ini /etc/lidm.ini
install-service:
@if command -v systemctl &> /dev/null; then \
make install-service-systemd; \
elif command -v dinitctl &> /dev/null; then \
make install-service-dinit; \
else \
printf '\x1b[1;31m%s\x1b[0m\n' "Unknown init system, skipping install..."; \
fi
install-service-systemd:
install -m755 ./assets/services/systemd.service /etc/systemd/system/lidm.service
@printf '\x1b[1m%s\x1b[0m\n\n' " don't forget to run 'systemctl enable lidm'"
install-service-dinit:
install -m755 ./assets/services/dinit /etc/dinit.d/lidm
@printf '\x1b[1m%s\x1b[0m\n\n' " don't forget to run 'dinitctl enable lidm'"

14
PKGBUILD Normal file
View File

@ -0,0 +1,14 @@
pkgname=lidm
pkgver=0.0.0
pkgrel=1
pkgdesc="A ✨fully✨ colorful cutomizable TUI display manager made in C for simplicity."
arch=('any')
url="https://github.com/javalsai/lidm"
license=('GPL')
source=("lidm::https://github.com/javalsai/lidm/releases/download/v$pkgver.zip")
sha256sums=('2771ca603fb02520cb1ea2dac10400fd4f512d7a8883a7ecffefe6595a93dcf5')
package() {
install -d "$pkgdir/usr/bin/lidm"
}
sha256sums=('5eb72f7d0425e81f9b42f70159ecc44d1b6ca5cfd4fde845d01348964273ab64')

View File

@ -34,7 +34,6 @@ We all know that the most important thing in a project is the ideology of the au
[ ![stopchatcontrol](https://stopchatcontrol.eu/wp-content/uploads/2023/09/1-1-1024x1024.png) ](https://stopchatcontrol.eu)
> *there's also a [change.org post](https://www.change.org/p/stoppt-die-chatkontrolle-grundrechte-gelten-auch-im-netz).*
# Requirements
* A computer with unix based system.
* That system should have the resources neccessary for this program to make sense (Sessions, users...).
@ -79,6 +78,7 @@ make install-service-dinit # dinit
> [!NOTE]
> You can skip **most** of this with the [AUR packages](https://aur.archlinux.org/packages?K=javalsai&SeB=m)
# Disabling other DM's with systemd
You may want to disable your current Display Manager for instance:
```sh

BIN
assets/media/lidm.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 MiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

4
assets/pkg/aur/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*/*
!*/.gitignore
!*/PKGBUILD
!*/.SRCINFO

17
assets/pkg/aur/README.md Normal file
View File

@ -0,0 +1,17 @@
# AUR Packages
These files are just for reference, I'll manually edit and publish them, at least until I automate it with github actions (like updating version automatically on a release).
There are three packages that follow standard conventions:
* [`lidm`](https://aur.archlinux.org/packages/lidm): Builds latest release (manually updated per release basis)
* [`lidm-bin`](https://aur.archlinux.org/packages/lidm-bin): Fetches latest release binary (compiled by GitHub Actions, also updated per release)
* [`lidm-git`](https://aur.archlinux.org/packages/lidm-git): Fetches latest commit and builds it (should be updated automatically)
> [!IMPORTANT]
> None of those packages include the service files, I'm considering automatically detecting it on the package function or providing it as separate services (standard practice again).
>
> Depending on how good these packages go (my first packages :P) I'll make service ones too.
## Services
Summary of what to do to install service files anyways:
* **systemd:** Copy `assets/services/systemd.service` to `/etc/systemd/system/lidm.service` and enable the service (`systemctl enable lidm`)
* **dinit:** Copy `assets/services/dinit` to `/etc/dinit.d/lidm` and enable the service (`dinitctl enable lidm`)

View File

@ -0,0 +1,18 @@
pkgbase = lidm-bin
pkgdesc = A fully colorful cutomizable TUI display manager made in C. (release binary)
pkgver = 0.0.1
pkgrel = 2
url = https://github.com/javalsai/lidm
arch = x86_64
license = GPL
depends = pam
provides = lidm
conflicts = lidm
source = lidm::https://github.com/javalsai/lidm/releases/download/0.0.1/lidm-x86_64
source = default-theme.ini::https://raw.githubusercontent.com/javalsai/lidm/0.0.1/themes/default.ini
source = LICENSE::https://raw.githubusercontent.com/javalsai/lidm/0.0.1/LICENSE
sha256sums = 4969018d527613729336abd51e37283ce77d7c7a2233434642804b88e550e622
sha256sums = 27db9b0cd2da80c0c60dcb13dfad0f9d65e7dddbb7b344b859803b9ac3943cd7
sha256sums = 3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986
pkgname = lidm-bin

View File

@ -0,0 +1,26 @@
pkgname=lidm-bin
pkgver=0.0.1
pkgrel=2
depends=('pam')
pkgdesc="A fully colorful cutomizable TUI display manager made in C. (release binary)"
arch=('x86_64')
url="https://github.com/javalsai/lidm"
license=('GPL')
provides=('lidm')
conflicts=('lidm')
source=(
"lidm::$url/releases/download/$pkgver/lidm-$arch"
"default-theme.ini::https://raw.githubusercontent.com/javalsai/lidm/$pkgver/themes/default.ini"
"LICENSE::https://raw.githubusercontent.com/javalsai/lidm/$pkgver/LICENSE"
)
sha256sums=(
'4969018d527613729336abd51e37283ce77d7c7a2233434642804b88e550e622'
'27db9b0cd2da80c0c60dcb13dfad0f9d65e7dddbb7b344b859803b9ac3943cd7'
'3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986'
)
package() {
install -Dm755 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
install -Dm755 lidm "${pkgdir}/usr/bin/lidm"
install -Dm755 default-theme.ini "${pkgdir}/etc/lidm.ini"
}

View File

@ -0,0 +1,16 @@
pkgbase = lidm-git
pkgdesc = A fully colorful cutomizable TUI display manager made in C. (last git commit)
pkgver = 0.0.1.r0.gd6b165b
pkgrel = 2
url = https://github.com/javalsai/lidm
arch = any
license = GPL
makedepends = git
makedepends = make
depends = pam
provides = lidm
conflicts = lidm
source = lidm-repo::git+https://github.com/javalsai/lidm
sha256sums = SKIP
pkgname = lidm-git

View File

@ -0,0 +1,31 @@
pkgname=lidm-git
pkgver=0.0.1.r0.gd6b165b
pkgrel=2
depends=('pam')
makedepends=('git' 'make')
pkgdesc="A fully colorful cutomizable TUI display manager made in C. (last git commit)"
arch=('any')
url="https://github.com/javalsai/lidm"
license=('GPL')
provides=('lidm')
conflicts=('lidm')
source=("lidm-repo::git+https://github.com/javalsai/lidm")
sha256sums=('SKIP')
pkgver() {
cd lidm-repo
git describe --long --abbrev=7 --tags | \
sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}
build() {
cd lidm-repo
make CFLAGS="-O3"
}
package() {
cd lidm-repo
install -Dm755 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
install -Dm755 lidm "${pkgdir}/usr/bin/lidm"
install -Dm755 themes/default.ini "${pkgdir}/etc/lidm.ini"
}

View File

@ -0,0 +1,12 @@
pkgbase = lidm
pkgdesc = A fully colorful cutomizable TUI display manager made in C. (build latest tag)
pkgver = 0.0.1
pkgrel = 2
url = https://github.com/javalsai/lidm
arch = any
license = GPL
depends = pam
source = lidm-repo::git+https://github.com/javalsai/lidm
sha256sums = SKIP
pkgname = lidm

View File

@ -0,0 +1,22 @@
pkgname=lidm
pkgver=0.0.1
pkgrel=2
depends=('pam')
pkgdesc="A fully colorful cutomizable TUI display manager made in C. (build latest tag)"
arch=('any')
url="https://github.com/javalsai/lidm"
license=('GPL')
source=("lidm-repo::git+https://github.com/javalsai/lidm")
sha256sums=('SKIP')
build() {
cd lidm-repo
make CFLAGS="-O3"
}
package() {
cd lidm-repo
install -Dm755 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
install -Dm755 lidm "${pkgdir}/usr/bin/lidm"
install -Dm755 themes/default.ini "${pkgdir}/etc/lidm.ini"
}

12
assets/pkg/aur/make-srcinfo.sh Executable file
View File

@ -0,0 +1,12 @@
#/usr/bin/env bash
set -e
MYSELF=$(realpath "$0")
MYDIR=$(dirname "$MYSELF")
for pkg in "$MYDIR"/*/; do
cd "$pkg"
printf "\x1b[1mEntering '%s'\x1b[0m\n" "$pkg"
makepkg --printsrcinfo | tee .SRCINFO
echo
done

8
assets/services/dinit Normal file
View File

@ -0,0 +1,8 @@
type = process
command = /sbin/agetty tty7 linux-c -n -l /bin/lidm -o 7
restart = true
depends-on = login.target
termsignal = HUP
smooth-recovery = true
inittab-id = 7
inittab-line = tty7

View File

@ -0,0 +1,17 @@
[Unit]
Description=TUI display manager
After=systemd-user-sessions.service plymouth-quit-wait.service
After=getty@tty3.service
Conflicts=getty@tty3.service
[Service]
Type=idle
ExecStart=/usr/bin/lidm
StandardError=journal
StandardInput=tty
TTYPath=/dev/tty3
TTYReset=yes
TTYVHangup=yes
[Install]
Alias=display-manager.service

View File

@ -5,12 +5,14 @@
#include <security/pam_misc.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <auth.h>
#include <sessions.h>
#include <ui.h>
#include <unistd.h>
#include <util.h>
int pam_conversation(int num_msg, const struct pam_message **msg,
struct pam_response **resp, void *appdata_ptr) {
@ -51,6 +53,11 @@ pam_handle_t *get_pamh(char *user, char *passwd) {
}
#undef CHECK_PAM_RET
void *shmalloc(size_t size) {
return mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS,
-1, 0);
}
void moarEnv(char *user, struct session session, struct passwd *pw) {
chdir(pw->pw_dir);
setenv("HOME", pw->pw_dir, true);
@ -96,56 +103,89 @@ bool launch(char *user, char *passwd, struct session session,
return false;
}
// point of no return
// TODO: move this to get_pamh, before first setcred, like login does
if (cb != NULL)
cb();
if(setgid(pw->pw_gid) == -1) {
perror("setgid");
exit(EXIT_FAILURE);
bool *reach_session = shmalloc(sizeof(bool));
if (reach_session == NULL) {
perror("error allocating shared memory");
return false;
}
if(initgroups(user, pw->pw_gid) == -1) {
perror("init groups");
exit(EXIT_FAILURE);
*reach_session = false;
uint pid = fork();
if (pid == 0) { // child
char *TERM = NULL;
char *_GETTERM = getenv("TERM");
if (_GETTERM != NULL)
strcln(&TERM, _GETTERM);
if (clearenv() != 0) {
print_errno("clearenv");
_exit(EXIT_FAILURE);
}
char **envlist = pam_getenvlist(pamh);
if (envlist == NULL) {
print_errno("pam_getenvlist");
_exit(EXIT_FAILURE);
}
for (uint i = 0; envlist[i] != NULL; i++) {
putenv(envlist[i]);
}
// FIXME: path hotfix
putenv("PATH=/bin:/usr/bin");
if (TERM != NULL) {
setenv("TERM", TERM, true);
free(TERM);
}
free(envlist);
moarEnv(user, session, pw);
// TODO: chown stdin to user
// does it inherit stdin from parent and
// does parent need to reclaim it after
// this dies?
if (setgid(pw->pw_gid) == -1) {
print_errno("setgid");
_exit(EXIT_FAILURE);
}
if (initgroups(user, pw->pw_gid) == -1) {
print_errno("initgroups");
_exit(EXIT_FAILURE);
}
if (setuid(pw->pw_uid) == -1) {
perror("setuid");
_exit(EXIT_FAILURE);
}
if (cb != NULL)
cb();
*reach_session = true;
// TODO: these will be different due to TryExec
// and, Exec/TryExec might contain spaces as args
if (session.type == SHELL) {
system("clear");
execlp(session.exec, session.exec, NULL);
} else if (session.type == XORG || session.type == WAYLAND) {
system("clear");
execlp(session.exec, session.exec, NULL);
}
perror("execl error");
fprintf(stderr, "failure calling session");
} else {
waitpid(pid, NULL, 0);
pam_setcred(pamh, PAM_DELETE_CRED);
pam_close_session(pamh, 0);
pam_end(pamh, PAM_SUCCESS);
if (*reach_session == false) {
return false;
} else
exit(0);
}
char **envlist = pam_getenvlist(pamh);
if (envlist == NULL) {
perror("pam_getenvlist");
exit(EXIT_FAILURE);
}
// TODO: chown stdin to user
if (setuid(pw->pw_uid) == -1) {
perror("setuid");
exit(EXIT_FAILURE);
}
system("clear");
printf("\x1b[0m\x1b[H");
for (uint i = 0; envlist[i] != NULL; i++) {
putenv(envlist[i]);
}
// NOTE: path hotfix
putenv("PATH=/bin:/usr/bin");
free(envlist);
moarEnv(user, session, pw);
pam_setcred(pamh, PAM_DELETE_CRED);
pam_close_session(pamh, 0);
pam_end(pamh, PAM_SUCCESS);
if (session.type == SHELL) {
system("clear");
execlp(session.exec, session.exec, NULL);
} else if (session.type == XORG || session.type == WAYLAND) {
system("clear");
execlp(session.exec, session.exec, NULL);
}
perror("execl error");
fprintf(stderr, "failure calling session");
return true;
}

View File

@ -9,9 +9,20 @@
#include <ui.h>
#include <users.h>
void chvt(char *arg) {
size_t bsize = snprintf(NULL, 0, "chvt %s", arg) + 1;
char *buf = malloc(bsize);
snprintf(buf, bsize, "chvt %s", arg);
system(buf);
free(buf);
}
int main(int argc, char *argv[]) {
struct config* config = parse_config("/etc/lidm.ini");
if(config == NULL) {
if (argc == 2)
chvt(argv[1]);
struct config *config = parse_config("/etc/lidm.ini");
if (config == NULL) {
fprintf(stderr, "error parsing config\n");
return 1;
}

View File

@ -40,6 +40,7 @@ static u_int16_t used_size = 0;
static struct session *sessions = NULL;
static struct sessions_list *__sessions_list = NULL;
// NOTE: commented printf's here would be nice to have debug logs if I ever implement it
static enum session_type session_type;
static int fn(const char *fpath, const struct stat *sb, int typeflag) {
// practically impossible to reach this
@ -47,12 +48,14 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) {
if (used_size == 0xffff)
return 0;
if (!S_ISREG(sb->st_mode))
if (sb == NULL || !S_ISREG(sb->st_mode))
return 0;
/*printf("gonna open %s\n", fpath);*/
FILE *fd = fopen(fpath, "r");
if (fd == NULL) {
fprintf(stderr, "error opening file (r) %s", fpath);
perror("fopen");
fprintf(stderr, "error opening file (r) %s\n", fpath);
return 0;
}
@ -63,6 +66,7 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) {
char *exec_buf = NULL;
char *tryexec_buf = NULL;
while (true) {
/*printf(".");*/
char *buf = malloc(sb->st_blksize);
ssize_t read_size = getline(&buf, &alloc_size, fd);
if (read_size == -1) {
@ -91,11 +95,13 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) {
if (found == 0b111)
break;
}
/*printf("\nend parsing...\n");*/
fclose(fd);
// just add this to the list
if (name_buf != NULL && exec_buf != NULL) {
/*printf("gonna add to session list\n");*/
if (used_size >= alloc_size) {
alloc_size += bs;
sessions = realloc(sessions, alloc_size * unit_size);
@ -128,6 +134,7 @@ struct sessions_list *get_avaliable_sessions() {
for (uint i = 0; i < sources_size; i++) {
session_type = sources[i].type;
/*printf("recurring into %s\n", sources[i].dir);*/
ftw(sources[i].dir, &fn, 1);
}

View File

@ -569,7 +569,7 @@ void print_errno(const char *descr) {
origin.x, theme.colors.err, errno, strerror(errno));
else {
fprintf(stderr, "\x1b[%d;%dH\x1b[%sm%s(%d): %s", origin.y - 1, origin.x,
descr, theme.colors.err, errno, strerror(errno));
theme.colors.err, descr, errno, strerror(errno));
}
}

29
themes/README.md Normal file
View File

@ -0,0 +1,29 @@
# Themes
## cherry.ini
![cherry.ini theme](./screenshots/cherry.png)
## default.ini
![default.ini theme](./screenshots/default.png)
## nature.ini
![nature.ini theme](./screenshots/nature.png)
## nord.ini
![nord.ini theme](./screenshots/nord.png)
## old-blue.ini
![old-blue.ini theme](./screenshots/old-blue.png)
## old-blue-thick.ini
![old-blue-thick.ini theme](./screenshots/old-blue-thick.png)
## pure-tastelessness.ini
![pure-tastelessness.ini theme](./screenshots/pure-tastelessness.png)
## tasteless.ini
![tasteless.ini theme](./screenshots/tasteless.png)
## tastelessness.ini
![tastelessness.ini theme](./screenshots/tastelessness.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 261 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 267 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 KiB

BIN
themes/screenshots/nord.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 273 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 267 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 333 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 KiB