parent
b2e6c5075c
commit
30b1ced97d
@ -0,0 +1,146 @@
|
|||||||
|
#!/usr/bin/make -f
|
||||||
|
|
||||||
|
#SHELL := /bin/bash
|
||||||
|
MAKEFILE_FILEPATH := $(abspath $(lastword $(MAKEFILE_LIST)))
|
||||||
|
MAKEFILE_DIR := $(notdir $(patsubst %/,%,$(dir $(MAKEFILE_FILEPATH))))
|
||||||
|
MAKEFILE_PATH := $(dir $(MAKEFILE_FILEPATH))
|
||||||
|
|
||||||
|
CMAKE_COMMAND = cmake
|
||||||
|
CMAKE_SOURCE_DIR = $(MAKEFILE_PATH)source
|
||||||
|
CMAKE_BUILD_DIR = $(MAKEFILE_PATH)compile
|
||||||
|
#CMAKE_SOURCE_DIR = ./source
|
||||||
|
#CMAKE_BUILD_DIR = ./compile
|
||||||
|
DEPENDS = /bin/cmake
|
||||||
|
PREFIX ?= /usr
|
||||||
|
PKGNAME = $(MAKEFILE_DIR)
|
||||||
|
#PKGNAME = ubl-settings-manager
|
||||||
|
LATEST_TAG=
|
||||||
|
default_target: all
|
||||||
|
|
||||||
|
.PHONY: all init depend debug prepare check build uninstall install clean help
|
||||||
|
|
||||||
|
all: init build
|
||||||
|
|
||||||
|
init:
|
||||||
|
@echo "Initialize ..."; \
|
||||||
|
if [ -d ".git" ]; then \
|
||||||
|
LATEST_TAG=$$(git describe --tags | sed 's/^v//'|grep -oE "^[0-9]{1,}.[0-9]{1,}"); \
|
||||||
|
else \
|
||||||
|
LATEST_TAG="0.0"; \
|
||||||
|
fi; \
|
||||||
|
sed -r "s/^(string version_application).*/\1=\"$${LATEST_TAG}\";/" -i source/${PKGNAME}.h; \
|
||||||
|
echo "-- Build path: ${CMAKE_BUILD_DIR}"
|
||||||
|
|
||||||
|
depend:
|
||||||
|
@echo "Check depends ..."
|
||||||
|
@for FILE_DEPEND in $(DEPENDS); do \
|
||||||
|
if [ ! -f $${FILE_DEPEND} ]; then \
|
||||||
|
echo "ERROR: Depend '$${FILE_DEPEND}' not found !"; \
|
||||||
|
exit 1; \
|
||||||
|
fi; \
|
||||||
|
done; \
|
||||||
|
echo "Check depends: OK"
|
||||||
|
# $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
|
||||||
|
|
||||||
|
debug: init build
|
||||||
|
@echo "Debug ..."; \
|
||||||
|
if [ ! -d ${CMAKE_BUILD_DIR} ]; then \
|
||||||
|
$(CMAKE_COMMAND) -S${CMAKE_SOURCE_DIR} -B${CMAKE_BUILD_DIR} -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="${PREFIX}"; \
|
||||||
|
fi; \
|
||||||
|
echo "${CMAKE_BUILD_DIR}/${PKGNAME}"; \
|
||||||
|
cp ${CMAKE_BUILD_DIR}/${PKGNAME} ./; \
|
||||||
|
echo "Debug: OK"
|
||||||
|
|
||||||
|
prepare:
|
||||||
|
@echo "Prepare ..."; \
|
||||||
|
if [ ! -d ${CMAKE_BUILD_DIR} ]; then \
|
||||||
|
$(CMAKE_COMMAND) -S${CMAKE_SOURCE_DIR} -B${CMAKE_BUILD_DIR} -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="${PREFIX}"; \
|
||||||
|
fi; \
|
||||||
|
echo "Prepare: OK"
|
||||||
|
|
||||||
|
check:
|
||||||
|
@echo "Check ..."; \
|
||||||
|
if [ -f ${CMAKE_BUILD_DIR}/${PKGNAME} ]; then \
|
||||||
|
echo "Check: OK"; \
|
||||||
|
else \
|
||||||
|
echo "Check: ${CMAKE_BUILD_DIR}/${PKGNAME} not found !"; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
build: depend prepare
|
||||||
|
@echo "Build ..."; \
|
||||||
|
make --directory=${CMAKE_BUILD_DIR}; \
|
||||||
|
echo "Build: OK"
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
@echo "Uninstall ..."
|
||||||
|
@for FILE_PO in $(wildcard *.po); do \
|
||||||
|
LANG=$${FILE_PO##*_};LANG=$${LANG%.*}; \
|
||||||
|
FILE_MO=$${FILE_PO##*/}; FILE_MO="$${FILE_MO%_*.po}.mo"; \
|
||||||
|
PATH_FILE_MO="${DESTDIR}${PREFIX}/share/locale/$${LANG}/LC_MESSAGES/$${FILE_MO}"; \
|
||||||
|
$(RM) "$${PATH_FILE_MO}"; \
|
||||||
|
done
|
||||||
|
@$(RM) "${DESTDIR}${PREFIX}/bin/${PKGNAME}"
|
||||||
|
@$(RM) "${DESTDIR}${PREFIX}/share/polkit-1/actions/com.ublinux.${PKGNAME}.policy"
|
||||||
|
@if [ -z ${DESTDIR} ]; then \
|
||||||
|
[ -d "${DESTDIR}${PREFIX}/share/icons/hicolor/" ] && gtk-update-icon-cache -fiq "${DESTDIR}${PREFIX}/share/icons/hicolor/" &>/dev/null || true; \
|
||||||
|
update-desktop-database --quiet &>/dev/null || true; \
|
||||||
|
[ -d "${DESTDIR}${PREFIX}/share/applications" ] && touch "${DESTDIR}${PREFIX}/share/applications" &>/dev/null || true; \
|
||||||
|
fi
|
||||||
|
@echo "Uninstall: OK"
|
||||||
|
|
||||||
|
install: check uninstall
|
||||||
|
@echo "Install ..."
|
||||||
|
#################################################### УДАЛИТЬ ПЕРЕД КОММИТОМ ################################################################################
|
||||||
|
@gcc source/ubl-settings-repo-back.c source/ubl-settings-repo-back.h source/ubl-strings.h -o ubl-settings-repo-back `pkg-config --cflags --libs gtk+-3.0 vte-2.91 webkit2gtk-4.0 webkit2gtk-web-extension-4.0` -g
|
||||||
|
#################################################### УДАЛИТЬ ПЕРЕД КОММИТОМ ################################################################################
|
||||||
|
@for FILE_PO in $(wildcard *.po); do \
|
||||||
|
LANG=$${FILE_PO##*_};LANG=$${LANG%.*}; \
|
||||||
|
install -dm755 "${DESTDIR}${PREFIX}/share/locale/$${LANG}/LC_MESSAGES"; \
|
||||||
|
FILE_MO=$${FILE_PO##*/}; FILE_MO="$${FILE_MO%_*.po}.mo"; \
|
||||||
|
PATH_FILE_MO="${DESTDIR}${PREFIX}/share/locale/$${LANG}/LC_MESSAGES/$${FILE_MO}"; \
|
||||||
|
echo "$${FILE_PO}"; \
|
||||||
|
msgfmt "$${FILE_PO}" -v -f -o "$${PATH_FILE_MO}"; \
|
||||||
|
done
|
||||||
|
@install -dm755 "${DESTDIR}${PREFIX}/share/icons/hicolor/scalable/apps"
|
||||||
|
@install -dm755 "${DESTDIR}${PREFIX}/share/polkit-1/actions"
|
||||||
|
@install -Dm644 -t "${DESTDIR}${PREFIX}/share/polkit-1/actions/" "com.ublinux.${PKGNAME}.policy"
|
||||||
|
@install -Dm755 -t "${DESTDIR}${PREFIX}/bin/" "${CMAKE_BUILD_DIR}/${PKGNAME}"
|
||||||
|
@install -dm755 "${DESTDIR}/etc/xdg"
|
||||||
|
@install -dm755 "${DESTDIR}${PREFIX}/share/applications"
|
||||||
|
@if [ -z ${DESTDIR} ]; then \
|
||||||
|
[ -d "${DESTDIR}${PREFIX}/share/icons/hicolor/" ] && gtk-update-icon-cache -fiq "${DESTDIR}${PREFIX}/share/icons/hicolor/" &>/dev/null || true; \
|
||||||
|
update-desktop-database --quiet &>/dev/null || true; \
|
||||||
|
[ -d "${DESTDIR}${PREFIX}/share/applications" ] && touch "${DESTDIR}${PREFIX}/share/applications" &>/dev/null || true; \
|
||||||
|
fi
|
||||||
|
@echo "Install: OK"
|
||||||
|
@sed -r "s/^(string version_application=\"*\").*/string version_application;/" -i source/${PKGNAME}.h; \
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@echo "Clean ..."
|
||||||
|
@$(RM) -rd ${CMAKE_BUILD_DIR}
|
||||||
|
@if [ -d ${CMAKE_BUILD_DIR} ]; then \
|
||||||
|
echo "Clean: error, compile directory exist ${CMAKE_BUILD_DIR}"; \
|
||||||
|
else \
|
||||||
|
echo "Clean: OK"; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
up_ver:
|
||||||
|
@CURRENT=$$(grep 'VERSION' ${FILE_VERSION} | cut -d" " -f2); \
|
||||||
|
MAJOR=$$(cut -d. -f1 <<< $${CURRENT}); \
|
||||||
|
MINOR=$$(cut -d. -f2 <<< $${CURRENT}); \
|
||||||
|
VER="$${MAJOR}.$$(($${MINOR}+1))"; \
|
||||||
|
sed "s/VERSION *[[:digit:]]*.*/VERSION $${VER}/" -i ${FILE_VERSION}; \
|
||||||
|
echo "Updated version to VERSION.md: $${CURRENT} to $${VER}"
|
||||||
|
|
||||||
|
help:
|
||||||
|
@echo "The following are some of the valid targets for this Makefile:"; \
|
||||||
|
echo "... all (the default if no target is provided)"; \
|
||||||
|
echo "... init"; \
|
||||||
|
echo "... debug"; \
|
||||||
|
echo "... prepare"; \
|
||||||
|
echo "... compile"; \
|
||||||
|
echo "... install"; \
|
||||||
|
echo "... uninstall"; \
|
||||||
|
echo "... clean"; \
|
||||||
|
echo "... up_ver"
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.7)
|
||||||
|
project(ubl-settings-repo-back)
|
||||||
|
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
|
||||||
|
pkg_check_modules(GTK REQUIRED glib-2.0)
|
||||||
|
include_directories(${GTK_INCLUDE_DIRS})
|
||||||
|
link_directories(${GTK_LIBRARY_DIRS})
|
||||||
|
add_definitions(${GTK_CFLAGS_OTHER})
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always \
|
||||||
|
-O2 -pipe -fno-plt -fexceptions \
|
||||||
|
-Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security \
|
||||||
|
-fstack-clash-protection -fcf-protection")
|
||||||
|
|
||||||
|
|
||||||
|
set(SOURCE_FILES
|
||||||
|
ubl-settings-repo-back.c
|
||||||
|
ubl-settings-repo-back.h
|
||||||
|
# ubl-strings.h
|
||||||
|
)
|
||||||
|
|
||||||
|
set(LIBRARIES
|
||||||
|
${GTK_LIBRARIES}
|
||||||
|
pthread)
|
||||||
|
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
|
||||||
|
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIBRARIES})
|
||||||
|
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_BINARY_DIR})
|
||||||
|
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
|
||||||
@ -0,0 +1,141 @@
|
|||||||
|
#include "ubl-settings-repo-back.h"
|
||||||
|
|
||||||
|
|
||||||
|
dict_simple *yon_dict_new(){
|
||||||
|
dict_simple *dict = (dict_simple*)malloc(sizeof(dict_simple));
|
||||||
|
dict->first=dict;
|
||||||
|
dict->next=NULL;
|
||||||
|
dict->data=NULL;
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
|
||||||
|
dict_simple *yon_dict_append(dict_simple *dictionary_to_append){
|
||||||
|
dict_simple *dict = (dict_simple*)malloc(sizeof(dict_simple));
|
||||||
|
dictionary_to_append->next=dict;
|
||||||
|
dict->first=dictionary_to_append->first;
|
||||||
|
dict->next=NULL;
|
||||||
|
dict->data=NULL;
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
|
||||||
|
repo_operation *yon_operation_new(){
|
||||||
|
repo_operation *operation = (repo_operation*)malloc(sizeof(repo_operation));
|
||||||
|
operation->package_add=NULL;
|
||||||
|
operation->package_remove=NULL;
|
||||||
|
operation->rename=NULL;
|
||||||
|
operation->target=NULL;
|
||||||
|
operation->create=0;
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *yon_string_append(char *source, char *append){
|
||||||
|
int size = (strlen(source)+strlen(append)+2);
|
||||||
|
char *n_source = (char*)malloc(sizeof(char)*size);
|
||||||
|
memset(n_source,0,size);
|
||||||
|
memcpy(n_source,source,strlen(source));
|
||||||
|
memcpy(n_source+strlen(source)," ",1);
|
||||||
|
memcpy(n_source+strlen(source)+1,append,strlen(append));
|
||||||
|
return n_source;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *yon_string_copy(char *string){
|
||||||
|
if (string){
|
||||||
|
char *str = malloc(sizeof(char)*strlen(string)+1);
|
||||||
|
memset(str,0,strlen(string)+1);
|
||||||
|
memcpy(str,string,strlen(string));
|
||||||
|
return str;
|
||||||
|
} else return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *yon_string_find_last(char *source, char *find){
|
||||||
|
|
||||||
|
for (char *found = strstr(source,find);found;found=strstr(found,find)){
|
||||||
|
if (found);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int yon_repo_proceed(int argc, char *argv[]){
|
||||||
|
int option_index=0;
|
||||||
|
int show_help=0;
|
||||||
|
{
|
||||||
|
struct option long_options[] = {
|
||||||
|
{"repo-new", 1, 0, 1},
|
||||||
|
{"package-add", 1, 0, 2},
|
||||||
|
{"package-remove", 1, 0, 3},
|
||||||
|
{"repo-rename", 1, 0, 4},
|
||||||
|
{"origin", 1, 0, 'o'},
|
||||||
|
{ NULL, 0, NULL, 0 }
|
||||||
|
};
|
||||||
|
dict_simple *dict = yon_dict_new();
|
||||||
|
repo_operation *operation = yon_operation_new();
|
||||||
|
dict->data=(void*)operation;
|
||||||
|
#define curpack(dict) ((repo_operation*)dict->data)
|
||||||
|
for (int i=0;i<argc;i++){
|
||||||
|
int argument=getopt_long(argc,argv,"o",long_options,&option_index);
|
||||||
|
switch(argument){
|
||||||
|
case 2: curpack(dict)->package_add = yon_string_append(curpack(dict)->package_add,yon_string_copy(optarg));
|
||||||
|
break;
|
||||||
|
case 3: curpack(dict)->package_remove = yon_string_append(curpack(dict)->package_add,yon_string_copy(optarg));
|
||||||
|
break;
|
||||||
|
case 4: curpack(dict)->rename=yon_string_copy(optarg);
|
||||||
|
case 1:
|
||||||
|
if (!((repo_operation*)dict->data)->target) ((repo_operation*)dict->data)->target=yon_string_copy(optarg);
|
||||||
|
else {
|
||||||
|
dict = yon_dict_append(dict);
|
||||||
|
operation = yon_operation_new();
|
||||||
|
dict->data=(void*)operation;
|
||||||
|
((repo_operation*)dict->data)->target=yon_string_copy(optarg);
|
||||||
|
}
|
||||||
|
((repo_operation*)dict->data)->create=1;
|
||||||
|
break;
|
||||||
|
case 'o':
|
||||||
|
if (!((repo_operation*)dict->data)->target) ((repo_operation*)dict->data)->target=yon_string_copy(optarg);
|
||||||
|
else {
|
||||||
|
dict = yon_dict_append(dict);
|
||||||
|
operation = yon_operation_new();
|
||||||
|
dict->data=(void*)operation;
|
||||||
|
((repo_operation*)dict->data)->target=yon_string_copy(optarg);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '?': printf("%s: %c\n",UNKNOWN_ARGUMENT_LABEL,argument);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (dict_simple *dct=dict->first;dct;dct=dct->next){
|
||||||
|
if (curpack(dct)->target){
|
||||||
|
if (curpack(dct)->create){
|
||||||
|
GKeyFile *file = g_key_file_new();
|
||||||
|
g_key_file_load_from_file(file,"/etc/pacman.conf",G_KEY_FILE_KEEP_COMMENTS,NULL);
|
||||||
|
g_key_file_set_string(file,curpack(dct)->target,"Server",curpack(dct)->target);
|
||||||
|
char *command = yon_string_append("repo-add ",curpack(dct)->target);
|
||||||
|
if (curpack(dct)->package_add){
|
||||||
|
command = yon_string_append(command," ");
|
||||||
|
command = yon_string_append(command,curpack(dct)->package_add);
|
||||||
|
}
|
||||||
|
system(command);
|
||||||
|
|
||||||
|
} else if (curpack(dct)->package_remove){
|
||||||
|
char *command = yon_string_append("repo-remove ",curpack(dct)->target);
|
||||||
|
command = yon_string_append(command," ");
|
||||||
|
command = yon_string_append(command,curpack(dct)->package_remove);
|
||||||
|
system(command);
|
||||||
|
}
|
||||||
|
if (curpack(dct)->package_add){
|
||||||
|
char *command = yon_string_append("repo-add ",curpack(dct)->target);
|
||||||
|
command = yon_string_append(command," ");
|
||||||
|
command = yon_string_append(command,curpack(dct)->package_add);
|
||||||
|
}
|
||||||
|
system(command);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]){
|
||||||
|
char *local=setlocale(LC_ALL, "");
|
||||||
|
textdomain (LocaleName);
|
||||||
|
yon_repo_proceed(argc, argv);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
#include <getopt.h>
|
||||||
|
#include <locale.h>
|
||||||
|
#include <libintl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <glib-2.0/glib.h>
|
||||||
|
#include "ubl-strings.h"
|
||||||
|
|
||||||
|
#define LocaleName "ubl-settings-repo-back"
|
||||||
|
|
||||||
|
|
||||||
|
#define _(String) gettext(String)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *target;
|
||||||
|
char *package_add;
|
||||||
|
char *package_remove;
|
||||||
|
char *rename;
|
||||||
|
int create;
|
||||||
|
|
||||||
|
} repo_operation;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
struct dict_simple *first;
|
||||||
|
struct dict_simple *next;
|
||||||
|
void *data;
|
||||||
|
} dict_simple;
|
||||||
|
|
||||||
|
char *yon_string_append(char *source, char *append);
|
||||||
|
char *yon_string_copy(char *string);
|
||||||
@ -0,0 +1 @@
|
|||||||
|
#define UNKNOWN_ARGUMENT_LABEL _("Unknown argument has been given")
|
||||||
Binary file not shown.
Loading…
Reference in new issue