Quantcast
Channel: 可丁丹尼 @ 一路往前走2.0
Viewing all 79 articles
Browse latest View live

列出 USB Plug 資訊

$
0
0

USB Plug資訊可以由udevadm info [device name or path],但往往插入USB後跟本不知道產生週邊對應的資訊,可能知道在/sys/bus/usb/devices/,執行ls -l得到結果如下:

/sys/bus/usb/devices $ ls -la
total 0
drwxr-xr-x 2 root root 0 May 17 13:17 .
drwxr-xr-x 4 root root 0 May 17 13:17 ..
lrwxrwxrwx 1 root root 0 May 17 13:17 1-0:1.0 -> ../../../devices/platform/soc/3f980000.usb/usb1/1-0:1.0
lrwxrwxrwx 1 root root 0 May 17 13:17 1-1 -> ../../../devices/platform/soc/3f980000.usb/usb1/1-1
lrwxrwxrwx 1 root root 0 May 17 13:17 1-1.1 -> ../../../devices/platform/soc/3f980000.usb/usb1/1-1/1-1.1
lrwxrwxrwx 1 root root 0 May 17 13:17 1-1.1:1.0 -> ../../../devices/platform/soc/3f980000.usb/usb1/1-1/1-1.1/1-1.1:1.0
lrwxrwxrwx 1 root root 0 May 17 13:17 1-1:1.0 -> ../../../devices/platform/soc/3f980000.usb/usb1/1-1/1-1:1.0
lrwxrwxrwx 1 root root 0 May 17 13:17 usb1 -> ../../../devices/platform/soc/3f980000.usb/usb1

這個列表比較不直覺,接下來可以利用幾個命令取直接取得真實的位置

查看USB周邊

//-----------start-----------
lsusb
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
//------------end------------

上面列表的ID格式為:ID [vid]:[pid],記住格式,下面會利用這兩個資訊直接找到實際位置

取得USB週邊

雖然使用lsusb能看到接了什麼樣的USB週邊,但還是無法資料較詳細的資訊,下面script可以由pidvid取得在linux上實際產生的資訊的位置

//-----------start-----------
idVendor="vid"; idProduct="pid";   find -L /sys/bus/usb/devices/ -maxdepth 2 -name idVendor -exec grep -l $idVendor {} \; |     while read line; do       location=$(dirname $line);       grep -q $idProduct $location/idProduct;        if [ "$?" -eq "0" ]; then         echo $location;        fi ;     done
//------------end------------

只要修改idProduct(pid)、idVendor(vid)的內容就可以由pidvid找到,這次要查詢ID 0424:ec00代入

//-----------start-----------
idVendor="0424"; idProduct="ec00";   find -L /sys/bus/usb/devices/ -maxdepth 2 -name idVendor -exec grep -l $idVendor {} \; |     while read line; do       location=$(dirname $line);       grep -q $idProduct $location/idProduct;        if [ "$?" -eq "0" ]; then         echo $location;        fi ;     done
//------------end------------

執行範例:

script貼入shell執行

//-----------start-----------
idVendor="0424"; idProduct="ec00";   find -L /sys/bus/usb/devices/ -maxdepth 2 -name idVendor -exec grep -l $idVendor {} \; |     while read line; do       location=$(dirname $line);       grep -q $idProduct $location/idProduct;        if [ "$?" -eq "0" ]; then         echo $location;        fi ;     done
/sys/bus/usb/devices/1-1.1
//------------end------------

得到結果/sys/bus/usb/devices/1-1.1

取得Plug 資訊

從上面資訊取得Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter在Linux 位置/sys/bus/usb/devices/1-1.1,使用udevadm查看資訊

執行:

udevadm info /sys/bus/usb/devices/1-1.1

結果:

P: /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.1
N: bus/usb/001/003
L: 0
E: DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.1
E: DEVNAME=/dev/bus/usb/001/003
E: DEVTYPE=usb_device
E: DRIVER=usb
E: OF_NAME=usbether
E: OF_FULLNAME=/soc/usb@7e980000/usb1@1/usbether@1
E: OF_COMPATIBLE_0=usb424,ec00
E: OF_COMPATIBLE_N=1
E: OF_ALIAS_0=ethernet0
E: PRODUCT=424/ec00/200
E: TYPE=255/0/1
E: BUSNUM=001
E: DEVNUM=003
E: MAJOR=189
E: MINOR=2
E: SUBSYSTEM=usb
E: USEC_INITIALIZED=9975919
E: ID_VENDOR=0424
E: ID_VENDOR_ENC=0424
E: ID_VENDOR_ID=0424
E: ID_MODEL=ec00
E: ID_MODEL_ENC=ec00
E: ID_MODEL_ID=ec00
E: ID_REVISION=0200
E: ID_SERIAL=0424_ec00
E: ID_BUS=usb
E: ID_USB_INTERFACES=:ff00ff:
E: ID_VENDOR_FROM_DATABASE=Standard Microsystems Corp.
E: ID_MODEL_FROM_DATABASE=SMSC9512/9514 Fast Ethernet Adapter

要更詳細資訊加入-a -p參數

udevadm info -a -p /sys/bus/usb/devices/1-1.1

結果:

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

looking at device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.1':
KERNEL=="1-1.1"
SUBSYSTEM=="usb"
DRIVER=="usb"
ATTR{configuration}==""
ATTR{devpath}=="1.1"
ATTR{bConfigurationValue}=="1"
ATTR{bDeviceProtocol}=="01"
ATTR{bcdDevice}=="0200"
ATTR{bNumInterfaces}==" 1"
ATTR{devnum}=="3"
ATTR{bmAttributes}=="e0"
ATTR{bMaxPacketSize0}=="64"
ATTR{urbnum}=="5815803"
ATTR{bDeviceClass}=="ff"
ATTR{ltm_capable}=="no"
ATTR{maxchild}=="0"
ATTR{tx_lanes}=="1"
ATTR{version}==" 2.00"
ATTR{avoid_reset_quirk}=="0"
ATTR{speed}=="480"
ATTR{quirks}=="0x0"
ATTR{bMaxPower}=="2mA"
ATTR{bNumConfigurations}=="1"
ATTR{bDeviceSubClass}=="00"
ATTR{idVendor}=="0424"
ATTR{rx_lanes}=="1"
ATTR{busnum}=="1"
ATTR{authorized}=="1"
ATTR{idProduct}=="ec00"
ATTR{removable}=="fixed"

looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1':
KERNELS=="1-1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{bmAttributes}=="e0"
ATTRS{bNumInterfaces}==" 1"
ATTRS{bcdDevice}=="0200"
ATTRS{maxchild}=="5"
ATTRS{tx_lanes}=="1"
ATTRS{bDeviceProtocol}=="02"
ATTRS{busnum}=="1"
ATTRS{devpath}=="1"
ATTRS{rx_lanes}=="1"
ATTRS{quirks}=="0x0"
ATTRS{configuration}==""
ATTRS{bNumConfigurations}=="1"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{devnum}=="2"
ATTRS{idProduct}=="9514"
ATTRS{bDeviceClass}=="09"
ATTRS{idVendor}=="0424"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{speed}=="480"
ATTRS{urbnum}=="29"
ATTRS{bConfigurationValue}=="1"
ATTRS{bMaxPower}=="2mA"
ATTRS{bDeviceSubClass}=="00"
ATTRS{removable}=="unknown"
ATTRS{ltm_capable}=="no"
ATTRS{version}==" 2.00"
ATTRS{authorized}=="1"

looking at parent device '/devices/platform/soc/3f980000.usb/usb1':
KERNELS=="usb1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{rx_lanes}=="1"
ATTRS{ltm_capable}=="no"
ATTRS{bNumConfigurations}=="1"
ATTRS{bDeviceProtocol}=="01"
ATTRS{bcdDevice}=="0510"
ATTRS{idVendor}=="1d6b"
ATTRS{authorized}=="1"
ATTRS{devnum}=="1"
ATTRS{serial}=="3f980000.usb"
ATTRS{urbnum}=="26"
ATTRS{interface_authorized_default}=="1"
ATTRS{bNumInterfaces}==" 1"
ATTRS{authorized_default}=="1"
ATTRS{removable}=="unknown"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{configuration}==""
ATTRS{speed}=="480"
ATTRS{maxchild}=="1"
ATTRS{product}=="DWC OTG Controller"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{bDeviceClass}=="09"
ATTRS{bConfigurationValue}=="1"
ATTRS{bMaxPower}=="0mA"
ATTRS{busnum}=="1"
ATTRS{manufacturer}=="Linux 5.10.17-v7+ dwc_otg_hcd"
ATTRS{quirks}=="0x0"
ATTRS{bmAttributes}=="e0"
ATTRS{tx_lanes}=="1"
ATTRS{devpath}=="0"
ATTRS{idProduct}=="0002"
ATTRS{bDeviceSubClass}=="00"
ATTRS{version}==" 2.00"

looking at parent device '/devices/platform/soc/3f980000.usb':
KERNELS=="3f980000.usb"
SUBSYSTEMS=="platform"
DRIVERS=="dwc_otg"
ATTRS{mode}=="Mode = 0x1"
ATTRS{fr_interval}=="Frame Interval = 0x1d4b"
ATTRS{spramdump}=="SPRAM Dump"
ATTRS{devspeed}=="Device Speed = 0x0"
ATTRS{hprt0}=="HPRT0 = 0x00001005"
ATTRS{buspower}=="Bus Power = 0x1"
ATTRS{bussuspend}=="Bus Suspend = 0x0"
ATTRS{hcddump}=="HCD Dump"
ATTRS{regvalue}=="invalid offset"
ATTRS{hnp}=="HstNegScs = 0x0"
ATTRS{mode_ch_tim_en}=="Mode Change Ready Timer Enable = 0x0"
ATTRS{gsnpsid}=="GSNPSID = 0x4f54280a"
ATTRS{hsic_connect}=="HSIC Connect = 0x1"
ATTRS{grxfsiz}=="GRXFSIZ = 0x00000306"
ATTRS{srp}=="SesReqScs = 0x1"
ATTRS{gpvndctl}=="GPVNDCTL = 0x00000000"
ATTRS{regoffset}=="0xffffffff"
ATTRS{remote_wakeup}=="Remote Wakeup Sig = 0 Enabled = 0 LPM Remote Wakeup = 0"
ATTRS{wr_reg_test}=="Time to write GNPTXFSIZ reg 10000000 times: 740 msecs (74 jiffies)"
ATTRS{driver_override}=="(null)"
ATTRS{gotgctl}=="GOTGCTL = 0x001c0001"
ATTRS{gusbcfg}=="GUSBCFG = 0x20001700"
ATTRS{ggpio}=="GGPIO = 0x00000000"
ATTRS{guid}=="GUID = 0x2708a000"
ATTRS{rd_reg_test}=="Time to read GNPTXFSIZ reg 10000000 times: 1410 msecs (141 jiffies)"
ATTRS{hptxfsiz}=="HPTXFSIZ = 0x02000406"
ATTRS{inv_sel_hsic}=="Invert Select HSIC = 0x0"
ATTRS{regdump}=="Register Dump"
ATTRS{srpcapable}=="SRPCapable = 0x1"
ATTRS{rem_wakeup_pwrdn}==""
ATTRS{hcd_frrem}=="HCD Dump Frame Remaining"
ATTRS{busconnected}=="Bus Connected = 0x1"
ATTRS{enumspeed}=="Device Enumeration Speed = 0x1"
ATTRS{gnptxfsiz}=="GNPTXFSIZ = 0x01000306"
ATTRS{hnpcapable}=="HNPCapable = 0x1"

looking at parent device '/devices/platform/soc':
KERNELS=="soc"
SUBSYSTEMS=="platform"
DRIVERS==""
ATTRS{driver_override}=="(null)"

looking at parent device '/devices/platform':
KERNELS=="platform"
SUBSYSTEMS==""
DRIVERS==""

The post 列出 USB Plug 資訊 appeared first on 可丁丹尼 @ 一路往前走2.0.


20210525-systemctl 取得 service pid

$
0
0

一般來說,查看service狀態會執行命令

systemctl status rfidgw

然後就會看到該service狀態

//-----------start-----------
● rfidgw.service - rfidgw service description
Loaded: loaded (/lib/systemd/system/rfidgw.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2021-05-24 15:12:17 CST; 1min 51s ago
Process: 6823 ExecStartPre=/usr/bin/touch /var/log/heartgw.log (code=exited, status=0/SUCCESS)
Main PID: 6824 (rfidgw_spi1)
Tasks: 7 (limit: 2062)
CGroup: /system.slice/rfidgw.service
└─6824 /home gw rfidgw rfidgw_spi1

May 24 15:12:19 DMGW-43A rfidgw_spi1[6824]: 15:12:19.079: DMGW_UUID:1d0c0fcc-f805-4e67-92d7-a72e2b7ca724
May 24 15:12:19 DMGW-43A rfidgw_spi1[6824]: 15:12:19.112: Repy_Handler:: 21081
May 24 15:12:19 DMGW-43A rfidgw_spi1[6824]: 15:12:19.112: SOC_SERIAL:000000004B1B363F
May 24 15:12:19 DMGW-43A rfidgw_spi1[6824]: 15:12:19.113: HOSTNAME:DMGW-43A
May 24 15:12:19 DMGW-43A rfidgw_spi1[6824]: 15:12:19.113: ==[ RFIDGW_RESTART_REASON:null ]==
May 24 15:12:19 DMGW-43A rfidgw_spi1[6824]: 15:12:19.152: RFID_A7127_ProcTH
May 24 15:12:19 DMGW-43A rfidgw_spi1[6824]: 15:12:19.180: --------------------------------------------------------------
May 24 15:12:19 DMGW-43A rfidgw_spi1[6824]: 15:12:19.180: [[]]===Use Socket Client to get RFID Tag====]]
May 24 15:12:19 DMGW-43A rfidgw_spi1[6824]: 15:12:19.181: [[]]===Use Socket Client to get RFID Tag====]]
//------------end------------

上述結果中的Main PID則是Service執行PID,我們用參數的方式直接取得Main PID屬性的值

systemctl show --property MainPID --value rfidgw

執行後會返回該屬性的值

6824

以上就是取得該service的PID,利用ps指定返查

ps -f --pid 6824

會得到結果如下

UID        PID  PPID  C STIME TTY          TIME CMD
root      6824     1 18 15:12 ?        00:00:09 /home gw rfidgw rfidgw_spi1

The post 20210525-systemctl 取得 service pid appeared first on 可丁丹尼 @ 一路往前走2.0.

Linux /etc/skel 目錄

$
0
0

目的

/etc/skel/目錄是用來存放新使用者配置檔案的目錄,當新增新使用者(useradd)的時候,這個目錄下的所有檔案會自動被複制到新新增的使用者的家目錄下。執行下面指令查看/etc/skel

ls -la /etc/skel/

ls所包含的命令:

  • -a 列出隱藏檔

  • -l 列表方式顯示檔案 輸出結果:

drwxr-xr-x  2 root root 4096 Aug 24 09:03 .
drwxr-xr-x 96 root root 4096 Jul 25 10:34 ..
-rw-r--r--  1 root root  220 Apr 18  2019 .bash_logout
-rw-r--r--  1 root root 3523 Jan 11  2021 .bashrc
-rw-r--r--  1 root root 1010 Aug 24 09:03 .profile

指定 skel

新增使用者時可以透過命令來改變預設的/etc/skel目錄作為使用者配置檔案的目錄:

sudo useradd -d /home/jasonchen -m -k /etc/my_skel jasonchen

變更預設 skel

不想在每次新建使用者時,都重新指定新的使用者配置檔案的目錄,可以通過修改/etc/default/useradd配置檔案並查詢SKEL變數的定義:

# Default values for useradd(8)
#
# The SHELL variable specifies the default login shell on your
# system.
# Similar to DHSELL in adduser. However, we use "sh" here because
# useradd is a low level utility and should be as general
# as possible
SHELL=/bin/bash
#
# The default group for users
# 100=users on Debian systems
# Same as USERS_GID in adduser
# This argument is used when the -n flag is specified.
# The default behavior (when -n and -g are not specified) is to create a
# primary user group with the same name as the user being added to the
# system.
# GROUP=100
#
# The default home directory. Same as DHOME for adduser
# HOME=/home
#
# The number of days after a password expires until the account
# is permanently disabled
# INACTIVE=-1
#
# The default expire date
# EXPIRE=
#
# The SKEL variable specifies the directory containing "skeletal" user
# files; in other words, files such as a sample .profile that will be
# copied to the new user's home directory when it is created.
SKEL=/etc/skel
#
# Defines whether the mail spool should be created while
# creating the account
# CREATE_MAIL_SPOOL=yes

如果此變數的定義已被註釋掉,可以取消註釋,然後修改其值:

SKEL=/etc/my_skel

The post Linux /etc/skel 目錄 appeared first on 可丁丹尼 @ 一路往前走2.0.

Linux 登入畫面 轉向 login screen rotation

$
0
0

Linux 登入畫面 轉向 login screen rotation

顯示畫面通常在出廠時都會設定好預設的方向解析度,在某些設備像平板它設定的解析度方向可能是直式的,非一般我們習慣的橫式,這時候就要透過命令在登入畫面出現後先自動轉向,以下例子使用lightdm顯示管理器為例。

設定檔建立/開啟

lightdm設定檔依版本不同會各別放置於:

  • /usr/share/lightdm/lightdm.conf.d/*.conf
  • /etc/lightdm/lightdm.conf.d/*.conf
  • /etc/lightdm/lightdm.conf

上面前兩項只要在目錄中建立新設定檔後就會自動取用設定,最後一個要將參數新增至lightdm.conf檔案,依照你設定檔的類型開啟或建立檔案:

nano /usr/share/lightdm/lightdm.conf.d/80-display-setup.conf

nano /etc/lightdm/lightdm.conf.d/80-display-setup.conf

nano /etc/lightdm/lightdm.conf

新增設定

將設定新增區段[SeatDefaults]並加入display-setup-script,在lightdm顯示登入畫面時執行命令xrandr -o right,依照你需要轉向將right代換成rightleftnormal

[SeatDefaults]
display-setup-script=xrandr -o right

設定好之後存檔並重新開機設定才會生效

The post Linux 登入畫面 轉向 login screen rotation appeared first on 可丁丹尼 @ 一路往前走2.0.

Unifi UDM Pro 變更 WAN IP (Static IP)

$
0
0

2022-03-08-Unifi UDM Pro 變更 WAN IP (Static IP)

UDM Pro 功能非常的強大,設定的邏輯上比較嚴謹,一但你設定WAN為固定IP,要變更IP就不像一般路由器一樣直接更改WAN IP就能完成。

147e857524c26bef9a2d0c5cbf87b899.png

上圖中要將192.168.1.161改成192.168.1.25時發生錯誤

變更流程

UDM Pro可以一次增加許多WAN的IP,所以畫面看到的設定畫面其實是第一組設定,之後可以再增加其他的WAN端IP,所以WAN端設定固定IP後, 您必需增加一組WAN的臨時IP後並將網路至WAN的IP改為增加的第二組,才能將第一組WAN IP變更

開始操作

此次操作要將原本192.168.1.35WAN IP改為192.168.1.161 WAN IP

增加臨時IP

輸入臨時IP192.168.1.144網路遮罩採用255.255.255.024,輸入 192.168.1.144/24並按下Add

a9dbf067ccd472bd1aa588f4653d99ef.png

之後就能看到增加的WAN IP

90681fa8a52c2af249a05eb15f5ad3f1.png

接下來就需要去Network上變更內定對外的WAN IP

變更 Network 至WAN

cb5eaf8e6818b3a5157c1da47cfde5d1.png

上圖中會看到Internet Source IP上可以做選擇,接下來將192.168.1.35指定成我們之前設定的臨時WAN IP192.168.1.144

28ca941567a429d309b4a37a60fc0ff1.png

記得按下Apply Changes,再來就回到原本的Internet選擇變更第一組WAN IP

變更第一組WAN IP

ac6696f662738e617a32379cb79e52fa.png

如上圖中,將原本的192.168.1.35改成192.168.1.161按下Apply Changes就完成設定,不會出現錯誤訊息,

再次變更 Network 至WAN IP

前面設定已經將Network 至WAN IP設定為臨時WAN IP 192.168.1.144,記得將它變更為新設定WAN IP 192.168.1.161,如此後面才能將臨時WAN IP192.168.1.144刪除,操作過程不再說明,直接看下圖結果:

a4ce23c3624c9845e5fce8169830d1fe.png

刪除臨時IP

當你設定好後再將原本增加的臨時WAN IP 192.168.1.144刪除,

2f18b21ca7a0271bdb8aa1a3950cd660.png

一樣記得按下Apply Changes進行套用,如此就完成變更WAN IP

866bed8a7d2dfa8a3ff13ce88f60e0ab.png

結論

UDM Pro Internet設定邏輯較不同,一旦你設定WAN 為固定IP時,整個NetworkInternet關系是以IP進行關連,所以需要進行手動的指定, 沒辦法像DHCPPPPOE的關系會自動去對應,這次的經驗對我初次操作的新手真的是一項新的邏輯。

參考連結

The post Unifi UDM Pro 變更 WAN IP (Static IP) appeared first on 可丁丹尼 @ 一路往前走2.0.

Pi 安裝freeSWITCH (0)-前言

$
0
0

freeSWITCH 整合提供了PBXIVRSoftPhone功能,讓以往VoIP通話是不是只有一對一話後,還提供電話總機的功能,以前類比電話機機總是要購買整合好的設備,現今利用網路加上freeSWITCH就能建立網路版的電話總機IPPBX3c3a5832d70537bb58bb3b55a3b7558b.png 除此之外還能安裝像MicroSIP這類的軟體版的網路電話進行操作,評估IPPBX時能先節省一比費用,真正導入時再視需要購買硬體版的網路電話。

此編文章主要是記錄安裝的方法,以往都是要將整個原始碼下載、編譯、安裝的過程,現今官方已經有提供freeSWITCH主程式的Debian套件安裝,大大降原始碼編譯錯誤的機率,未來會將一些設定的方式再分享。

參考資訊

名稱 說明 網址
MicroSIP 網路電話 https://www.microsip.org/
FreeSWITCH 軟體型電話交換機 freeswitch.org/
Zoiper 網路電話、支援iOS、Android https://www.zoiper.com/

The post Pi 安裝freeSWITCH (0)-前言 appeared first on 可丁丹尼 @ 一路往前走2.0.

Pi 安裝freeSWITCH (1)-編譯 Sofia-sip and SpanDSP

$
0
0

freeSWITCH新版本已經將 Sofia-sipSpanDSP 獨立,安裝freeSWITCH之前需要編譯 Sofia-sipSpanDSP 函數庫才能正確執行,以下操作請在root權限或是sudo

安裝套件

sudo apt install -y git subversion build-essential autoconf automake libtool libncurses5 libncurses5-dev make libjpeg-dev libtool libtool-bin libsqlite3-dev libpcre3-dev libspeexdsp-dev libldns-dev libedit-dev yasm libopus-dev cmake autoconf libtool liblua5.2-dev libcurl4-openssl-dev libexpat1-dev libgnutls28-dev libtiff5-dev libx11-dev unixodbc-dev libssl-dev python-dev zlib1g-dev libasound2-dev libogg-dev libvorbis-dev libperl-dev libgdbm-dev libdb-dev uuid-dev libsndfile1-dev
libmariadb-dev python3 pip

下載 Sofia-sip 原始碼

使用 git將原始碼clone

git clone https://github.com/freeswitch/sofia-sip

Build Sofia-sip

進入剛剛clone下來的原始碼目錄並建立configure設定檔程式

cd sofia-sip
./bootstrap.sh
+ AUTOMAKE=automake ACLOCAL=aclocal
+ export AUTOMAKE ACLOCAL
+ autoreconf -i
libtoolize: putting auxiliary files in '.'.
libtoolize: copying file './ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: copying file 'm4/libtool.m4'
libtoolize: copying file 'm4/ltoptions.m4'
libtoolize: copying file 'm4/ltsugar.m4'
libtoolize: copying file 'm4/ltversion.m4'
libtoolize: copying file 'm4/lt~obsolete.m4'
configure.ac:41: installing './compile'
configure.ac:35: installing './config.guess'
configure.ac:35: installing './config.sub'
configure.ac:37: installing './install-sh'
configure.ac:37: installing './missing'
libsofia-sip-ua-glib/su-glib/Makefile.am: installing './depcomp'
parallel-tests: installing './test-driver'
+ + find . ( -namexargs run* chmod -o +x
-name *.sh ) -a -type f
+ chmod +x scripts/coverage scripts/fix-include-sofia-sip scripts/hide_emails.sh scripts/lcov-report scripts/rpmbuild-snaphot scripts/uncovered

執行設定檔配置檢查,無問題進行make編譯,編譯完成後進行make install將函數庫安裝至系統

./configure
make
make install

Build SpanDSP

方法如前面章節一樣的方式將原始碼編譯並安裝至系統:

git clone https://github.com/freeswitch/spandsp
./bootstrap.sh
./configure
make
make install

接下來就可以進行套件方法安裝freeSWITCH主程式

The post Pi 安裝freeSWITCH (1)-編譯 Sofia-sip and SpanDSP appeared first on 可丁丹尼 @ 一路往前走2.0.

Pi 安裝freeSWITCH (2)-建立SignalWire Personal Access T

$
0
0

安機裝套件時,freeSWITCH要求必需要有Personal Access Token才能進行套件的下載安裝。

建立SignalWire 帳號

登入或建立你的signalwire帳號 1292896df887ca64dcb1092278c22bc4.png

建立 Personal Access Token

註冊完成後,點選左方選單,並按下Personal Access Tokens建立PAT Token ![3b9bd575ac166ccd7e850a9e1dd21ae1.png](.1292896df887ca64dcb1092278c22bc4.png /3b9bd575ac166ccd7e850a9e1dd21ae1.png)

輸入名稱

![a71b0bf76c58e33530aedce1b88cb0b9.png](1292896df887ca64dcb1092278c22bc4.png /a71b0bf76c58e33530aedce1b88cb0b9.png)

按下Generate Token產生Token, ![3aaf77958659f349bd3e1b2d0bb916c2.png](1292896df887ca64dcb1092278c22bc4.png /3aaf77958659f349bd3e1b2d0bb916c2.png)

請將Token記住,平台上無法重新查詢到產生的Token,忘記時就要RevokeToken刪除再產生新的一組!

The post Pi 安裝freeSWITCH (2)-建立SignalWire Personal Access T appeared first on 可丁丹尼 @ 一路往前走2.0.


Pi 安裝freeSWITCH (3)-安裝主程式

$
0
0

登入 Pi Console

進行ssh或是開啟Terminal視窗,接下來會在終端執行操作

匯出 Token

執行export TOKEN=pat_XXXXXXpat_XXXXXX為您的Token,此變數會存留在當下的Console,如果關閉連線視窗重新連線後要重新執行

套件安裝

apt-get update && apt-get install -y gnupg2 wget lsb-release

加入套件來源

加入第三方套件來源之前要先安裝它通行的Public Key,因官方教學提供給Pi的來源有問題,以下改成Debian 教學中的來源:

wget --http-user=signalwire --http-password=$TOKEN -O - https://freeswitch.signalwire.com/repo/deb/debian-release/signalwire-freeswitch-repo.gpg | apt-key add -

加入Token

echo "machine freeswitch.signalwire.com login signalwire password $TOKEN" > /etc/apt/auth.conf

加入套件來源


echo "deb https://freeswitch.signalwire.com/repo/deb/rpi/debian-release/ `lsb_release -sc` main" > /etc/apt/sources.list.d/freeswitch.list echo "deb-src https://freeswitch.signalwire.com/repo/deb/rpi/debian-release/ `lsb_release -sc` main" >> /etc/apt/sources.list.d/freeswitch.list

安裝套件

apt-get update && apt-get install -y freeswitch-meta-all

參考資料

Installation Raspberry Pi

The post Pi 安裝freeSWITCH (3)-安裝主程式 appeared first on 可丁丹尼 @ 一路往前走2.0.

移除檔案的副檔名

$
0
0
using System;
using System.IO;
public class Example
{
public static void Main()
{
string filepath= @"C:\1234\5678\abc.csv";
// 直接將副檔名給null就會清空
string onlyFileNamePath = Path.ChangeExtension(filepath, null);
Console.WriteLine(filePathWithoutExt);
}
}

The post 移除檔案的副檔名 appeared first on 可丁丹尼 @ 一路往前走2.0.

調整 pve root Resize pve root

$
0
0

調整 pve root Resize pve root

安裝pve如果您的系統碟容量比較小,按照比例會取得較小的pve-root空間,像下面:

root@pve:~# lsblk
NAME               MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                  8:0    0   113G  0 disk
├─sda1               8:1    0  1007K  0 part
├─sda2               8:2    0   512M  0 part
└─sda3               8:3    0 112.5G  0 part
├─pve-swap       253:0    0     8G  0 lvm  [SWAP]
├─pve-root       253:1    0    28G  0 lvm  /
├─pve-data_tmeta 253:2    0     1G  0 lvm
│ └─pve-data     253:4    0  60.5G  0 lvm
└─pve-data_tdata 253:3    0  60.5G  0 lvm
└─pve-data     253:4    0  60.5G  0 lvm
sdb                  8:16   0   2.7T  0 disk
├─sdb1               8:17   0   2.7T  0 part
└─sdb9               8:25   0     8M  0 part
sdc                  8:32   0   2.7T  0 disk
├─sdc1               8:33   0   2.7T  0 part
└─sdc9               8:41   0     8M  0 part

pve-root 被分配到28G,很快的它就會滿了,接下來就需要調整空間,下面會將pve-data 刪除以取得最大的空間。

刪除 /dev/pve/data

lvremove /dev/pve/data

調整 pve-root 空間

lvresize -l +100%FREE /dev/pve/root

檢查檔案系統

resize2fs /dev/mapper/pve-root

完成

以下操作能看到pve-root擴充到104.5G

root@pve:/var/cache# lsblk
NAME         MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda            8:0    0   113G  0 disk
├─sda1         8:1    0  1007K  0 part
├─sda2         8:2    0   512M  0 part
└─sda3         8:3    0 112.5G  0 part
├─pve-swap 253:0    0     8G  0 lvm  [SWAP]
└─pve-root 253:1    0 104.5G  0 lvm  /
sdb            8:16   0   2.7T  0 disk
├─sdb1         8:17   0   2.7T  0 part
└─sdb9         8:25   0     8M  0 part
sdc            8:32   0   2.7T  0 disk
├─sdc1         8:33   0   2.7T  0 part
└─sdc9         8:41   0     8M  0 part

The post 調整 pve root Resize pve root appeared first on 可丁丹尼 @ 一路往前走2.0.

x11vnc 整合至 systemd 開機自動執行

$
0
0

設定密碼

x11vnc 遠端控制畫面是傳輸XWindows整個畫面,與其他的vnc server不同, 在使用時建議一定要先設定密碼做好最低限度的保護。

sudo x11vnc -storepasswd [你的密碼] /etc/x11vnc.passwd

建立 Systemd Service檔案

使用編輯器建立x11vnc.service,如:nano x11vnc.service

[Unit]
Description=VNC Server
After=multi-user.target network.target

[Service]
Restart=always
# Replace this with x0vncserver from TigerVNC in Ubuntu 18.04.
# Set password by running `sudo x11vnc -storepasswd [PASSWORD] /etc/x11vnc.passwd`
ExecStart=/usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /etc/x11vnc.passwd -rfbport 5900 -shared

[Install]
WantedBy=multi-user.target

存檔後記住x11vnc.service的路徑,等下會複制到對應的目錄。

安裝 Servce 檔案至 Systemd

sudo cp [path to]/x11vnc.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable x11vnc.service

啟動x11vnc

sudo systemctl start x11vnc

啟動後查看一下執行是否正常

sudo systemctl status x11vnc

danny@EDY-G41MT-D3:~$ sudo systemctl status x11vnc
● x11vnc.service - X11VNC Server
Loaded: loaded (/lib/systemd/system/x11vnc.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2022-11-03 09:53:54 CST; 31min ago
Main PID: 913 (x11vnc)
Tasks: 2 (limit: 9337)
Memory: 16.7M
CPU: 30.635s
CGroup: /system.slice/x11vnc.service
├─913 /usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /etc/x11vnc.passwd -rfbport 5900 -shared
└─916 /usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /etc/x11vnc.passwd -rfbport 5900 -shared

Nov 03 10:07:07 EDY-G41MT-D3 x11vnc[916]: 03/11/2022 10:07:07 Statistics             events    Transmit/ RawEquiv ( saved)
Nov 03 10:07:07 EDY-G41MT-D3 x11vnc[916]: 03/11/2022 10:07:07  FramebufferUpdate   :    182 |         0/        0 (  0.0%)
Nov 03 10:07:07 EDY-G41MT-D3 x11vnc[916]: 03/11/2022 10:07:07  ZRLE                :    508 |    151060/  9056768 ( 98.3%)
Nov 03 10:07:07 EDY-G41MT-D3 x11vnc[916]: 03/11/2022 10:07:07  TOTALS              :    690 |    151060/  9056768 ( 98.3%)
Nov 03 10:07:07 EDY-G41MT-D3 x11vnc[916]: 03/11/2022 10:07:07 Statistics             events    Received/ RawEquiv ( saved)
Nov 03 10:07:07 EDY-G41MT-D3 x11vnc[916]: 03/11/2022 10:07:07  PointerEvent        :    259 |      1554/     1554 (  0.0%)
Nov 03 10:07:07 EDY-G41MT-D3 x11vnc[916]: 03/11/2022 10:07:07  FramebufferUpdate   :    509 |      5090/     5090 (  0.0%)
Nov 03 10:07:07 EDY-G41MT-D3 x11vnc[916]: 03/11/2022 10:07:07  SetEncodings        :      1 |        24/       24 (  0.0%)
Nov 03 10:07:07 EDY-G41MT-D3 x11vnc[916]: 03/11/2022 10:07:07  SetPixelFormat      :      1 |        20/       20 (  0.0%)
Nov 03 10:07:07 EDY-G41MT-D3 x11vnc[916]: 03/11/2022 10:07:07  TOTALS              :    770 |      6688/     6688 (  0.0%)

The post x11vnc 整合至 systemd 開機自動執行 appeared first on 可丁丹尼 @ 一路往前走2.0.

2022-12-22 man 指定語言 語系

$
0
0

man 透過 --locale=語系 指定要看的語系說明,但不清楚語系名稱時進入usr/share/man查詢:

ls -la /usr/share/man

danny@EDY-G41MT-D3:/usr/share/man$ ls -la
total 484
drwxr-xr-x  36 root root   4096 Sep 23 08:53 .
drwxr-xr-x 347 root root  12288 Dec  3 17:01 ..
drwxr-xr-x   5 root root   4096 Feb  7  2020 cs
drwxr-xr-x   5 root root   4096 Feb  7  2020 da
drwxr-xr-x   6 root root   4096 Feb  7  2020 de
drwxr-xr-x   6 root root   4096 Sep 23 08:53 es
drwxr-xr-x   3 root root   4096 May 11  2022 fi
drwxr-xr-x   6 root root   4096 May 11  2022 fr
drwxr-xr-x   3 root root   4096 May 11  2022 hr
drwxr-xr-x   5 root root   4096 May 11  2022 hu
drwxr-xr-x   5 root root   4096 May 11  2022 id
drwxr-xr-x   5 root root   4096 Feb  7  2020 it
drwxr-xr-x   6 root root   4096 Sep 23 08:53 ja
drwxr-xr-x   5 root root   4096 Feb  7  2020 ko
drwxr-xr-x   2 root root 102400 Dec  3 17:01 man1
drwxr-xr-x   2 root root  24576 May 17  2022 man2
drwxr-xr-x   2 root root 122880 Nov  4 09:37 man3
drwxr-xr-x   2 root root   4096 Dec  3 17:01 man4
drwxr-xr-x   2 root root  28672 Dec  3 17:01 man5
drwxr-xr-x   2 root root   4096 Nov  2 11:30 man6
drwxr-xr-x   2 root root  16384 Nov  2 11:30 man7
drwxr-xr-x   2 root root  53248 Dec  3 17:01 man8
drwxr-xr-x   6 root root   4096 May 11  2022 nl
drwxr-xr-x   5 root root   4096 Feb  7  2020 pl
drwxr-xr-x   6 root root   4096 May 11  2022 pt
drwxr-xr-x   5 root root   4096 May 11  2022 pt_BR
drwxr-xr-x   5 root root   4096 May 11  2022 ro
drwxr-xr-x   6 root root   4096 Sep 23 08:53 ru
drwxr-xr-x   4 root root   4096 May 11  2022 sl
drwxr-xr-x   5 root root   4096 May 11  2022 sr
drwxr-xr-x   6 root root   4096 Jun 28 10:52 sv
drwxr-xr-x   5 root root   4096 Feb  7  2020 tr
drwxr-xr-x   5 root root   4096 May 11  2022 uk
drwxr-xr-x   4 root root   4096 Sep 23 08:53 vi
drwxr-xr-x  10 root root   4096 Dec 22 11:29 zh_CN
drwxr-xr-x  10 root root   4096 Dec 22 11:29 zh_TW
danny@EDY-G41MT-D3:/usr/share/man$

看到語系名稱後指定語系就完成,這裡指定zh_TW查詢指令pwd

man --locale=zh_TW pwd

7a585423349979df8dfacbc7ef1bea63.png

The post 2022-12-22 man 指定語言 語系 appeared first on 可丁丹尼 @ 一路往前走2.0.

2022-12-27 tar 去掉路徑結構

$
0
0

產生測試資料

cd /tmp
mkdir 11/22/33 -p
touch 11/f1
touch 11/22/f2
touch 11/22/33/f3

目錄結構

tree tmp
tmp
└── 11
├── 22
│   ├── 33
│   │   └── f3
│   └── f2
└── f1

壓縮

一般來說我們會使用zcf指定tar完成後再gzip,我們看看2個指令的差別

指令1

tar -zcf b1.tar.gz tmp/

指令2

cd tmp
tar -zcf ../b2.tar.gz .

壓縮完成後看一下目錄結構

tar tzf b1.tar.gz
tmp/
tmp/11/
tmp/11/f1
tmp/11/22/
tmp/11/22/f2
tmp/11/22/33/
tmp/11/22/33/f3

tar tzf b2.tar.gz
./
./11/
./11/f1
./11/22/
./11/22/f2
./11/22/33/
./11/22/33/f3

上面看到雖然壓縮的內容一樣,但會因指定路徑的關系造成目錄結構的不同,那如果想要消除最上層的目錄結構像b2.tar.gz的內容是不是就要切到當前目錄進行壓縮才行?這答案當然是不需要的,參數上面只要再加上-C(--directory)指定目錄路徑就能像你自行切到當前目錄一樣的效果

-C (–directory)

如果要保持b2.tar.gz的結構,在參數上面將原本要cd tmp/的指定換成-C tmp/目錄加上,

tar -zcf b3.tar.gz -C tmp/ .

壓縮好後看一下結構:

tar tzf b3.tar.gz
./
./11/
./11/f1
./11/22/
./11/22/f2
./11/22/33/
./11/22/33/f3

參考資料

The post 2022-12-27 tar 去掉路徑結構 appeared first on 可丁丹尼 @ 一路往前走2.0.

Enable Serial Terminal 開啟Serial 終端

$
0
0

Raspberry Pi SoC 後期有內建2組UART,所以會做一個相容,

tty UART Type map
Serial0 mini UART ttyS0
Serial1 PL011 ttyAMA0

Kernel

Open /boot/cmdline.txt

console=serial0,115200 root=PARTUUID=d82c2881-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

EDIT console=serial0,115200

console=serial0,115200

這個是開機過程Kernel會將輸出導出至UART,如果沒設定在開機過程就只能在螢幕上看到

Terminal

終端輸出還是需要靠程式本身處理,主要的systemd設定在

sudo nano lib/systemd/system/serial-getty@.service

使用@機制,啟動時要在@後面加上設備名稱如:ttyS0

sudo systemctl enable serial-getty@[ttyS0|ttyAMA0].service

假設是ttyS0

sudo systemctl enable serial-getty@ttyS0.service

參考資料

Enabling a Serial Port Console: getty systemd

啟用Raspberry Pi 3B+ 序列埠功能

The post Enable Serial Terminal 開啟Serial 終端 appeared first on 可丁丹尼 @ 一路往前走2.0.


NPM Monorepo 設定

$
0
0

NPM Monorepo 設定

1. 目錄結構:

//-----------start-----------
my-monorepo/
|-- packages/
| |-- my-first-package/
| | |-- index.js
| |-- my-second-package/
| | |-- index.js
|-- package.json

//------------end------------

2. 最上層套件 package.json 宣告:

//-----------start-----------
{
"name": "@dystw/dystw",
"version": "1.0.0",
"private": true,
"workspaces": [
"packages/*"
],
"exports": {
"./my-first-package": "./packages/my-first-package/index.js",
"./my-second-package": "./packages/my-second-package/index.js"
}
}
//------------end------------

重要提示:在最上層的 package.json 中使用 exports 可以确保子模块被正确地導出,使得在外部可以像這樣引用:@dystw/my-first-package 和 @dystw/my-second-package。

3. 子套件 package.json 宣告:

my-first-package/package.json:

//-----------start-----------
{
"name": "@dystw/my-first-package",
"version": "1.0.0",
"main": "index.js"
}
//------------end------------

my-second-package/package.json:

//-----------start-----------
{
"name": "@dystw/my-second-package",
"version": "1.0.0",
"main": "index.js"
}
//------------end------------

4. 將模組推送至 Git:

//-----------start-----------
git init
git add .
git commit -m "Initial commit"
git remote add origin http://abc.com/my-monorepo.git
git push -u origin master
//------------end------------

5. 專案引用建議:

當你想在另一個專案中引用這些模組時,在該專案的 package.json 中,你可以如下所示添加依赖:

//-----------start-----------
{
"dependencies": {
"@dystw/my-first-package": "git+http://abc.com/my-monorepo.git",
"@dystw/my-second-package": "git+http://abc.com/my-monorepo.git"
}
}
//------------end------------

或直接引入最上層的套件名稱

//-----------start-----------
{
"dependencies": {
"@dystw/dystw": "git+http://abc.com/my-monorepo.git",
}
}
//------------end------------

之後,你可以執行 npm install 或 yarn install(取決於你使用哪個包管理器)來安裝這些模組。

The post NPM Monorepo 設定 appeared first on 可丁丹尼 @ 一路往前走2.0.

flutter 指定 android sdk 路徑

$
0
0

指令:

flutter --android-sdk "[路徑]

範例:

C:\Users\danny>flutter config --android-sdk "D:\3106_AndroidSDK"
Setting "android-sdk" value to "D:\3106_AndroidSDK".
You may need to restart any open editors for them to read new settings.

記得指定完成後執行flutter doctor --android-licenses 去同意整個授權才能使用!

The post flutter 指定 android sdk 路徑 appeared first on 可丁丹尼 @ 一路往前走2.0.

nextcloud 使用者檔案 重建索引 (docker)

$
0
0

建立nextcloud如果覺的檔案在網頁上顯示的內容與實際檔案有出入時可以透過occ來重新建立檔案的索引。 假設nextcloud建立在/var/www/html之中:

cd /var/www/html
sudo -u www-data php occ files:scan [使用者名稱]

重建完成後會看到如下:

+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 13      | 71    | 00:00:04     |
+---------+-------+--------------+

剛好您建立的是在docker下的nextcloud時,使用docker命令到容器的console中執行:

docker exec -it [容器ID] bash

進到容器中一樣切到nextcloud安裝目錄並執行:

cd /var/www/html
sudo -u www-data php occ files:scan [使用者名稱]

如果想要重建所有的使用者:

cd /var/www/html
sudo -u www-data php occ files:scan --all

The post nextcloud 使用者檔案 重建索引 (docker) appeared first on 可丁丹尼 @ 一路往前走2.0.

ssh authorized_key 失效

$
0
0

使用 VSCode 遠端開發時發現把 public key 加入 authorized_key 還是失效,之後才知道可以加上參數進行檢查,於事先在”命令提示字元執行ssh`:

ssh -i [private key path name] -v gw@192.168.19.38

結果發現真的有問題:

:
:
debug1: Next authentication method: publickey
debug1: Offering public key: id_rsa-dmgw RSA SHA256:eXU7QTcaydeRJeEwHa9bOA9swT explicit
debug1: Server accepts key: id_rsa-dmgw RSA SHA256:eXU7QTcaydeRJeEwHa9bOA9swT explicit
Load key "id_rsa-dmgw": invalid format

最後不知道怎麼解決,直接拷貝別台機器上同樣的 private key至 windows後再進行一次檢查,檢查命令:

ssh-keygen -y -f [private key path name]

結果:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCfeAvs gw@dmgw

如果錯誤時會出現:

Load key "id_rsa-dmgw": invalid format

The post ssh authorized_key 失效 appeared first on 可丁丹尼 @ 一路往前走2.0.

Viewing all 79 articles
Browse latest View live