33#include <stdbool.h>
44#include <string.h>
55#include <time.h>
6- //#include <Python.h>
7- // gcc -std=c99 -ggdb3 -O0 -pedantic-errors -Wall -Wextra -fpie $(python3-config --cflags --embed) -o 'createstructure.out' 'createstructure.c' $(python3-config --embed --ldflags) && ./createstructure.out
86
97// Definitions
108#define MALLOC_MAX_SIXE 1024
@@ -126,8 +124,7 @@ char* choppy(char *s)
126124 char * n = malloc (MALLOC_MAX_SIXE ); // max return size
127125 if ( s )
128126 strcpy ( n , s );
129- if (n [strlen (n )- 1 ] == "\n" )
130- n [strlen (n )- 1 ]= '\0' ;
127+ n [strlen (n )- 1 ]= '\0' ;
131128 return n ;
132129}
133130
@@ -267,10 +264,10 @@ void get_setup()
267264 puts ("\u2139 Getting setup" );
268265
269266#ifdef UBUNTU
270- TOKEN = read_by_terminal ("cat ~ /createstructure.conf | grep 'token' | sed 's/token=//' | sed 's/token= //'" );
271- //SOURCES = read_by_terminal("cat ~ /createstructure.conf | grep 'sources' | sed 's/sources=//' | sed 's/sources= //'");
272- ORGANIZATION_NAME = read_by_terminal ("cat ~ /createstructure.conf | grep 'organization_name' | sed 's/organization_name=//' | sed 's/organization_name= //'" );
273- IGNORE = read_by_terminal ("cat ~ /createstructure.conf | grep 'ignore' | sed 's/ignore=//' | sed 's/ignore= //'" );
267+ TOKEN = read_by_terminal ("cat /etc /createstructure.conf | grep 'token' | sed 's/token=//' | sed 's/token= //'" );
268+ //SOURCES = read_by_terminal("cat /etc /createstructure.conf | grep 'sources' | sed 's/sources=//' | sed 's/sources= //'");
269+ ORGANIZATION_NAME = read_by_terminal ("cat /etc /createstructure.conf | grep 'organization_name' | sed 's/organization_name=//' | sed 's/organization_name= //'" );
270+ IGNORE = read_by_terminal ("cat /etc /createstructure.conf | grep 'ignore' | sed 's/ignore=//' | sed 's/ignore= //'" );
274271#endif // UBUNTU
275272#ifdef WINDOWS
276273 char * TO_DELATE = read_by_terminal ("powershell -command \"& {echo ''}\"" );
@@ -283,9 +280,6 @@ void get_setup()
283280 IGNORE = read_by_terminal ("powershell -command \"& {get-content $Env:HOMEDRIVE\\Progra~1\\createstructure\\createstructure.conf | where { $_ -match 'ignore'} | %{$_ -replace 'ignore=',''} | %{$_ -replace 'ignore= ',''} }\"" );
284281 IGNORE = str_replace (IGNORE , sizeof (IGNORE ), TO_DELATE , "" );
285282#endif // WINDOWS
286- TOKEN = choppy (TOKEN );
287- ORGANIZATION_NAME = choppy (ORGANIZATION_NAME );
288- IGNORE = choppy (IGNORE );
289283}
290284
291285void help (int argc , char * * argv )
@@ -394,27 +388,33 @@ void login()
394388
395389 if (verbose )
396390 //printf("\n---Infos---\n\u2139 TOCKEN: %s%s\n\u2139 SOURCES: %s\n\u2139 ORGANIZATION_NAME (empty if you will use your personal account): %s\n\u2139 IGNORE: %s\n", &TEMP_TOKEN, TEMP_TOKEN_AUTO, &TEMP_SOURCES, &TEMP_ORGANIZATION_NAME, &TEMP_IGNORE);
397- printf ("\n---Infos---\n\u2139 TOCKEN: %s%s\n\u2139 ORGANIZATION_NAME (empty if you will use your personal account): %s\n\u2139 IGNORE: %s\n" , choppy ( & TEMP_TOKEN ), choppy ( TEMP_TOKEN_AUTO ), choppy ( & TEMP_ORGANIZATION_NAME ), choppy ( & TEMP_IGNORE ) );
391+ printf ("\n---Infos---\n\u2139 TOCKEN: %s%s\n\u2139 ORGANIZATION_NAME (empty if you will use your personal account): %s\n\u2139 IGNORE: %s\n" , & TEMP_TOKEN , TEMP_TOKEN_AUTO , & TEMP_ORGANIZATION_NAME , & TEMP_IGNORE );
398392
399393 // Save insert options
400394 char execution_string [2048 ] = {'\0' };
401395
402396#ifdef UBUNTU
403- //sprintf(execution_string, "sudo echo 'token=%s%s\nsources=%s\norganization_name=%s\nignore=%s' > ~/createstructure.conf", TEMP_TOKEN, TEMP_TOKEN_AUTO, TEMP_SOURCES, TEMP_ORGANIZATION_NAME, TEMP_IGNORE);
404- sprintf (execution_string , "echo 'token=%s%s' > ~/createstructure.conf; echo 'organization_name=%s' >> ~/createstructure.conf; echo 'ignore=%s' >> ~/createstructure.conf" , choppy (TEMP_TOKEN ), choppy (TEMP_TOKEN_AUTO ), choppy (TEMP_ORGANIZATION_NAME ), choppy (TEMP_IGNORE ));
405- printf ("echo 'token=%s%s' > ~/createstructure.conf; echo 'organization_name=%s' >> ~/createstructure.conf; echo 'ignore=%s' >> ~/createstructure.conf" , choppy (TEMP_TOKEN ), choppy (TEMP_TOKEN_AUTO ), choppy (TEMP_ORGANIZATION_NAME ), choppy (TEMP_IGNORE ));
397+ //sprintf(execution_string, "sudo echo 'token=%s%s\nsources=%s\norganization_name=%s\nignore=%s' > /etc/createstructure.conf", TEMP_TOKEN, TEMP_TOKEN_AUTO, TEMP_SOURCES, TEMP_ORGANIZATION_NAME, TEMP_IGNORE);
398+ sprintf (execution_string , "sudo echo 'token=%s%s\norganization_name=%s\nignore=%s' > /etc/createstructure.conf" , TEMP_TOKEN , TEMP_TOKEN_AUTO , TEMP_ORGANIZATION_NAME , TEMP_IGNORE );
406399#endif // UBUNTU
407400#ifdef WINDOWS
408401 //sprintf(execution_string, "echo token=%s%s > %HOMEDRIVE%\\Progra~1\\createstructure\\createstructure.conf && echo sources=%s >> %HOMEDRIVE%\\Progra~1\\createstructure\\createstructure.conf && echo organization_name=%s >> %HOMEDRIVE%\\Progra~1\\createstructure\\createstructure.conf && echo ignore=%s >> %HOMEDRIVE%\\Progra~1\\createstructure\\createstructure.conf", TEMP_TOKEN, TEMP_TOKEN_AUTO, TEMP_SOURCES, TEMP_ORGANIZATION_NAME, TEMP_IGNORE);
409402 sprintf (execution_string , "echo token=%s%s > %HOMEDRIVE%\\Progra~1\\createstructure\\createstructure.conf && echo organization_name=%s >> %HOMEDRIVE%\\Progra~1\\createstructure\\createstructure.conf && echo ignore=%s >> %HOMEDRIVE%\\Progra~1\\createstructure\\createstructure.conf" , TEMP_TOKEN , TEMP_TOKEN_AUTO , TEMP_ORGANIZATION_NAME , TEMP_IGNORE );
410403#endif // WINDOWS
411404
412- if (verbose )
413- printf ("%s" , execution_string );
414405 system (execution_string );
415406
416407 if (verbose )
417408 printf ("%s" , "Configuration saved" );
409+
410+
411+ if (verbose )
412+ printf ("%s" , "Installing external packages" );
413+
414+ system ("pip3 -q install createstructure" );
415+
416+ if (verbose )
417+ printf ("%s" , "External packages installed" );
418418}
419419
420420void createstructure ()
@@ -426,8 +426,7 @@ void createstructure()
426426 char execution_string [2048 ] = {'\0' };
427427#ifdef UBUNTU
428428 //sprintf (execution_string, "python3 -c \"exec(\\\"from createstructure import createstructure;createstructure()\\\")\" -t=%s -s=%s -o=%s -i=%s %s", TOKEN, SOURCES, ORGANIZATION_NAME, IGNORE, (verbose ? "-v" : ""));
429- //sprintf (execution_string, "python3 -c \"exec(\\\"from createstructure import createstructure;createstructure()\\\")\" -t=%s -o=%s -i=%s %s", TOKEN, ORGANIZATION_NAME, IGNORE, (verbose ? "-v" : ""));
430- sprintf (execution_string , "python3 -c \"exec(\\\"import importlib.util;spec = importlib.util.spec_from_file_location('createstructure', '/home/castellanidavide/.local/lib/python3.8/site-packages/createstructure/__init__.py');foo = importlib.util.module_from_spec(spec);spec.loader.exec_module(foo);foo.createstructure()\\\")\" -t=%s -o=%s -i=%s %s" , TOKEN , ORGANIZATION_NAME , IGNORE , (verbose ? "-v" : "" ));
429+ sprintf (execution_string , "python3 -c \"exec(\\\"from createstructure import createstructure;createstructure()\\\")\" -t=%s -o=%s -i=%s %s" , TOKEN , ORGANIZATION_NAME , IGNORE , (verbose ? "-v" : "" ));
431430#endif // UBUNTU
432431#ifdef WINDOWS
433432 //sprintf (execution_string, "python.exe -c \"exec(\\\"from createstructure import createstructure;createstructure()\\\")\" -t=%s -s=%s -o=%s -i=%s %s", TOKEN, SOURCES, ORGANIZATION_NAME, IGNORE, (verbose ? "-v" : ""));
0 commit comments