(2007-04-11) Kable-distro
This commit is contained in:
117
pkg-manager/Ficheros.c
Normal file
117
pkg-manager/Ficheros.c
Normal file
@@ -0,0 +1,117 @@
|
||||
// permitir offsets de 64bits (tamaños mayores de 4GB)
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "Ficheros.h"
|
||||
|
||||
|
||||
// Funcion para recorrer recursivamente un directorio
|
||||
void Recurse_Dir(char *dir_orig,Recurse_Dir_func func,void *data){
|
||||
DIR *directorio;
|
||||
struct dirent *entidad_dir;
|
||||
char dir[1024];
|
||||
char path[1024];
|
||||
char file[255];
|
||||
struct stat stat_info;
|
||||
|
||||
// poner la bara final del directorio
|
||||
strcpy(dir,dir_orig);
|
||||
if(dir_orig[strlen(dir_orig)-1]!='/'){
|
||||
strcat(dir,"/");
|
||||
}
|
||||
directorio=opendir(dir);
|
||||
if(directorio!=NULL){
|
||||
do{
|
||||
entidad_dir=readdir(directorio);
|
||||
if(entidad_dir!=NULL){
|
||||
if(strcmp(entidad_dir->d_name,".") &&
|
||||
strcmp(entidad_dir->d_name,"..")){
|
||||
// costruir el path y fichero
|
||||
strcpy(path,dir);
|
||||
strcat(path,entidad_dir->d_name);
|
||||
strcpy(file,entidad_dir->d_name);
|
||||
// llamar a la funcion
|
||||
func(path,file,data);
|
||||
// comprobar si es un directorio
|
||||
lstat(path, &stat_info);
|
||||
if(S_ISDIR(stat_info.st_mode) &&
|
||||
!(stat_info.st_mode&S_IFLNK)){
|
||||
// es un directorio recursivar
|
||||
Recurse_Dir(path,func,data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}while(entidad_dir!=NULL);
|
||||
closedir(directorio);
|
||||
}
|
||||
}
|
||||
|
||||
// funcion para recorrer un directorio
|
||||
// (la recursividad la determina la funcion, si la necesitara)
|
||||
void Dir_ForEach(char *path,Dir_ForEach_func func,void *data){
|
||||
DIR *directorio;
|
||||
struct dirent *entidad_dir;
|
||||
char f_path[1024];
|
||||
|
||||
directorio=opendir(path);
|
||||
if(directorio!=NULL){
|
||||
do{
|
||||
entidad_dir=readdir(directorio);
|
||||
if(entidad_dir!=NULL){
|
||||
if(strcmp(entidad_dir->d_name,".") &&
|
||||
strcmp(entidad_dir->d_name,"..")){
|
||||
// Apartir de aqui hay un fichero(o directorio)
|
||||
strcpy(f_path,path);
|
||||
strcat(f_path,"/");
|
||||
strcat(f_path,entidad_dir->d_name);
|
||||
func(f_path,entidad_dir->d_name,data);
|
||||
}
|
||||
}
|
||||
}while(entidad_dir!=NULL);
|
||||
closedir(directorio);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int ExisteFichero(char *string){
|
||||
int existe=0;
|
||||
FILE *fil;
|
||||
fil=fopen(string,"r");
|
||||
if(fil!=NULL){
|
||||
fclose(fil);
|
||||
existe=1;
|
||||
}
|
||||
return(existe);
|
||||
}
|
||||
|
||||
int EsDirectorio(char *string){
|
||||
struct stat stat_info;
|
||||
lstat(string, &stat_info);
|
||||
if(S_ISDIR(stat_info.st_mode) &&
|
||||
!(stat_info.st_mode&S_IFLNK)){
|
||||
return(1);
|
||||
}else{
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void borrado_recursivo_func(char *path,char *name,void *data){
|
||||
if(EsDirectorio(path))
|
||||
Dir_ForEach(path,borrado_recursivo_func,NULL);
|
||||
remove(path);
|
||||
}
|
||||
|
||||
void borrado_recursivo(char *path){
|
||||
Dir_ForEach(path,borrado_recursivo_func,NULL);
|
||||
remove(path);
|
||||
}
|
||||
|
||||
|
||||
|
||||
21
pkg-manager/Ficheros.h
Normal file
21
pkg-manager/Ficheros.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef _FICHEROS_H_
|
||||
#define _FICHEROS_H_
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// Funcion para recorrer recursivamente un directorio
|
||||
typedef void (*Recurse_Dir_func)(char *path,char *name,void *data);
|
||||
void Recurse_Dir(char *dir_orig,Recurse_Dir_func func,void *data);
|
||||
|
||||
// funcion para recorrer un directorio
|
||||
// (la recursividad la determina la funcion, si la necesitara)
|
||||
typedef void (*Dir_ForEach_func)(char *path,char *name,void *data);
|
||||
void Dir_ForEach(char *path,Dir_ForEach_func func,void *data);
|
||||
|
||||
|
||||
int ExisteFichero(char *string);
|
||||
|
||||
int EsDirectorio(char *string);
|
||||
|
||||
void borrado_recursivo(char *path);
|
||||
#endif
|
||||
BIN
pkg-manager/Ficheros.o
Normal file
BIN
pkg-manager/Ficheros.o
Normal file
Binary file not shown.
89
pkg-manager/Makefile
Normal file
89
pkg-manager/Makefile
Normal file
@@ -0,0 +1,89 @@
|
||||
# Makefile Generico Ajustable
|
||||
|
||||
##################
|
||||
# Definiciones #
|
||||
##################
|
||||
|
||||
|
||||
CFLAGS = -g
|
||||
LIBS =
|
||||
CC = gcc
|
||||
CXX = g++
|
||||
DEBUGER = gdb
|
||||
RM = rm -f
|
||||
FUENTES = Ficheros.c StringUtil.c pkg-manager.c main.c
|
||||
CABECERAS = Ficheros.h StringUtil.h pkg-manager.h
|
||||
OBJS = Ficheros.o StringUtil.o pkg-manager.o main.o
|
||||
RESULTADO = pkg-manager
|
||||
|
||||
## definiciones para la instalacion
|
||||
PREFIX=/usr/local
|
||||
BINDIR = $(PREFIX)/bin
|
||||
BINFILES = $(RESULTADO)
|
||||
SHAREDIR = $(PREFIX)/share/$(RESULTADO)
|
||||
SHAREFILES =
|
||||
PIXDIR = $(SHAREDIR)/pixmaps
|
||||
PIXFILES =
|
||||
|
||||
|
||||
|
||||
|
||||
###############
|
||||
# Objetivos #
|
||||
###############
|
||||
all: $(RESULTADO)
|
||||
# ###########################
|
||||
# # Compilacion finalizada. #
|
||||
# ###########################
|
||||
|
||||
$(RESULTADO): $(OBJS)
|
||||
$(CC) -static $(OBJS) -o $(RESULTADO) $(LIBS)
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJS) $(RESULTADO)
|
||||
# #####################################
|
||||
# # limpieza terminada correctamente. #
|
||||
# #####################################
|
||||
|
||||
.cpp.o: $(CABECERAS)
|
||||
$(CXX) -c $(CFLAGS) $<
|
||||
|
||||
.c.o: $(CABECERAS)
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
|
||||
debug: $(RESULTADO)
|
||||
$(DEBUGER) $(RESULTADO)
|
||||
|
||||
run: $(RESULTADO)
|
||||
./$(RESULTADO)
|
||||
# #######################
|
||||
# # Ejecucion correcta. #
|
||||
# #######################
|
||||
|
||||
install: instala
|
||||
|
||||
instala: $(RESULTADO)
|
||||
mkdir -p $(DESTDIR)$(BINDIR)
|
||||
cp $(BINFILES) $(DESTDIR)$(BINDIR)
|
||||
if test "$(SHAREFILES)" != ""; then \
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR); \
|
||||
cp $(SHAREFILES) $(DESTDIR)$(SHAREDIR); \
|
||||
fi
|
||||
if test "$(PIXFILES)" != ""; then \
|
||||
mkdir -p $(DESTDIR)$(PIXDIR) ; \
|
||||
cp $(PIXFILES) $(DESTDIR)$(PIXDIR) ; \
|
||||
fi
|
||||
# #########################
|
||||
# # Instalacion Concluida #
|
||||
# #########################
|
||||
|
||||
|
||||
help:
|
||||
#
|
||||
# "make" para compilar, "make clean" para limpiar
|
||||
# y "make run" para ejecutar el resultado.
|
||||
# Aparte de "make debug" para ejecutar con el debuger.
|
||||
#
|
||||
|
||||
|
||||
|
||||
76
pkg-manager/StringUtil.c
Normal file
76
pkg-manager/StringUtil.c
Normal file
@@ -0,0 +1,76 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#include "StringUtil.h"
|
||||
|
||||
|
||||
|
||||
void basename(char *nombre,char *basename){
|
||||
int a,b,c;
|
||||
int len;
|
||||
int enc=0;
|
||||
len=strlen(nombre);
|
||||
a=len-1;
|
||||
while(a>-1 && !enc){
|
||||
if(nombre[a]!='/')
|
||||
a--;
|
||||
else
|
||||
enc=1;
|
||||
}
|
||||
if(enc){
|
||||
c=0;
|
||||
for(b=a+1;b<len;b++){
|
||||
basename[c]=nombre[b];
|
||||
c++;
|
||||
}
|
||||
basename[c]=0;
|
||||
}else{
|
||||
strcpy(basename,nombre);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void coger_marcado(char *cadena,int inicio,int fin,char *destino){
|
||||
int a,b=0;
|
||||
for(a=inicio;a<=fin;a++){
|
||||
destino[b]=cadena[a];
|
||||
b++;
|
||||
}
|
||||
destino[b]=0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void coger_entrecomillado(char *cadena,int *origen,char *dest){
|
||||
int pri=0,seg=0;
|
||||
int enc=0;
|
||||
int len=strlen(cadena);
|
||||
|
||||
// buscar primera comilla
|
||||
pri=origen[0];
|
||||
while(pri<len && !enc){
|
||||
if(cadena[pri]=='"'){
|
||||
enc=1;
|
||||
}else{
|
||||
pri++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// buscar segunda comilla
|
||||
enc=0;
|
||||
seg=pri+1;
|
||||
while(seg<len && !enc){
|
||||
if(cadena[seg]=='"'){
|
||||
enc=1;
|
||||
}else{
|
||||
seg++;
|
||||
}
|
||||
}
|
||||
|
||||
coger_marcado(cadena,pri+1,seg-1,dest);
|
||||
|
||||
*origen=seg+1;
|
||||
}
|
||||
13
pkg-manager/StringUtil.h
Normal file
13
pkg-manager/StringUtil.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef _STRINGUTIL_H_
|
||||
#define _STRINGUTIL_H_
|
||||
|
||||
|
||||
void basename(char *nombre,char *basename);
|
||||
|
||||
void coger_marcado(char *cadena,int inicio,int fin,char *destino);
|
||||
|
||||
|
||||
void coger_entrecomillado(char *cadena,int *origen,char *dest);
|
||||
|
||||
|
||||
#endif
|
||||
BIN
pkg-manager/StringUtil.o
Normal file
BIN
pkg-manager/StringUtil.o
Normal file
Binary file not shown.
BIN
pkg-manager/colisionador-1.tar.bz2
Normal file
BIN
pkg-manager/colisionador-1.tar.bz2
Normal file
Binary file not shown.
BIN
pkg-manager/colisionador-2.tar.bz2
Normal file
BIN
pkg-manager/colisionador-2.tar.bz2
Normal file
Binary file not shown.
10
pkg-manager/lista
Normal file
10
pkg-manager/lista
Normal file
@@ -0,0 +1,10 @@
|
||||
drwxr-xr-x root/root 0 2005-04-12 19:43:24 etc/
|
||||
drwxr-xr-x root/root 0 2005-04-12 19:43:29 etc/hotplug.d/
|
||||
drwxr-xr-x root/root 0 2005-04-12 19:43:45 etc/hotplug.d/default/
|
||||
-rwxr-xr-x root/root 249 2005-04-12 19:43:45 etc/hotplug.d/default/90-detect-block.hotplug
|
||||
drwxr-xr-x root/root 0 2005-04-12 19:43:57 usr/
|
||||
drwxr-xr-x root/root 0 2005-04-12 20:27:42 usr/sbin/
|
||||
-rwxr-xr-x root/root 1228 2005-04-12 19:44:47 usr/sbin/update-detected-block.sh
|
||||
-rwxr-xr-x root/root 3886 2005-04-12 20:27:38 usr/sbin/block-info.sh
|
||||
-rwxr-xr-x root/root 3687 2005-04-12 20:27:02 usr/sbin/detect-block.sh
|
||||
-rwxr-xr-x root/root 1685 2005-04-12 19:44:14 usr/sbin/convina-fstab.sh
|
||||
220
pkg-manager/main.c
Normal file
220
pkg-manager/main.c
Normal file
@@ -0,0 +1,220 @@
|
||||
// permitir offsets de 64bits (tamaños mayores de 4GB)
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <utime.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "StringUtil.h"
|
||||
#include "Ficheros.h"
|
||||
#include "pkg-manager.h"
|
||||
|
||||
|
||||
|
||||
void usage(){
|
||||
printf("Metodo de uso:\n");
|
||||
printf("pkg-manager install <pkg.tar.bz2> \n");
|
||||
printf("pkg-manager remove <pkg.tar.bz2> \n");
|
||||
printf("pkg-manager prepare \n");
|
||||
pkg_mostrar_entorno();
|
||||
}
|
||||
|
||||
|
||||
int main(int argc,char *argv[]){
|
||||
char fichero[1024];
|
||||
char nombre[1024];
|
||||
Pkg_File_List *pkg_lista;
|
||||
Root_File_List *lista;
|
||||
|
||||
// iniciar el sistema de paquetes
|
||||
pkg_iniciar();
|
||||
|
||||
|
||||
if(argc>1){
|
||||
// Instalar uno
|
||||
if(!strcmp(argv[1],"install") && argc==3){
|
||||
|
||||
// Comprobar que exista el paquete
|
||||
strcpy(fichero,argv[2]);
|
||||
if(!ExisteFichero(fichero)){
|
||||
printf("El paquete \"%s\" no existe.\n",fichero);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// cargar lista de ficheros del sistema
|
||||
lista=lista_sistema_cargar();
|
||||
|
||||
// determinar el nombre del paquete
|
||||
basename(fichero,nombre);
|
||||
|
||||
// preparar para la extraccion del fichero
|
||||
pkg_preparar(nombre);
|
||||
|
||||
// extraer el fichero
|
||||
printf("*** Extrayendo: \"%s\"\n",nombre);
|
||||
pkg_extraer(fichero,nombre);
|
||||
|
||||
// combinar en el sistema
|
||||
printf("*** Combinando \"%s\"\n",nombre);
|
||||
pkg_merge(lista,nombre);
|
||||
|
||||
// realizar proceso de postinstalacion
|
||||
printf("*** Configurando \"%s\"\n",nombre);
|
||||
pkg_postinstall(nombre);
|
||||
|
||||
|
||||
// guardar nueva lista
|
||||
lista_sistema_guardar(lista);
|
||||
|
||||
// liberar lista
|
||||
lista_sistema_borrar(lista);
|
||||
|
||||
// salir
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Instalar varios
|
||||
if(!strcmp(argv[1],"install") && argc>3){
|
||||
int a;
|
||||
// cargar lista de ficheros del sistema
|
||||
lista=lista_sistema_cargar();
|
||||
|
||||
// Por cada paquete
|
||||
for(a=2;a<argc;a++){
|
||||
|
||||
// Comprobar que exista el paquete
|
||||
strcpy(fichero,argv[a]);
|
||||
if(!ExisteFichero(fichero))
|
||||
continue;
|
||||
|
||||
|
||||
// determinar el nombre del paquete
|
||||
basename(fichero,nombre);
|
||||
|
||||
// preparar para la extraccion del fichero
|
||||
pkg_preparar(nombre);
|
||||
|
||||
// extraer el fichero
|
||||
printf("*** Extrayendo: \"%s\"\n",nombre);
|
||||
pkg_extraer(fichero,nombre);
|
||||
|
||||
// combinar en el sistema
|
||||
printf("*** Combinando \"%s\"\n",nombre);
|
||||
pkg_merge(lista,nombre);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// guardar nueva lista
|
||||
lista_sistema_guardar(lista);
|
||||
|
||||
// liberar lista del sistema
|
||||
lista_sistema_borrar(lista);
|
||||
|
||||
|
||||
// Postinstalacion
|
||||
for(a=2;a<argc;a++){
|
||||
// determinar el nombre del paquete
|
||||
basename(argv[a],nombre);
|
||||
if(!pkg_estado(nombre)){
|
||||
continue;
|
||||
}
|
||||
|
||||
// realizar proceso de postinstalacion
|
||||
printf("*** Configurando \"%s\"\n",nombre);
|
||||
pkg_postinstall(nombre);
|
||||
|
||||
}
|
||||
|
||||
// salir
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Desinstalar uno
|
||||
if(!strcmp(argv[1],"remove") && argc==3){
|
||||
if(pkg_estado(argv[2])){
|
||||
// cargar lista de ficheros del sistema
|
||||
lista=lista_sistema_cargar();
|
||||
|
||||
// determinar el nombre del paquete
|
||||
strcpy(fichero,argv[2]);
|
||||
basename(fichero,nombre);
|
||||
|
||||
// realizar proceso de predesinstalacion
|
||||
printf("*** Desconfigurando \"%s\"\n",nombre);
|
||||
pkg_preuninstall(nombre);
|
||||
// descombinar el paquete del sistema
|
||||
printf("*** Descombinando \"%s\"\n",nombre);
|
||||
pkg_unmerge(lista,nombre);
|
||||
// eliminar ficheros
|
||||
printf("*** Eliminando \"%s\"\n",nombre);
|
||||
pkg_eliminar(nombre);
|
||||
|
||||
// guardar nueva lista
|
||||
lista_sistema_guardar(lista);
|
||||
|
||||
// liberar listas
|
||||
lista_sistema_borrar(lista);
|
||||
|
||||
// salir
|
||||
exit(0);
|
||||
}else{
|
||||
// paquete no instalado
|
||||
printf("No esta instalado\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// "Merge" uno
|
||||
if(!strcmp(argv[1],"merge") && argc==3){
|
||||
if(pkg_estado(argv[2])){
|
||||
// cargar lista de ficheros del sistema
|
||||
lista=lista_sistema_cargar();
|
||||
|
||||
// determinar el nombre del paquete
|
||||
strcpy(fichero,argv[2]);
|
||||
basename(fichero,nombre);
|
||||
|
||||
|
||||
// combinar en el sistema
|
||||
printf("*** Combinando \"%s\"\n",nombre);
|
||||
pkg_merge(lista,nombre);
|
||||
|
||||
|
||||
// guardar nueva lista
|
||||
lista_sistema_guardar(lista);
|
||||
|
||||
// liberar lista del sistema
|
||||
lista_sistema_borrar(lista);
|
||||
|
||||
|
||||
// salir
|
||||
exit(0);
|
||||
}else{
|
||||
// paquete no instalado
|
||||
printf("No esta instalado\n");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Preparar directorios para la BD
|
||||
if(!strcmp(argv[1],"prepare")){
|
||||
// Preparar el sistema destino
|
||||
pkg_preparar_dir_systema();
|
||||
|
||||
// salir
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
usage();
|
||||
|
||||
return(0);
|
||||
}
|
||||
BIN
pkg-manager/main.o
Normal file
BIN
pkg-manager/main.o
Normal file
Binary file not shown.
BIN
pkg-manager/pkg-manager
Normal file
BIN
pkg-manager/pkg-manager
Normal file
Binary file not shown.
511
pkg-manager/pkg-manager.c
Normal file
511
pkg-manager/pkg-manager.c
Normal file
@@ -0,0 +1,511 @@
|
||||
// permitir offsets de 64bits (tamaños mayores de 4GB)
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <utime.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "StringUtil.h"
|
||||
#include "Ficheros.h"
|
||||
#include "pkg-manager.h"
|
||||
|
||||
|
||||
|
||||
static char system_root[255];
|
||||
static char pkg_basedir[255];
|
||||
static char root_list_file[255];
|
||||
|
||||
|
||||
|
||||
|
||||
// Estructuras para la lista de ficheros del sistema
|
||||
|
||||
Root_File_List *lista_sistema_cargar(){
|
||||
Root_File_List *lista_contenedor;
|
||||
Root_File_Ent *lista=NULL,*pi=NULL,*aux;
|
||||
FILE *fichero;
|
||||
char linea[2048];
|
||||
int origen;
|
||||
|
||||
fichero=fopen(root_list_file,"r");
|
||||
if(fichero!=NULL){
|
||||
while(fgets(linea,2048,fichero)!=NULL){
|
||||
aux=(Root_File_Ent *)malloc(sizeof(Root_File_Ent));
|
||||
origen=0;
|
||||
coger_entrecomillado(linea,&origen,aux->nombre);
|
||||
coger_entrecomillado(linea,&origen,aux->propietario);
|
||||
|
||||
aux->next=NULL;
|
||||
if(pi==NULL){
|
||||
lista=aux;
|
||||
pi=lista;
|
||||
}else{
|
||||
pi->next=(void *)aux;
|
||||
pi=aux;
|
||||
}
|
||||
}
|
||||
fclose(fichero);
|
||||
}
|
||||
|
||||
lista_contenedor=(Root_File_List *)malloc(sizeof(Root_File_List));
|
||||
lista_contenedor->lista=lista;
|
||||
lista_contenedor->tail=aux;
|
||||
|
||||
return(lista_contenedor);
|
||||
}
|
||||
|
||||
void lista_sistema_borrar(Root_File_List *lista){
|
||||
Root_File_Ent *next,*aux;
|
||||
next=lista->lista;
|
||||
while(next!=NULL){
|
||||
aux=(Root_File_Ent *)next->next;
|
||||
free(next);
|
||||
next=aux;
|
||||
}
|
||||
free(lista);
|
||||
}
|
||||
|
||||
Root_File_Ent *lista_sistema_sacar_fichero(Root_File_List *lista,char *fichero){
|
||||
Root_File_Ent *aux,*prev=NULL,*pi;
|
||||
int enc=0;
|
||||
pi=lista->lista;
|
||||
|
||||
while(pi!=NULL && !enc){
|
||||
if(!strcmp(pi->nombre,fichero)){
|
||||
aux=pi;
|
||||
enc=1;
|
||||
}else{
|
||||
prev=pi;
|
||||
pi=(Root_File_Ent *)pi->next;
|
||||
}
|
||||
}
|
||||
|
||||
if(enc){
|
||||
if(aux==lista->tail){
|
||||
lista->tail=prev;
|
||||
}
|
||||
if(prev!=NULL){
|
||||
prev->next=aux->next;
|
||||
}else{
|
||||
lista->lista=aux->next;
|
||||
}
|
||||
return(aux);
|
||||
}else{
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void lista_sistema_apendizar_fichero(Root_File_List *lista,char *fichero,char *propietario){
|
||||
Root_File_Ent *aux;
|
||||
|
||||
// anhadir fichero a la lista de ficheros(del sistema)
|
||||
aux=(Root_File_Ent *)malloc(sizeof(Root_File_Ent));
|
||||
strcpy(aux->nombre,fichero);
|
||||
strcpy(aux->propietario,propietario);
|
||||
|
||||
aux->next=NULL;
|
||||
if(lista->tail==NULL){
|
||||
lista->lista=aux;
|
||||
lista->tail=aux;
|
||||
}else{
|
||||
lista->tail->next=(void *)aux;
|
||||
lista->tail=aux;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void lista_sistema_guardar(Root_File_List *lista){
|
||||
Root_File_Ent *aux;
|
||||
FILE *fichero;
|
||||
aux=lista->lista;
|
||||
|
||||
//fichero=fopen(ROOT_LIST_FILE,"w");
|
||||
fichero=fopen(root_list_file,"w");
|
||||
if(fichero!=NULL){
|
||||
while(aux!=NULL){
|
||||
fprintf(fichero,"\"%s\"\t\"%s\"\n",aux->nombre,aux->propietario);
|
||||
aux=(Root_File_Ent *)aux->next;
|
||||
}
|
||||
fclose(fichero);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Estructuras para la lista de ficheros del paquete
|
||||
|
||||
Pkg_File_List *pkg_lista_cargar(char *nombre){
|
||||
Pkg_File_List *lista_contenedor;
|
||||
Pkg_File_Ent *lista=NULL,*pi=NULL,*aux;
|
||||
FILE *fichero;
|
||||
char path_fichero[1024];
|
||||
char linea[1024];
|
||||
int a;
|
||||
|
||||
//sprintf(path_fichero,PKG_BASEDIR"%s/lista\0",nombre);
|
||||
sprintf(path_fichero,"%s%s/lista\0",pkg_basedir,nombre);
|
||||
|
||||
fichero=fopen(path_fichero,"r");
|
||||
if(fichero!=NULL){
|
||||
while(fgets(linea,1024,fichero)!=NULL){
|
||||
aux=(Pkg_File_Ent *)malloc(sizeof(Root_File_Ent));
|
||||
// quitar el salto de linea final
|
||||
for(a=strlen(linea)-3;a<strlen(linea);a++){
|
||||
if(linea[a]=='\n')
|
||||
linea[a]=0;
|
||||
}
|
||||
// copiar nombre de fichero
|
||||
strcpy(aux->nombre,linea);
|
||||
// avanzar el la lista
|
||||
aux->next=NULL;
|
||||
if(pi==NULL){
|
||||
lista=aux;
|
||||
pi=lista;
|
||||
}else{
|
||||
pi->next=(void *)aux;
|
||||
pi=aux;
|
||||
}
|
||||
}
|
||||
fclose(fichero);
|
||||
}
|
||||
|
||||
lista_contenedor=(Pkg_File_List *)malloc(sizeof(Pkg_File_List));
|
||||
lista_contenedor->lista=lista;
|
||||
|
||||
return(lista_contenedor);
|
||||
}
|
||||
|
||||
|
||||
void pkg_lista_borrar(Pkg_File_List *lista){
|
||||
Pkg_File_Ent *next,*aux;
|
||||
next=lista->lista;
|
||||
while(next!=NULL){
|
||||
aux=(Pkg_File_Ent *)next->next;
|
||||
free(next);
|
||||
next=aux;
|
||||
}
|
||||
free(lista);
|
||||
}
|
||||
|
||||
|
||||
void pkg_lista_print(Pkg_File_List *lista){
|
||||
Pkg_File_Ent *pi;
|
||||
|
||||
pi=lista->lista;
|
||||
while(pi!=NULL){
|
||||
printf("%s\n",pi->nombre);
|
||||
pi=(Pkg_File_Ent *)pi->next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Funcion para preparar la extraccion de un paquete
|
||||
void pkg_preparar(char *name){
|
||||
char path[1024];
|
||||
|
||||
// crear los directorios
|
||||
//sprintf(path,PKG_BASEDIR"%s\0",name);
|
||||
sprintf(path,"%s%s\0",pkg_basedir,name);
|
||||
mkdir(path,0755);
|
||||
//sprintf(path,PKG_BASEDIR"%s/ficheros\0",name);
|
||||
sprintf(path,"%s%s/ficheros\0",pkg_basedir,name);
|
||||
mkdir(path,0755);
|
||||
}
|
||||
|
||||
// Funcion para extraer un paquete
|
||||
void pkg_extraer(char *fichero,char *nombre){
|
||||
char comando[1024];
|
||||
char destdir[1024];
|
||||
char listfile[1024];
|
||||
// preparar el comando
|
||||
sprintf(destdir,"%s%s/ficheros\0",pkg_basedir,nombre);
|
||||
sprintf(listfile,"%s%s/lista\0",pkg_basedir,nombre);
|
||||
sprintf(comando,"tar xjvfp %s -C %s --index-file %s &> /dev/null\0",fichero,destdir,listfile);
|
||||
|
||||
|
||||
// extarer el paquete utilizando tar+bzip2
|
||||
system(comando);
|
||||
|
||||
|
||||
|
||||
// Recoger scripts de instalacion y desinstalacion
|
||||
char script_path[1024],script_dest_path[1024];
|
||||
sprintf(script_path,"%s%s/ficheros/install.sh\0",pkg_basedir,nombre);
|
||||
sprintf(script_dest_path,"%s%s/install.sh\0",pkg_basedir,nombre);
|
||||
if(ExisteFichero(script_path)){
|
||||
rename(script_path,script_dest_path);
|
||||
}
|
||||
|
||||
sprintf(script_path,"%s%s/ficheros/uninstall.sh\0",pkg_basedir,nombre);
|
||||
sprintf(script_dest_path,"%s%s/uninstall.sh\0",pkg_basedir,nombre);
|
||||
if(ExisteFichero(script_path)){
|
||||
rename(script_path,script_dest_path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
Root_File_List *lista_sistema;
|
||||
char pkg_nombre[1024];
|
||||
char path[1024];
|
||||
char vpath[1024];
|
||||
} pkg_merge_parms ;
|
||||
|
||||
|
||||
void pkg_merge_func(char *path,char *name,void *data){
|
||||
pkg_merge_parms *parms=(pkg_merge_parms *)data;
|
||||
char file_dest_path[1024];
|
||||
char file_vpath[1024];
|
||||
struct stat stat_info;
|
||||
|
||||
// preparar los paths
|
||||
sprintf(file_dest_path,"%s%s/%s\0",system_root,parms->vpath,name);
|
||||
strcpy(file_vpath,parms->vpath);
|
||||
if(strcmp(file_vpath,"")){
|
||||
strcat(file_vpath,"/");
|
||||
}
|
||||
strcat(file_vpath,name);
|
||||
|
||||
// obtener stat del fichero
|
||||
lstat(path, &stat_info);
|
||||
|
||||
|
||||
if(EsDirectorio(path)){
|
||||
int existe=0;
|
||||
pkg_merge_parms new_parms;
|
||||
// es un directorio
|
||||
if(!ExisteFichero(file_dest_path)){
|
||||
// crear el directorio inexistente
|
||||
mkdir(file_dest_path,0755);
|
||||
}else{
|
||||
existe=1;
|
||||
}
|
||||
|
||||
// preparar nuevos parametros
|
||||
strcpy(new_parms.path,path);
|
||||
strcpy(new_parms.vpath,file_vpath);
|
||||
strcpy(new_parms.pkg_nombre,parms->pkg_nombre);
|
||||
new_parms.lista_sistema=parms->lista_sistema;
|
||||
|
||||
// recursivar
|
||||
Dir_ForEach(path,pkg_merge_func,&new_parms);
|
||||
|
||||
// establecer atributos del directorio origen
|
||||
if(!existe){
|
||||
struct utimbuf tiempos;
|
||||
chmod(file_dest_path,stat_info.st_mode);
|
||||
chown(file_dest_path,stat_info.st_uid,stat_info.st_gid);
|
||||
tiempos.actime=stat_info.st_atime;
|
||||
tiempos.modtime=stat_info.st_mtime;
|
||||
utime(file_dest_path,&tiempos);
|
||||
}
|
||||
}else{
|
||||
struct utimbuf tiempos;
|
||||
// es un fichero
|
||||
|
||||
// comprobar si el fichero existia previamente
|
||||
if(ExisteFichero(file_dest_path)){
|
||||
// el fichero destino existe
|
||||
Root_File_Ent *nodo_fichero;
|
||||
nodo_fichero=lista_sistema_sacar_fichero(parms->lista_sistema,file_vpath);
|
||||
if(nodo_fichero!=NULL){
|
||||
if(strcmp(nodo_fichero->propietario,parms->pkg_nombre)){
|
||||
char path_respaldo[1024];
|
||||
// el fichero es de un paquete diferente
|
||||
sprintf(path_respaldo,"%s%s/ficheros/%s\0",
|
||||
pkg_basedir,
|
||||
nodo_fichero->propietario,
|
||||
file_vpath);
|
||||
rename(file_dest_path,path_respaldo);
|
||||
}
|
||||
free(nodo_fichero);
|
||||
}
|
||||
}
|
||||
|
||||
// es un fichero (o enlace)
|
||||
rename(path,file_dest_path);
|
||||
lista_sistema_apendizar_fichero(parms->lista_sistema,file_vpath,parms->pkg_nombre);
|
||||
}
|
||||
}
|
||||
|
||||
// funcion para combinar el paquete con el sistema
|
||||
void pkg_merge(Root_File_List *lista_sistema,char *nombre){
|
||||
char path[1024];
|
||||
pkg_merge_parms parms;
|
||||
|
||||
// preparar los parametros
|
||||
sprintf(path,"%s%s/ficheros\0",pkg_basedir,nombre);
|
||||
strcpy(parms.vpath,"");
|
||||
strcpy(parms.path,path);
|
||||
strcpy(parms.pkg_nombre,nombre);
|
||||
parms.lista_sistema=lista_sistema;
|
||||
|
||||
// combinar el directorio con el sistema
|
||||
Dir_ForEach(path,pkg_merge_func,&parms);
|
||||
}
|
||||
|
||||
|
||||
// funcion para descombinar el paquete del sistema
|
||||
void pkg_unmerge(Root_File_List *lista_sistema,char *nombre){
|
||||
Root_File_Ent *pi,*prev;
|
||||
|
||||
prev=NULL;
|
||||
pi=lista_sistema->lista;
|
||||
|
||||
while(pi!=NULL){
|
||||
if(!strcmp(pi->propietario,nombre)){
|
||||
char orig_path[1024],dest_path[1024];
|
||||
|
||||
// preparar paths
|
||||
sprintf(orig_path,"%s%s\0",system_root,pi->nombre);
|
||||
sprintf(dest_path,"%s%s/ficheros/%s\0",pkg_basedir,nombre,pi->nombre);
|
||||
|
||||
// mover el fichero
|
||||
rename(orig_path,dest_path);
|
||||
|
||||
// avanzar
|
||||
if(prev==NULL){
|
||||
lista_sistema->lista=(Root_File_Ent *)pi->next;
|
||||
}else{
|
||||
prev->next=(void *)pi->next;
|
||||
}
|
||||
pi=(Root_File_Ent *)pi->next;
|
||||
}else{
|
||||
// siguente
|
||||
prev=pi;
|
||||
pi=(Root_File_Ent *)pi->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// funcion para eliminar el paquete del sistema (solo el dir)
|
||||
void pkg_eliminar(char *nombre){
|
||||
char path[1024];
|
||||
|
||||
sprintf(path,"%s%s\0",pkg_basedir,nombre);
|
||||
borrado_recursivo(path);
|
||||
}
|
||||
|
||||
// realizar las operaciones necesarias en la instalacion
|
||||
void pkg_postinstall(char *nombre){
|
||||
char path[1024],comando[1024];
|
||||
|
||||
sprintf(path,"%s%s/install.sh\0",pkg_basedir,nombre);
|
||||
if(ExisteFichero(path)){
|
||||
sprintf(comando,"sh %s\0",path);
|
||||
system(comando);
|
||||
}
|
||||
}
|
||||
|
||||
// realizar las operaciones necesarias en la desinstalacion
|
||||
void pkg_preuninstall(char *nombre){
|
||||
char path[1024],comando[1024];
|
||||
|
||||
sprintf(path,"%s%s/uninstall.sh\0",pkg_basedir,nombre);
|
||||
if(ExisteFichero(path)){
|
||||
sprintf(comando,"sh %s\0",path);
|
||||
system(comando);
|
||||
}
|
||||
}
|
||||
|
||||
// funcion para comprobar el estado del paquete
|
||||
int pkg_estado(char *nombre){
|
||||
char path[1024];
|
||||
|
||||
sprintf(path,"%s%s\0",pkg_basedir,nombre);
|
||||
if(ExisteFichero(path))
|
||||
if(EsDirectorio(path))
|
||||
return(1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define SYSTEM_ROOT "/"
|
||||
#define PKG_BASEDIR "var/db/pkg/"
|
||||
#define ROOT_LIST_FILE "lista_ficheros"
|
||||
|
||||
// Funcion para inicializar el sistema de paquetes
|
||||
void pkg_iniciar(){
|
||||
char *env_val;
|
||||
|
||||
/////////////////////////
|
||||
// obtener configuracion
|
||||
/////////////////////////
|
||||
|
||||
|
||||
env_val=getenv("SYSTEM_ROOT");
|
||||
if(env_val!=NULL){
|
||||
// valor en el entorno
|
||||
strcpy(system_root,env_val);
|
||||
}else{
|
||||
// valor por defecto
|
||||
strcpy(system_root,SYSTEM_ROOT);
|
||||
}
|
||||
|
||||
env_val=getenv("PKG_BASEDIR");
|
||||
if(env_val!=NULL){
|
||||
// valor de entorno
|
||||
sprintf(pkg_basedir,"%s%s\0",system_root,env_val);
|
||||
}else{
|
||||
// valor por defecto
|
||||
sprintf(pkg_basedir,"%s%s\0",system_root,PKG_BASEDIR);
|
||||
}
|
||||
|
||||
|
||||
env_val=getenv("ROOT_LIST_FILE");
|
||||
if(env_val!=NULL){
|
||||
// valor de entorno
|
||||
sprintf(root_list_file,"%s%s\0",pkg_basedir,env_val);
|
||||
}else{
|
||||
// valor por defecto
|
||||
sprintf(root_list_file,"%s%s\0",pkg_basedir,ROOT_LIST_FILE);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// comprobar directorio del sistema de paquetes
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
|
||||
void pkg_preparar_dir_systema(){
|
||||
char comando[255];
|
||||
|
||||
// Crear los directorios
|
||||
sprintf(comando,"mkdir -pv %s",pkg_basedir);
|
||||
system(comando);
|
||||
|
||||
// Crear el fichero de la lista del sistema
|
||||
sprintf(comando,"touch %s",root_list_file);
|
||||
system(comando);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// funcion para mostrar el entorno
|
||||
void pkg_mostrar_entorno(){
|
||||
printf("Entorno:\n");
|
||||
printf("SYSTEM_ROOT =\"%s\"\n",system_root);
|
||||
printf("PKG_BASEDIR =\"%s\"\n",pkg_basedir);
|
||||
printf("ROOT_LIST_FILE =\"%s\"\n",root_list_file);
|
||||
|
||||
}
|
||||
456
pkg-manager/pkg-manager.c.old
Normal file
456
pkg-manager/pkg-manager.c.old
Normal file
@@ -0,0 +1,456 @@
|
||||
// permitir offsets de 64bits (tamaños mayores de 4GB)
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <utime.h>
|
||||
|
||||
#include "StringUtil.h"
|
||||
#include "Ficheros.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#define SYSTEM_ROOT "/home/kable/testsystem/"
|
||||
#define PKG_BASEDIR SYSTEM_ROOT"var/db/pkg/"
|
||||
#define ROOT_LIST_FILE PKG_BASEDIR"lista_ficheros"
|
||||
|
||||
|
||||
|
||||
// Estructuras para la lista de ficheros del sistema
|
||||
|
||||
typedef struct {
|
||||
char nombre[1024];
|
||||
char propietario[255];
|
||||
void *next;
|
||||
} Root_File_Ent;
|
||||
|
||||
typedef struct {
|
||||
Root_File_Ent *lista;
|
||||
} Root_File_List;
|
||||
|
||||
|
||||
Root_File_List *lista_sistema_cargar(){
|
||||
Root_File_List *lista_contenedor;
|
||||
Root_File_Ent *lista=NULL,*pi=NULL,*aux;
|
||||
FILE *fichero;
|
||||
char linea[2048];
|
||||
int origen;
|
||||
|
||||
fichero=fopen(ROOT_LIST_FILE,"r");
|
||||
if(fichero!=NULL){
|
||||
while(fgets(linea,2048,fichero)!=NULL){
|
||||
aux=(Root_File_Ent *)malloc(sizeof(Root_File_Ent));
|
||||
origen=0;
|
||||
coger_entrecomillado(linea,&origen,aux->nombre);
|
||||
coger_entrecomillado(linea,&origen,aux->propietario);
|
||||
|
||||
aux->next=NULL;
|
||||
if(pi==NULL){
|
||||
lista=aux;
|
||||
pi=lista;
|
||||
}else{
|
||||
pi->next=(void *)aux;
|
||||
pi=aux;
|
||||
}
|
||||
}
|
||||
fclose(fichero);
|
||||
}
|
||||
|
||||
lista_contenedor=(Root_File_List *)malloc(sizeof(Root_File_List));
|
||||
lista_contenedor->lista=lista;
|
||||
|
||||
return(lista_contenedor);
|
||||
}
|
||||
|
||||
void lista_sistema_borrar(Root_File_List *lista){
|
||||
Root_File_Ent *next,*aux;
|
||||
next=lista->lista;
|
||||
while(next!=NULL){
|
||||
aux=(Root_File_Ent *)next->next;
|
||||
free(next);
|
||||
next=aux;
|
||||
}
|
||||
free(lista);
|
||||
}
|
||||
|
||||
Root_File_Ent *lista_sistema_sacar_fichero(Root_File_List *lista,char *fichero){
|
||||
Root_File_Ent *aux,*prev=NULL,*pi;
|
||||
int enc=0;
|
||||
pi=lista->lista;
|
||||
|
||||
while(pi!=NULL && !enc){
|
||||
if(!strcmp(pi->nombre,fichero)){
|
||||
aux=pi;
|
||||
enc=1;
|
||||
}else{
|
||||
prev=pi;
|
||||
pi=(Root_File_Ent *)pi->next;
|
||||
}
|
||||
}
|
||||
|
||||
if(enc){
|
||||
if(prev!=NULL){
|
||||
prev->next=aux->next;
|
||||
}else{
|
||||
lista->lista=aux->next;
|
||||
}
|
||||
return(aux);
|
||||
}else{
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void lista_sistema_guardar(Root_File_List *lista){
|
||||
Root_File_Ent *aux;
|
||||
FILE *fichero;
|
||||
aux=lista->lista;
|
||||
|
||||
fichero=fopen(ROOT_LIST_FILE,"w");
|
||||
if(fichero!=NULL){
|
||||
while(aux!=NULL){
|
||||
fprintf(fichero,"\"%s\"\t\"%s\"\n",aux->nombre,aux->propietario);
|
||||
aux=(Root_File_Ent *)aux->next;
|
||||
}
|
||||
fclose(fichero);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Estructuras para la lista de ficheros del paquete
|
||||
|
||||
typedef struct {
|
||||
char nombre[1024];
|
||||
void *next;
|
||||
} Pkg_File_Ent;
|
||||
|
||||
typedef struct {
|
||||
Pkg_File_Ent *lista;
|
||||
} Pkg_File_List;
|
||||
|
||||
|
||||
|
||||
Pkg_File_List *pkg_lista_cargar(char *nombre){
|
||||
Pkg_File_List *lista_contenedor;
|
||||
Pkg_File_Ent *lista=NULL,*pi=NULL,*aux;
|
||||
FILE *fichero;
|
||||
char path_fichero[1024];
|
||||
char linea[1024];
|
||||
int a;
|
||||
|
||||
sprintf(path_fichero,PKG_BASEDIR"%s/lista\0",nombre);
|
||||
|
||||
fichero=fopen(path_fichero,"r");
|
||||
if(fichero!=NULL){
|
||||
while(fgets(linea,1024,fichero)!=NULL){
|
||||
aux=(Pkg_File_Ent *)malloc(sizeof(Root_File_Ent));
|
||||
// quitar el salto de linea final
|
||||
for(a=strlen(linea)-3;a<strlen(linea);a++){
|
||||
if(linea[a]=='\n')
|
||||
linea[a]=0;
|
||||
}
|
||||
// copiar nombre de fichero
|
||||
strcpy(aux->nombre,linea);
|
||||
// avanzar el la lista
|
||||
aux->next=NULL;
|
||||
if(pi==NULL){
|
||||
lista=aux;
|
||||
pi=lista;
|
||||
}else{
|
||||
pi->next=(void *)aux;
|
||||
pi=aux;
|
||||
}
|
||||
}
|
||||
fclose(fichero);
|
||||
}
|
||||
|
||||
lista_contenedor=(Pkg_File_List *)malloc(sizeof(Pkg_File_List));
|
||||
lista_contenedor->lista=lista;
|
||||
|
||||
return(lista_contenedor);
|
||||
}
|
||||
|
||||
|
||||
void pkg_lista_borrar(Pkg_File_List *lista){
|
||||
Pkg_File_Ent *next,*aux;
|
||||
next=lista->lista;
|
||||
while(next!=NULL){
|
||||
aux=(Pkg_File_Ent *)next->next;
|
||||
free(next);
|
||||
next=aux;
|
||||
}
|
||||
free(lista);
|
||||
}
|
||||
|
||||
|
||||
void pkg_lista_print(Pkg_File_List *lista){
|
||||
Pkg_File_Ent *pi;
|
||||
|
||||
pi=lista->lista;
|
||||
while(pi!=NULL){
|
||||
printf("%s\n",pi->nombre);
|
||||
pi=(Pkg_File_Ent *)pi->next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void combinar_listas(Root_File_List *lista,Pkg_File_List *lista_pkg,char *nombre){
|
||||
Pkg_File_Ent *pi;
|
||||
Root_File_Ent *aux,*last;
|
||||
int enc=0;
|
||||
|
||||
// buscar el ultimo elemento de la lista
|
||||
last=lista->lista;
|
||||
while(last!=NULL && !enc){
|
||||
if(last->next==NULL){
|
||||
enc=1;
|
||||
}else{
|
||||
last=(Root_File_Ent *)last->next;
|
||||
}
|
||||
}
|
||||
|
||||
pi=lista_pkg->lista;
|
||||
while(pi!=NULL){
|
||||
if(pi->nombre[strlen(pi->nombre)-1]!='/'){ // solo ficheros
|
||||
// anhadir fichero(del paquete) a la lista de ficheros(del sistema)
|
||||
aux=(Root_File_Ent *)malloc(sizeof(Root_File_Ent));
|
||||
strcpy(aux->nombre,pi->nombre);
|
||||
strcpy(aux->propietario,nombre);
|
||||
|
||||
aux->next=NULL;
|
||||
if(last==NULL){
|
||||
lista->lista=aux;
|
||||
last=aux;
|
||||
}else{
|
||||
last->next=(void *)aux;
|
||||
last=aux;
|
||||
}
|
||||
}
|
||||
|
||||
// siguente fichero de paquete
|
||||
pi=(Pkg_File_Ent *)pi->next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void pkg_preparar(char *name){
|
||||
char path[1024];
|
||||
|
||||
// crear los directorios
|
||||
sprintf(path,PKG_BASEDIR"%s\0",name);
|
||||
mkdir(path,0755);
|
||||
sprintf(path,PKG_BASEDIR"%s/ficheros\0",name);
|
||||
mkdir(path,0755);
|
||||
}
|
||||
|
||||
|
||||
void pkg_extraer(char *fichero,char *nombre){
|
||||
char comando[1024];
|
||||
char destdir[1024];
|
||||
char listfile[1024];
|
||||
// preparar el comando
|
||||
sprintf(destdir,PKG_BASEDIR"%s/ficheros\0",nombre);
|
||||
sprintf(listfile,PKG_BASEDIR"%s/lista\0",nombre);
|
||||
sprintf(comando,"tar xjvfp %s -C %s --index-file %s &> /dev/null\0",fichero,destdir,listfile);
|
||||
|
||||
|
||||
// extarer el paquete utilizando tar+bzip2
|
||||
system(comando);
|
||||
|
||||
|
||||
|
||||
// Recoger scripts de instalacion y desinstalacion
|
||||
char script_path[1024],script_dest_path[1024];
|
||||
sprintf(script_path,PKG_BASEDIR"%s/ficheros/install.sh\0",nombre);
|
||||
sprintf(script_dest_path,PKG_BASEDIR"%s/install.sh\0",nombre);
|
||||
if(ExisteFichero(script_path)){
|
||||
rename(script_path,script_dest_path);
|
||||
}
|
||||
|
||||
sprintf(script_path,PKG_BASEDIR"%s/ficheros/uninstall.sh\0",nombre);
|
||||
sprintf(script_dest_path,PKG_BASEDIR"%s/uninstall.sh\0",nombre);
|
||||
if(ExisteFichero(script_path)){
|
||||
rename(script_path,script_dest_path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void pkg_merge_dir(Root_File_List *lista_sistema,char *pkg_nombre,char *path,char *vpath){
|
||||
DIR *directorio;
|
||||
struct dirent *entidad_dir;
|
||||
char file_path[1024];
|
||||
char file_dest_path[1024];
|
||||
char file_vpath[1024];
|
||||
struct stat stat_info;
|
||||
|
||||
// abrir el directorio
|
||||
directorio=opendir(path);
|
||||
if(directorio!=NULL){
|
||||
do{
|
||||
entidad_dir=readdir(directorio);
|
||||
if(entidad_dir!=NULL){
|
||||
if(strcmp(entidad_dir->d_name,".") &&
|
||||
strcmp(entidad_dir->d_name,"..")){
|
||||
// procesar la entidad (fichero o directorio)
|
||||
strcpy(file_path,path);
|
||||
strcat(file_path,"/");
|
||||
strcat(file_path,entidad_dir->d_name);
|
||||
strcpy(file_dest_path,SYSTEM_ROOT);
|
||||
strcat(file_dest_path,vpath);
|
||||
strcat(file_dest_path,"/");
|
||||
strcat(file_dest_path,entidad_dir->d_name);
|
||||
strcpy(file_vpath,vpath);
|
||||
if(strcmp(vpath,"")){
|
||||
strcat(file_vpath,"/");
|
||||
}
|
||||
strcat(file_vpath,entidad_dir->d_name);
|
||||
lstat(file_path, &stat_info);
|
||||
|
||||
if( S_ISDIR(stat_info.st_mode) &&
|
||||
!(stat_info.st_mode&S_IFLNK)){
|
||||
char new_path[1024];
|
||||
char new_vpath[1024];
|
||||
int existe=0;
|
||||
|
||||
// es un directorio
|
||||
strcpy(new_path,file_path);
|
||||
strcpy(new_vpath,file_vpath);
|
||||
|
||||
// crear el directorio
|
||||
if(!ExisteFichero(file_dest_path)){
|
||||
mkdir(file_dest_path,0755);
|
||||
}else{
|
||||
existe=1;
|
||||
}
|
||||
|
||||
// recursivar
|
||||
pkg_merge_dir(lista_sistema,pkg_nombre,new_path,new_vpath);
|
||||
|
||||
// establecer atributos del directorio origen
|
||||
if(!existe){
|
||||
struct utimbuf tiempos;
|
||||
chmod(file_dest_path,stat_info.st_mode);
|
||||
chown(file_dest_path,stat_info.st_uid,stat_info.st_gid);
|
||||
tiempos.actime=stat_info.st_atime;
|
||||
tiempos.modtime=stat_info.st_mtime;
|
||||
utime(file_dest_path,&tiempos);
|
||||
}
|
||||
|
||||
// borrar el directorio movido
|
||||
//remove(new_path);
|
||||
}else{
|
||||
struct utimbuf tiempos;
|
||||
|
||||
// comprobar si el fichero existia previamente
|
||||
if(ExisteFichero(file_dest_path)){
|
||||
// el fichero destino existe
|
||||
Root_File_Ent *nodo_fichero;
|
||||
|
||||
nodo_fichero=lista_sistema_sacar_fichero(lista_sistema,file_vpath);
|
||||
if(nodo_fichero!=NULL){
|
||||
if(strcmp(nodo_fichero->propietario,pkg_nombre)){
|
||||
char path_respaldo[1024];
|
||||
// el fichero es de un paquete diferente
|
||||
//printf("Colision\n");
|
||||
strcpy(path_respaldo,PKG_BASEDIR);
|
||||
strcat(path_respaldo,nodo_fichero->propietario);
|
||||
strcat(path_respaldo,"/ficheros/");
|
||||
strcat(path_respaldo,file_vpath);
|
||||
rename(file_dest_path,path_respaldo);
|
||||
}
|
||||
free(nodo_fichero);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// es un fichero (o enlace)
|
||||
rename(file_path,file_dest_path);
|
||||
|
||||
// establecer los atributos del fichero origen
|
||||
chmod(file_dest_path,stat_info.st_mode);
|
||||
chown(file_dest_path,stat_info.st_uid,stat_info.st_gid);
|
||||
tiempos.actime=stat_info.st_atime;
|
||||
tiempos.modtime=stat_info.st_mtime;
|
||||
utime(file_dest_path,&tiempos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}while(entidad_dir!=NULL);
|
||||
closedir(directorio);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void pkg_merge(Root_File_List *lista_sistema,char *nombre){
|
||||
char path[1024];
|
||||
char vpath[1024];
|
||||
|
||||
// preparar los path
|
||||
sprintf(path,PKG_BASEDIR"%s/ficheros\0",nombre);
|
||||
strcpy(vpath,"");
|
||||
|
||||
// combinar el directorio con el sistema
|
||||
pkg_merge_dir(lista_sistema,nombre,path,vpath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc,char *argv[]){
|
||||
char fichero[1024];
|
||||
char nombre[1024];
|
||||
Pkg_File_List *pkg_lista;
|
||||
Root_File_List *lista;
|
||||
|
||||
|
||||
if(argc>1){
|
||||
// cargar lista de ficheros del sistema
|
||||
lista=lista_sistema_cargar();
|
||||
|
||||
|
||||
strcpy(fichero,argv[1]);
|
||||
// determinar el nombre del paquete
|
||||
basename(fichero,nombre);
|
||||
// preparar para la extraccion del fichero
|
||||
pkg_preparar(nombre);
|
||||
// extraer el fichero
|
||||
printf("*** Extrayendo: \"%s\"\n",nombre);
|
||||
pkg_extraer(fichero,nombre);
|
||||
// comb¡vinar en el sistema
|
||||
printf("*** Combinando \"%s\"\n",nombre);
|
||||
pkg_merge(lista,nombre);
|
||||
// cargar y combinarla con la del sistema
|
||||
pkg_lista=pkg_lista_cargar(nombre);
|
||||
combinar_listas(lista,pkg_lista,nombre);
|
||||
// guardar nueva lista
|
||||
lista_sistema_guardar(lista);
|
||||
|
||||
// liberar listas
|
||||
pkg_lista_borrar(pkg_lista);
|
||||
lista_sistema_borrar(lista);
|
||||
|
||||
}
|
||||
}
|
||||
71
pkg-manager/pkg-manager.h
Normal file
71
pkg-manager/pkg-manager.h
Normal file
@@ -0,0 +1,71 @@
|
||||
#ifndef _PKG_MANAGER_H_
|
||||
#define _PKG_MANAGER_H_
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Estructuras para la lista de ficheros del sistema
|
||||
|
||||
typedef struct {
|
||||
char nombre[1024];
|
||||
char propietario[255];
|
||||
void *next;
|
||||
} Root_File_Ent;
|
||||
|
||||
typedef struct {
|
||||
Root_File_Ent *lista;
|
||||
Root_File_Ent *tail;
|
||||
} Root_File_List ;
|
||||
|
||||
Root_File_List *lista_sistema_cargar();
|
||||
void lista_sistema_borrar(Root_File_List *lista);
|
||||
Root_File_Ent *lista_sistema_sacar_fichero(Root_File_List *lista,char *fichero);
|
||||
void lista_sistema_apendizar_fichero(Root_File_List *lista,char *fichero,char *propietario);
|
||||
void lista_sistema_guardar(Root_File_List *lista);
|
||||
|
||||
|
||||
// Estructuras para la lista de ficheros del paquete
|
||||
|
||||
typedef struct {
|
||||
char nombre[1024];
|
||||
void *next;
|
||||
} Pkg_File_Ent;
|
||||
|
||||
typedef struct {
|
||||
Pkg_File_Ent *lista;
|
||||
} Pkg_File_List;
|
||||
|
||||
|
||||
Pkg_File_List *pkg_lista_cargar(char *nombre);
|
||||
void pkg_lista_borrar(Pkg_File_List *lista);
|
||||
void pkg_lista_print(Pkg_File_List *lista);
|
||||
|
||||
|
||||
// Funcion para preparar la extraccion de un paquete
|
||||
void pkg_preparar(char *name);
|
||||
// Funcion para extraer un paquete
|
||||
void pkg_extraer(char *fichero,char *nombre);
|
||||
// funcion para combinar el paquete con el sistema
|
||||
void pkg_merge(Root_File_List *lista_sistema,char *nombre);
|
||||
// funcion para descombinar el paquete del sistema
|
||||
void pkg_unmerge(Root_File_List *lista_sistema,char *nombre);
|
||||
// funcion para eliminar el paquete del sistema (solo el dir)
|
||||
void pkg_eliminar(char *nombre);
|
||||
// realizar las operaciones necesarias en la instalacion
|
||||
void pkg_postinstall(char *nombre);
|
||||
// realizar las operaciones necesarias en la desinstalacion
|
||||
void pkg_preuninstall(char *nombre);
|
||||
// funcion para comprobar el estado del paquete
|
||||
int pkg_estado(char *nombre);
|
||||
|
||||
// Funcion para inicializar el sistema de paquetes
|
||||
void pkg_iniciar();
|
||||
|
||||
// Funcion para preparar el sistema destino
|
||||
void pkg_preparar_dir_systema();
|
||||
|
||||
// funcion para mostrar el entorno
|
||||
void pkg_mostrar_entorno();
|
||||
|
||||
#endif
|
||||
BIN
pkg-manager/pkg-manager.o
Normal file
BIN
pkg-manager/pkg-manager.o
Normal file
Binary file not shown.
BIN
pkg-manager/scriptado-1.tar.bz2
Normal file
BIN
pkg-manager/scriptado-1.tar.bz2
Normal file
Binary file not shown.
9
pkg-manager/shit-finder.sh
Normal file
9
pkg-manager/shit-finder.sh
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
SYS_LIST="sys_list"
|
||||
PKG_LIST="pkg_list"
|
||||
|
||||
# Generar lista del sistema
|
||||
echo "" > $SYS_LIST
|
||||
|
||||
Reference in New Issue
Block a user