前言
在linux的环境下,许多工具在初次使用或者进阶使用的时候都会用到man手册。 手册纯文本话的东西。自己开发的后台小程序,设置一个简单的手册。在linux的环境中直接查阅也会更加直观。在大平台的项目中,这种小程序的手册不需要其他用户查阅。秉承权限最小化。我们可以通过执行简单脚本,将其导入到临时的手册环境路径中。 当前用户退出终端后就不再使用。
环境
操作系统:window WSL kali 或者 linux 涉及基本命令:gzip 、sed、echo、mkdir、man
针对kali安装man
通过apt-get安装,若网络环境需要走代理.
#[根据网络可选]针对kali机器网络内部走代理才需要设置,否则不需要
# 需要代理的化境很难搞,如果口令有特殊字符还涉及URI编码#
[临时]export http_proxy="http:用户名:口令@代理IP:端口"
[仅针对apt]sudo gedit /etc/apt/apt.conf
替换yourproxyaddress 和proxyport
Acquire::http::Proxy "http://proxyip:port/";
[针对kali机器] /etc/apt/apt.conf.d/50kali
[针对用户]gedit ~/.bashrc 新增
export http_proxy="http:用户名:口令@代理IP:端口"
#更新
apt-get update
#查看帮助
apt-get -h
apt-cache search man
#安装手册的
apt-get install man
安装手册
apt-get install manpages-de manpages-de-dev manpages-dev glibc-doc manpages-posix-dev manpages-posix
参考资料
The man macro package is provided to enable users to create their own manual pages from online manual pages that have been processed with either the nroff command or troff command. The man macro package is used with either the nroff command or the troff command
样例说明
- 撰写一份需要设置的手册,当前样例手册为asn1c_skeletons.man
- 根据需求调整临时脚本mymanpro.sh,当前样例设置章节4,名字为
- sectionNUM=4
- definedMANname="asn1c_skeletons" NOTE:生成的的放在当前目录的man4对应设置的章四下,若目录和数字不一样,查阅失败
- 使用执行导入,即可使用
环境设置脚本mymanpro.sh
脚本简要说明:根据要求压缩手册到指定目录,将目录环境,通过和原有环境man手册的"MANPATH"进行比对防止重复导入
#!/bin/sh
#Unix Shell Script
#filenamed:mymanpro.sh
#run: . ./mymanpro.sh
sectionNUM=4
definedMANname="asn1c_skeletons"
PWDDIR=`pwd`
ADDMANDIR="${PWDDIR}/man${sectionNUM}"
function ContainedInArr()
{
arr=("$@")
arrlen=$#
echo $arr
i=1
while (( $i < $arrlen ))
do
printf "%3d:%-20s\n" $i ${arr[$i]}
if [ ${arr[0]} = ${arr[$i]} ]
then
echo "In"
return 1
fi
let i++
done
echo "Not In"
return 0
}
if [ ! -d ${ADDMANDIR} ] ;then
mkdir -p ${ADDMANDIR}
fi
MYMAN="${PWDDIR}/${definedMANname}.man"
if [ -e ${MYMAN} ] ;then
gzip -c ${MYMAN} > ${ADDMANDIR}/${definedMANname}.${sectionNUM}.gz
fi
# :->space
MANPATHTMP=` echo "${MANPATH}" | sed "s/:/\\x20/g" `
ContainedInArr ${PWDDIR} ${MANPATHTMP[@]}
if [ $? -eq 0 ] ;then
export MANPATH=${MANPATH}:${PWDDIR}
fi
操作
- 准备操作前目录结构
└─$ pwd
/mnt/d/LinuxRun
└─$ tree
.
├── asn1c_skeletons.man
└── mymanpro.sh
0 directories, 2 files
- 执行操作
└─$ source mymanpro.sh
/mnt/d/LinuxRun
1:/mnt/d/LinuxRun
In
- 执行后目录结构
└─$ tree
.
├── asn1c_skeletons.man
├── man4
│ └── asn1c_skeletons.4.gz
└── mymanpro.sh
1 directory, 3 files
- 执行查阅章四
man 4 asn1c_skeletons
样例man手册
.\"Datrilla :
.TH asn1cDevelopment 1 Usemannuals skeletons
.SH GENERATION CMD
\fP
.PP
.TP
precompile:asn1c -gen-PER TESTModule.asn
.TP
compile:cc -DPDU=Circle -I. -o CircleDecorder.exe *.c
.SH a variety of METHODS
\fP
.PP
.TP
\fBber_\fP Byte-oriented decoder(could read DER and CER)
.TP
\fBder_\fP
.TP
\fBper_\fP BIT-oriented
.TP
\fBxer_\fP UTF-8 XML
.SH BASIC TYPE C LANGUAGE FILE *\.c
\fP
.TP
\fBBOOLEAN\fP
.TP
\fBINTEGER\fP
.TP
\fBENUMERATED\fP
.TP
\fBREAL\fP
.TP
\fBBIT_STRING\fP
.TP
\fBOCTET_STRING\fP
.TP
\fBNULL\fP
.TP
\fBconstr_SEQUENCE\fP SEQUENCE
.TP
\fBconstr_SEQUENCE_OF\fP SEQUENCE OF
.TP
\fBconstr_SET\fP SET
.TP
\fBconstr_SET_OF\fP SET OF
.TP
\fBconstr_CHOICE\fP CHOICE
.TP
SelectionType | TaggedType @ref x.680 for more description
.TP
\fBOBJECT_IDENTIFIER\fP
.TP
\fBRELATIVE-OID\fP
.TP
EmbeddedPDVType ::= EMBEDDED PDV|ExternalType ::= EXTERNAL @ref x.680(200207) for more description
.TP
\fBRestrictedCharacterStringType x.680(200207) Annex H or x680 11.25.4\fP
\fP
.RS
\fBBMPString\fP
.RE
\fP
.RS
\fBGeneralString\fP
.RE
\fP
.RS
\fBGraphicString\fP
.RE
\fP
.RS
\fBIA5String\fP
.RE
\fP
.RS
\fBISO646String\fP
.TP
\fBNumericString\fP
.RE
\fP
.RS
\fBPrintableString\fP
.TP
\fBTeletexString\fP
.RE
\fP
.RS
\fBT61String\fP
.RE
\fP
.RS
\fBUniversalString\fP
.TP
\fBUTF8String\fP
.RE
\fP
.RS
\fBVideotexString\fP
.RE
\fP
.RS
\fBVisibleString\fP
.RE
.TP
UnrestrictedCharacterStringType ::= CHARACTER STRING @ref x.680(200207) 40 for more description
.TP
\fBGeneralizedTime\fP
.TP
\fBUTCTime\fP
.TP
\fBObjectDescriptor\fP
.TP
\fBconstraints\fP
标签:fP,RS,自制,apt,手册,TP,man
From: https://blog.51cto.com/datrilla/6123612