first commit
This commit is contained in:
commit
95b0445159
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
build
|
6
Makefile
Normal file
6
Makefile
Normal file
@ -0,0 +1,6 @@
|
||||
compile:
|
||||
gcc ./framework.c -o ./build/framework
|
||||
|
||||
build:
|
||||
dpkg-deb --build ./package
|
||||
|
4
framework.c
Normal file
4
framework.c
Normal file
@ -0,0 +1,4 @@
|
||||
#include <stdio.h>
|
||||
int main(){
|
||||
printf("Hello from losst.ru\n");
|
||||
}
|
10
package/DEBIAN/control
Normal file
10
package/DEBIAN/control
Normal file
@ -0,0 +1,10 @@
|
||||
Package: framework
|
||||
Version: 1.0
|
||||
Section: unknown
|
||||
Priority: optional
|
||||
Depends: libc6
|
||||
Architecture: amd64
|
||||
Essential: no
|
||||
Installed-Size: 20
|
||||
Maintainer: Rinsvent <rinsvent007@gmail.com>
|
||||
Description: Include prepared bash functions
|
BIN
package/usr/bin/framework
Executable file
BIN
package/usr/bin/framework
Executable file
Binary file not shown.
16
src/docker-compose.sh
Normal file
16
src/docker-compose.sh
Normal file
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
getEnv() {
|
||||
VAR_NAME=$1
|
||||
VAR_VALUE=${!VAR_NAME}
|
||||
if [ -z $VAR_VALUE ]
|
||||
then
|
||||
if [ $# -eq 2 ]
|
||||
then
|
||||
VAR_VALUE=$2
|
||||
else
|
||||
VAR_VALUE=NULL
|
||||
fi
|
||||
fi
|
||||
RETURN=$VAR_VALUE
|
||||
}
|
11
src/docker-compose.test.sh
Normal file
11
src/docker-compose.test.sh
Normal file
@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
TEMP=5234
|
||||
. ./env.sh
|
||||
|
||||
getEnv TEMP false
|
||||
echo "RESULT $RETURN"
|
||||
getEnv TEMP2 false
|
||||
echo "RESULT $RETURN"
|
||||
getEnv TEMP2
|
||||
echo "RESULT $RETURN"
|
9
src/io.sh
Normal file
9
src/io.sh
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
filePutContent() {
|
||||
local FILE_PATH=$1
|
||||
DIRECTORY_PATH=$(dirname $FILE_PATH)
|
||||
mkdir -p $DIRECTORY_PATH
|
||||
touch $FILE_PATH
|
||||
echo $2 >> $FILE_PATH
|
||||
}
|
9
src/io.test.sh
Normal file
9
src/io.test.sh
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
. ./io.sh
|
||||
|
||||
filePutContent ./temp.txt "Content was added successfuly1"
|
||||
filePutContent ./temp.txt "Content was added successfuly2"
|
||||
|
||||
cat ./temp.txt
|
||||
unlink ./temp.txt
|
85
src/logger.sh
Normal file
85
src/logger.sh
Normal file
@ -0,0 +1,85 @@
|
||||
#!/bin/bash
|
||||
|
||||
. ./var.sh
|
||||
. ./io.sh
|
||||
|
||||
# logger levels
|
||||
# error = 1
|
||||
# warning = 2
|
||||
# info = 3
|
||||
# debug = 9
|
||||
|
||||
getVar LOGGER_LEVEL 1
|
||||
LOGGER_LEVEL=$RETURN
|
||||
|
||||
getVar LOG_PATH ''
|
||||
LOG_PATH=$RETURN
|
||||
|
||||
ENDCOLOR="\e[0m"
|
||||
|
||||
function getLogPath() {
|
||||
getVar LOG_PATH ''
|
||||
local LOCAL_LOG_PATH=$RETURN
|
||||
|
||||
local YEAR
|
||||
YEAR=$(date +%Y)
|
||||
LOCAL_LOG_PATH=$(echo "$LOCAL_LOG_PATH" | sed -r "s/%Y/$YEAR/g")
|
||||
|
||||
local MONTH
|
||||
MONTH=$(date +%m)
|
||||
LOCAL_LOG_PATH=$(echo "$LOCAL_LOG_PATH" | sed -r "s/%m/$MONTH/g")
|
||||
|
||||
local DAY
|
||||
DAY=$(date +%d)
|
||||
LOCAL_LOG_PATH=$(echo "$LOCAL_LOG_PATH" | sed -r "s/%d/$DAY/g")
|
||||
|
||||
local HOUR
|
||||
HOUR=$(date +%H)
|
||||
LOCAL_LOG_PATH=$(echo "$LOCAL_LOG_PATH" | sed -r "s/%H/$HOUR/g")
|
||||
|
||||
local MINUTE
|
||||
MINUTE=$(date +%M)
|
||||
LOCAL_LOG_PATH=$(echo "$LOCAL_LOG_PATH" | sed -r "s/%i/$MINUTE/g")
|
||||
|
||||
RETURN=$LOCAL_LOG_PATH
|
||||
}
|
||||
|
||||
function writeFileLog() {
|
||||
getLogPath
|
||||
local LOG_PATH=$RETURN
|
||||
if [[ -n $LOG_PATH ]]
|
||||
then
|
||||
filePutContent "$LOG_PATH" "$(date "+%Y.%m.%d %H:%I:%S") [$2] $1"
|
||||
fi
|
||||
}
|
||||
|
||||
function error()
|
||||
{
|
||||
echo -e "\e[0m\E[41m\n!\n! [ERROR] $1\n!$ENDCOLOR" >&2
|
||||
writeFileLog "$1" "ERROR"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function warning()
|
||||
{
|
||||
if [ "$LOGGER_LEVEL" -gt 1 ]; then
|
||||
echo -e "\e[0m\E[43m\n!\n! [WARNING] $1\n!$ENDCOLOR" >&2
|
||||
writeFileLog "$1" "WARNING"
|
||||
fi
|
||||
}
|
||||
|
||||
function info
|
||||
{
|
||||
if [ "$LOGGER_LEVEL" -gt 2 ]; then
|
||||
echo -e "\e[0m\E[102m\n!\n! [INFO] $1\n!$ENDCOLOR" >&2
|
||||
writeFileLog "$1" "INFO"
|
||||
fi
|
||||
}
|
||||
|
||||
function debug
|
||||
{
|
||||
if [ "$LOGGER_LEVEL" -gt 8 ]; then
|
||||
echo -e "\e[0m\E[44m\n!\n! [DEBUG] $1\n!$ENDCOLOR" >&2
|
||||
writeFileLog "$1" "DEBUG"
|
||||
fi
|
||||
}
|
26
src/logger.test.sh
Normal file
26
src/logger.test.sh
Normal file
@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
LOG_PATH=./log%Y%m%d_%H%i
|
||||
. ./logger.sh
|
||||
|
||||
CURRENT_LOG_PATH=./log$(date +%Y%m%d_%H%M)
|
||||
|
||||
debug '23542'
|
||||
|
||||
LOGGER_LEVEL=9
|
||||
info '!!! info !!!'
|
||||
warning '!!! warning !!!'
|
||||
debug '!!! debug !!!'
|
||||
|
||||
echo -e "\nsadf"
|
||||
cat "$CURRENT_LOG_PATH"
|
||||
|
||||
error '!!! error !!!' &
|
||||
|
||||
sleep 1
|
||||
unlink "$CURRENT_LOG_PATH"
|
||||
LOG_PATH=""
|
||||
|
||||
error '!!! error2 !!!'
|
||||
|
||||
debug '!!! debug2 !!!'
|
16
src/var.sh
Normal file
16
src/var.sh
Normal file
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
getVar() {
|
||||
VAR_NAME=$1
|
||||
VAR_VALUE=${!VAR_NAME}
|
||||
if [ -z $VAR_VALUE ]
|
||||
then
|
||||
if [ $# -eq 2 ]
|
||||
then
|
||||
VAR_VALUE=$2
|
||||
else
|
||||
VAR_VALUE=NULL
|
||||
fi
|
||||
fi
|
||||
RETURN=$VAR_VALUE
|
||||
}
|
11
src/var.test.sh
Normal file
11
src/var.test.sh
Normal file
@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
TEMP=5234
|
||||
. ./var.sh
|
||||
|
||||
getVar TEMP false
|
||||
echo "RESULT $RETURN"
|
||||
getVar TEMP2 false
|
||||
echo "RESULT $RETURN"
|
||||
getVar TEMP2
|
||||
echo "RESULT $RETURN"
|
Loading…
Reference in New Issue
Block a user