Posted
Filed under Computer/package
Universial Package Manager snap testing

1. Install snap package
2. Install snapcraft (package builder)
$ sudo snap install snapcraft --classic

3. Simple Python script packaging
$ mkdir ~/work
- make a package(test-app) directory
$ mkdir ~/work/test-app

4. make a python script package
$ mkdir ~/work/test-app/myapp
$ mkdir ~/work/test-app/myapp/lib
$ vi ~/work/test-app/myapp/lib/TM.py
------------------------------------------------------------
from datetime import datetime
def now():
    return datetime.now().strftime('%s')
------------------------------------------------------------
$ touch ~/work/test-app/myapp/lib/__init__.py
$ vi ~/work/test-app/myapp/test_run
------------------------------------------------------------
#!/usr/bin/env python3
from lib import TM
def main():
    print('Hello, I am main()')
    aa=TM.now()
    input("now second is:{}".format(aa))
if __name__ == '__main__':
    main()
------------------------------------------------------------

5. make a snap configuration
$ mkdir ~/work/test-app/snap
$ vi ~/work/test-app/snap/snapcraft.yaml
------------------------------------------------------------
name:           test-app # package name
version:        '1.1'        # package version
summary:        Example python snap app
description: |
    Example python snap app description
base: core20      # Common Base OS ( 18: ubuntu 18.04, 20: ubuntu 20.04, 22: ubuntu 22.04 )
grade:          stable
confinement:    devmode
apps:
  test-app:  #Package name
    command:    myapp/test_run  #running command path and filename (/snap/bin/<package name> will running the command line path file)
    ## If need special path for shell script
    #command: sh $SNAP/opt/foo/bin/foo.sh
parts:
  test-app:
    source: . #my local directory is source
    ## When copy a file(shell/python/built binary file) to somewhere
    plugin:     dump 
    organize:
          src/myapp: .     # start with "src/" and my files are in the src directory. (copy the myapp directory)
    ## When use python setup.py to install application then use python plugin
    #plugin:     python
    #python-version: python3
------------------------------------------------------------

6. build 
$ cd ~/work/test-app
$ snapcraft

7. Install
$ snap install test-app_1.1_amd64.snap --devmode

8. check 
$ snap list |grep test-app
test-app             1.1                         x1     -                -            devmode
$ df -h
~~~
/dev/loop3                 128K  128K     0 100% /snap/test-app/x1
$ ls -l /snap/bin/test-app 
lrwxrwxrwx 1 root root 13 Aug  1 14:18 /snap/bin/test-app -> /usr/bin/snap
$ /snap/bin/test-app 
Hello, I am main()
now second is:1659388777

ETC & Tools)
$ cat cleanup_multipath_snapcraft_built_garbage.sh 
-------------------------------------------------------------------------------------------------------------
#!/bin/bash -x
## snapcraft-created multipass VMs
for vm in $(multipass list | awk '{print $1}' | grep "^snapcraft-"); do
    multipass delete $vm --purge
done
## snapcraft-created LXD containers
#for c in $(lxc list | awk '{print $2}' | grep "^snapcraft-" | grep -v "snapcraft-dev"); do
#    lxc delete $c --force
#done
-------------------------------------------------------------------------------------------------------------

$ cat remove_disabled_snap.sh 
-------------------------------------------------------------------------------------------------------------
#!/bin/bash
set -eu
LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' |
    while read snapname revision; do
        snap remove "$snapname" --revision="$revision"
    done
-------------------------------------------------------------------------------------------------------------

Remove Package
$ snap remove <package name>
other commands: https://www.cyberithub.com/36-popular-snap-command-examples-in-linux/


Few other snap configuration files example:
a) automatically use bin directory in local directory (Some updated code)
    original : https://github.com/gocarlos/python-ubuntu-snap-app-example
$ ls                    
bin  LICENSE  myapp_module  mygreatapp_1.0_amd64.snap  README.md  requirements.txt  snap
$ cat requirements.txt 
numpy
$ cat bin/my_great_app 
#!/usr/bin/env python3
from myapp_module import my_great_app
"""
    my application.
"""
def main():
    """run the application"""
    print('I\'m inside main')
    my_great_app.tata()
    input("Press enter to exit ;)")
    input()
if __name__ == '__main__':
    main()
$ ls myapp_module/
__init__.py  my_great_app.py
$ cat myapp_module/my_great_app.py 
#!/usr/bin/env python3
def tata():
    print ('you could do great stuff inside this function.')
    
def fun(x):
    return x + 1
$ cat snap/snapcraft.yaml 
name:           mygreatapp
version:        '1.0'
summary:        Example python snap app
description: |
    Example python snap app
base: core18
grade:          stable
confinement:    devmode
apps:
  mygreatapp:
    command:    my_great_app
parts:
  mygreatapp:
    plugin:     python
    python-version: python3
    source: .

b)  Automatically build and package from remote source file.
$ cat snap/snapcraft.yaml 
name: hello
base: core18
version: '2.10'
summary: GNU Hello, the "hello world" snap
description: |
  GNU hello prints a friendly greeting.
grade: devel
confinement: devmode
parts:
  gnu-hello:
    source: http://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz
    plugin: autotools
2022/08/02 06:32 2022/08/02 06:32
[로그인][오픈아이디란?]
Posted
Filed under Computer/package


Simple IPMI Tool v1.0.43
 - Check IPMI IP Address
 - Send IPMI connand at multi thread
ipmi <cmd> [-T <thread num:20>] [-U <user:ADMIN>] [-P <password:ADMIN>] [-p <port:623>] -H <ip1,ip2,...>
power <status,on,off,reset,cycle,shutdown> : Power handle
sdr            : Show full SDR Info
sdr <record ID>: Show SDR <record ID>'s Info
sdr list       : Show list
sel            : Show SEL List
fru            : Show FRU Info
raw <raw cmd>  : Run <raw cmd>
bmc info       : Show BMC Info
bmc reset cold : BMC Cold reset
bmc reset warm : BMC Warm reset 


This will be fast send IPMI command to multi node.
But, it is very inital version.



2020/06/18 04:23 2020/06/18 04:23
[로그인][오픈아이디란?]
Posted
Filed under Computer/package
$ ./sdr_temp_mon 
./sdr_temp_mon <bmc ip> [-b <bmc user> <bmc pass>] [-i <#|#m|#h>] [-l <log filename>] [-t <CPU,DIMM,...>] [-f <time format>]
-i : interval (default : 5seconds)
   <#>  : # seconds
   <#m> : # min
   <#h> : # hours
-b : BMC User & Password (default: ADMIN ADMIN)
-l : Logging the data to file, split data with "," symbol
-t : Temp monitoring items (default: CPU,DIMM) (ex: CPU,DIMM,System,...)
-f : Time Format (default: %H:%M:%S)


Monitor with System temperature and time display with date and seconds
$ ./sdr_temp_mon <BMC IP> -t CPU,DIMM,System -f "%m-%d %H:%M:%S"
                     time       CPU    System    DIMMA1    DIMMB1    DIMMD1    DIMME1
      12-26 14:49:41        51            34              32                              
      12-26 14:49:47        51            34              32                              
      12-26 14:49:52        50            34              32            

Base monitor with display HH:MM each 2min.
$ ./sdr_temp_mon <BMC IP> -i 2m -f "%H:%M"
                 time       CPU    DIMMA1    DIMMB1    DIMMD1    DIMME1
               14:50          51              32                              
               14:52          51              32        
If you want DIMM only at each 5seconds.
$ ./sdr_temp_mon <BMC IP> -t DIMM
                    time    DIMMA1    DIMMB1    DIMMD1    DIMME1
            14:53:27               32                              
            14:53:32               32               


Check available monitoring items:
# ipmitool -H <BMC IP> -U <User> -P <Password> sdr type Temperature
CPU Temp         | 01h | ok  |  3.1 | 49 degrees C
PCH Temp         | 0Ah | ok  |  7.1 | 54 degrees C
System Temp      | 0Bh | ok  |  7.2 | 34 degrees C
Peripheral Temp  | 0Ch | ok  |  7.3 | 35 degrees C
MB_10G Temp      | 0Dh | ok  |  7.4 | 40 degrees C
VRMCpu Temp      | 10h | ok  |  7.16 | 59 degrees C
VRMAB Temp       | 12h | ok  |  7.18 | 38 degrees C
VRMDE Temp       | 13h | ok  |  7.19 | 42 degrees C
DIMMA1 Temp      | B0h | ok  | 32.0 | 31 degrees C
DIMMB1 Temp      | B2h | ns  | 32.2 | No Reading
DIMMD1 Temp      | B6h | ns  | 32.6 | No Reading
DIMME1 Temp      | B8h | ns  | 32.8 | No Reading
U2NVMeSSD1 Temp  | 4Bh | ns  |  7.48 | No Reading
U2NVMeSSD2 Temp  | 4Ch | ns  |  7.49 | No Reading


You can use "DIMMA1" or "DIMM" for memory monitoring
DIMM will monitor all Dimm,
DIMMA1 will monitor with DIMMA1 location only.

You can check with above ipmitool command and can use bold string for the monitoring's "-t" option


2019/12/27 08:05 2019/12/27 08:05
[로그인][오픈아이디란?]
Posted
Filed under Computer/package
Enhanced sorting string lines.
It made by Python script.
Download it and change permission (chmod +x ./ksort)
and you can use it, if the system installed python.



$ ./ksort --help
usage: ksort [-h] [-v] [-i ID] [-s SYMBOL] [-p PRINTID] [-n NEWLINE] [-r]
             [-f FILE]
             [otherthings [otherthings ...]]
ksort for sorting string lines or sorting string lines in file
positional arguments:
  otherthings
optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -i ID, --field_id ID  sorting filed id (start from 0), only one, it should
                        need -s option
  -s SYMBOL, --field_symbol SYMBOL
                        field spliting symbol (space ex: space for all white
                        space, ' ' for only one space, it should need -i
                        option)
  -p PRINTID, --print_field PRINTID
                        print field id(start from 0) (ex: 1,3,...), it should
                        need -i and -s option
  -n NEWLINE, --newline NEWLINE
                        new line symbol (default: Linux (\n))
  -r, --reverse         reverse sort
  -m, --num             numerical sort
  -f FILE, --file FILE  Input text file
example)
sorting string:
./ksort "1
6
9
3
2
7"
reverse sorting string:
./ksort -r "1
6
9
3
2
7"
sorting file size :
./ksort -i 4 -s space "$(ls -l)"
sorting file size reverse:
./ksort -i 4 -s space -r "$(ls -l)"
sorting file size, and print size and filename:
./ksort -i 4 -s space -p 8,4 "$(ls -l)"


                                                                 ksort version 0.1.11
Inhanced inside sorting function. but, help command will issue. So, you can use help instruction with this page. 
                                                                   ksort version : 1.2.49
2018/09/13 03:00 2018/09/13 03:00
[로그인][오픈아이디란?]
Posted
Filed under Computer/package
k (1.1.3.101) command python version.

"k" command helpful console work and saving and searching your idea to the command's DB.
This is very simple command. but sometimes helpful to you.

Install :
1. download cep.pyc and k.py file (If you want sample DB file then download cep.db file)
2. copy thoese file to your bin directory.
3. mv k.py to k or make a soft link as "ln -s k.py k"
4. change permission to excutable (chmod +x k.py)
5. set your bin directory to PATH ( ex: ~/bin ,  echo "export PATH=${PATH}:~/bin" >> ~/.bashrc )
If your system have no python3 version then modify k.py file from "python3" to "python" at first line in k.py file.


Help:
$ k --help
CEP(Kage) personal command and library
  for helping CEP
  version: 1.1.3.101
  lib ver: 1.8.6.85

Usage)
/Users/kpark/bin/k <option>

 --help [<module>] : help [ for <module>]
 -v(--version) : version
 -b(--build) <file>    : build to binary file
 -m(--module) -b(--build) <file> : build to library file
 -h <hostname> : Make a hostname list

/Users/kpark/bin/k <command> [<option of command>]

 show/look/what            : show DB
   ( Make a done a task in show command )
 save/add                  : save to DB
 update/change/replace     : update to DB (*** Not support yet, just scheduled)
 recover                   : recover from trash to original DB (*** Not support yet, just scheduled)
 memory/remember           : save to DB
 forget/del/delete/trash   : remove in DB
 search  <string>          : find a <string> in all DB
 cleanup                   : Cleanup garbage data in DB file
 cleanup trash [all]       : Cleanup trash DB (all: make a empty trash) (default: remain 7days trash from now on)
 pkg                       : Package handle

 ping [<option of command>]
 ssh [<option of command>] -h [<id>@]<host> [<command>]
 scp [<option of command>] <file> [<id>@]<host>:[<path>]
 rsync [<option of command>] <file> [<id>@]<host>:[<path>]
 vi [<option of command>] <file>


Example)
make a your own domain system.
$ k add host <hostname> --ip <ip> [ --desc "<descriptions>" ] [ --keyfile <ssh password less key file> ]
$ k add host my_laptop --ip 192.168.1.100
$ k add host my_laptop1 --ip 192.168.1.101 --desc "testing server"
$ k add host my_laptop2 --ip 192.168.1.102 --desc "password less ssh server" --keyfile ~/.ssh/id_rsa

Show host list
$ k show host
192.168.1.100  my_laptop :
192.168.1.101  my_laptop1 : testing server
192.168.1.102  my_laptop2 : password less ssh server

SSH/SCP/PING command ( command expression is same as Linux default commands )
$ k ping my_laptop
PING 192.168.1.100 (192.168.1.100): 56 data bytes
64 bytes from 192.168.1.100: icmp_seq=0 ttl=64 time=1.472 ms
64 bytes from 192.168.1.100: icmp_seq=1 ttl=64 time=0.622 ms

$ k ssh me@my_laptop2
Warning: Permanently added '192.168.1.102' (ECDSA) to the list of known hosts.
Last login: Fri Aug 19 14:53:40 2016 from 192.168.1.100
my_laptop2:~ me$
<< Automatically download ssh-key data from DB and using ssh with temporary file and removed it >>

scp also using ssh-key file from DB.

SSH/SCP/PING/RSYNC finding from DB and /etc/hosts and DNS. if using IP then just using the IP.
So, no matter what working as normal your operation on your linux box.

Your own shell script commands :
if you make a simple script then your can add your script to the DB.
and you can use your own script from "k" command.

example)
$ k show shell
1471648123.631903 k

make a sample script
$ k k.k make_temp test

$ k vi test.k
<< modify  k shell for you >>

Add the test.k (k shell) to DB.
$ k add shell test --file test.k
Saved

$k show shell
1471648123.631903 k
1471648164.937767 test

Run the k shell from "k" command.
$ k kage$ k test --help
sh [<opt> [<input>] ]  <== this is a bug at marge from old k shell to "k" command.
  sh <filename> <== this is a bug at marge from old k shell to "k" command.

  --help : help
  -t <string> : test

$ k test -t abc
abc


k shell example)
_k_test() {
  << main code >>
}

This "_k_<command name>() {}" is main function.
If you want using k shell then you can add "#include k.k" in your script like as test.k script.
Then you can use k shell scripting.

very simple test2 script.
$ vi test2.k
_k_test2() {
    if [ "$1" == "--help" ]; then
          echo "My test2 help"
          exit
    elif [ "$1" == "-show" ]; then
         shift 1
         echo $*
    else
         echo $*
    fi
}

very simple test3 script.
$ vi test3.k
#include k.k
_k_test3() {
    opt=("$@")
    if _k_opt --help 0 0 "${opt[@]}" >/dev/null; then
          echo "My test3 help"
          exit
   elif get_val=$(_k_opt -t 1 0 "${opt[@]}"); then
      _k_test3_sample $get_val || return 1
   else
            echo "Unknown option"
            _k_exit 1
   fi
}

_k_test3_sample() {
     echo $*
}


It has no update function yet.
So, if you save wrong information or no more need saved information then please remove the information and re-add new information.

If you remove a data in DB then the data will be saved at trash table in the same DB.
So, you can recover it later. (not yet support recover function)

and you can use any linux command with "k" command like this.
$ k ls -F
Documents/                   initial-setup-ks.cfg           python/     Videos/
Downloads/    anaconda-ks.cfg   Pictures/  rpmbuild/   bin/               Desktop/
Music/                    Public/    Templates/

$ k cat -A anaconda-ks.cfg  | more
#version=RHEL7$
# System authorization information$
auth --enableshadow --passalgo=sha512$

2016/08/20 20:38 2016/08/20 20:38
[로그인][오픈아이디란?]