first commit

master
Rinsvent 2 years ago
commit 95b0445159
  1. 1
      .gitignore
  2. 6
      Makefile
  3. 4
      framework.c
  4. 10
      package/DEBIAN/control
  5. BIN
      package/usr/bin/framework
  6. 16
      src/docker-compose.sh
  7. 11
      src/docker-compose.test.sh
  8. 9
      src/io.sh
  9. 9
      src/io.test.sh
  10. 85
      src/logger.sh
  11. 26
      src/logger.test.sh
  12. 16
      src/var.sh
  13. 11
      src/var.test.sh

1
.gitignore vendored

@ -0,0 +1 @@
build

@ -0,0 +1,6 @@
compile:
gcc ./framework.c -o ./build/framework
build:
dpkg-deb --build ./package

@ -0,0 +1,4 @@
#include <stdio.h>
int main(){
printf("Hello from losst.ru\n");
}

@ -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

Binary file not shown.

@ -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
}

@ -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"

@ -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
}

@ -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

@ -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
}

@ -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 !!!'

@ -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
}

@ -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…
Cancel
Save