Closed realkcn closed 3 years ago
print-board.sh
Output Path, Name, BM from /bbs/0Announce/groups
directory
#!/usr/bin/env bash
set -e
function outputName () {
local Path=$1
local Name=$2
local BM=$3
if [[ -n "$Name" ]]; then
BM=${BM//(BM: /}
BM=${BM//)/}
echo -e "{\"path\": \"$Path\", \"name\": \"$Name\", \"bm\": \"$BM\"},"
fi
}
function printDotName () {
dotNameFile=$1
local Path=$1
local Name=$2
local BM=$3
while IFS= read -r line
do
if [[ $line =~ ^Name=([^[:space:]]+)\ *(.*) ]]; then
Name="${BASH_REMATCH[1]}"
BM="${BASH_REMATCH[2]}"
elif [[ $line =~ ^Path=~/(.+)$ ]]; then
Path="${BASH_REMATCH[1]}"
elif [[ $line =~ ^\# ]]; then
outputName "$Path" "$Name" "$BM"
Path=
Name=
BM=
fi
done < $dotNameFile
outputName "$Path" "$Name" "$BM"
}
printDotName $1
Sample output:
$ for d in /bbs/0Announce/groups/*; do ./print-board.sh $d/.Names; done
{"path": "sysop", "name": "斧头帮大堂", "bm": "SYSOP"},
{"path": "Announce", "name": "斧头帮通告", "bm": "SuperMM"},
...
import fs from 'fs'
const boardList = require('./boards.json')
const content = fs.readFileSync('./list.txt').toString()
const pathList = content.split('\n')
const content2 = fs.readFileSync('./group').toString()
const annBoardList = content2.split('\n')
const annBoards = {} as any
annBoardList.forEach(line => {
if (!line) { return }
const [ann, board] = line.split(/\s+/)
// 2[影音] 贴图
// 1[大话西游] TODO_List
let prefix = ''
switch (ann) {
case 'AxFaction':
// @EGroups 10, 25, 0, "0BBS", "0) 斧 头 帮 -- [黑帮/系统]"
prefix = '0[斧 头 帮]'
break
case 'Culture':
prefix = '5[吟风弄月]'
break
case 'DouFuGirl':
// @EGroups 0, 0, 0, "7Science", "7) 豆腐西施 -- [信息/商业]"
prefix = '7[豆腐西施]'
break
case 'Entertain':
// @EGroups 0, 0, 0, "3Computer", "3) 吃喝玩乐 -- [生活/享受]"
prefix = '3[吃喝玩乐]'
break
case 'Factions':
// @EGroups 0, 0, 0, "2Class", "2) 大小分舵 -- [地盘/校班]"
prefix = '2[大小分舵]'
break
case 'GoWest':
// @EGroups 0, 0, 0, "6Society", "6) 西游之路 -- [出国/取经]"
prefix = '6[西游之路]'
break
case 'PandoraBox':
// @EGroups 0, 0, 0, "8City", "8) 东成西就 -- [乡情/城市]"
prefix = '8[东成西就]'
break
case 'Poem':
// @EGroups 0, 0, 0, "5Art", "5) 吟风弄月 -- [感性/文化]"
prefix = '5[吟风弄月]'
break
case 'Reserve':
// @EGroups 0, 0, 0, "9Talk", "9) 大圣取经 -- [专业/申请]"
prefix = '9[大圣取经]'
break
case 'Watering':
// @EGroups 0, 0, 0, "4Rec", "4) 游戏人生 -- [游戏/娱乐]"
prefix = '4[游戏人生]'
break
case 'zixia':
// @EGroups 0, 0, 0, "1THU", "1) 大话西游 -- [科学/技术]"
prefix = '1[大话西游]'
break
default:
console.info('unknown line:', line)
throw new Error('faint')
}
annBoards[board] = prefix
})
const newBoards = {} as {
[path: string]: {
name?: string,
path?: string,
bm?: string[],
}
}
boardList.forEach((board: any) => { newBoards[board.path] = {} })
pathList.forEach(p => { newBoards[p] = { path: p } })
boardList.forEach((board: any) => {
console.info('board: ', board)
const b = newBoards[board.path]
const prefix = annBoards[board.path]
if (!prefix) {
throw new Error(board.path)
}
b.name = prefix + ' ' + board.name.replace(/^.*\//, '')
b.path = board.path
if (!board.bm) {
b.bm = ['SYSOPS']
} else {
b.bm = board.bm.split(/\s+/)
}
})
// console.info(boardList, pathList)
console.info(JSON.stringify(newBoards))
Data files:
$cat boards.json
[
{"path": "sysop", "name": "斧头帮大堂", "bm": "SYSOP"},
{"path": "Announce", "name": "斧头帮通告", "bm": "SuperMM"},
{"path": "vote", "name": "投票结果", "bm": "SYSOP"},
{"path": "Manager", "name": "猪头开会", "bm": "SuperMM ZhuTou"},
...
$ more list.txt
0000
17Salsa
1Club
2.Trade
29BBS
3.Look4Group
3Amanager
...
$ more group
AxFaction sysop
AxFaction Announce
AxFaction vote
AxFaction Manager
AxFaction INeed
AxFaction FAQ
AxFaction test
AxFaction Discontentme
...
成功就在眼前了!
The json file has been put at /bbs/tmp/convert
folder:
bbs@bbs:~/tmp/convert$ ls -l boards.json
-rw-r--r-- 1 bbs bbs 62397 Jan 21 22:20 boards.json
How to read json in C ... -_-b...
bbs@bbs:~/tmp/convert$ wc -l < dotboards.name.txt
835
boardheader.BM
bbs@bbs:~/tmp/convert$ wc -l < dotboards.bm.txt
835
bbs@bbs:~/tmp/convert$ wc -l < dotboards.path.txt
835
.BOARDS
We did it!
bbs@bbs:~/tmp/convert$ strings ~/.BOARDS
sysop
SYSOP
SYSOP
Announce
SuperMM
...
find /bbs/0Announce/groups/ -maxdepth 2 > ann.txt
for b in $(cat dotboards.path.txt); do echo $(grep "/$b$" ann.txt | head -1); done
We rebuilt .BOARDS
succeed on Jan 25, 2021!
Close this issue because it seems that our boards work great now!
Really thank all the efforts from @realkcn, appreciate it!
Struct:
boardheader
list of boards:
Content of file ".Names" in 0Announce:
Group defined in etc/menu.ini
Some other information from syssecurity board.