Winse Blog

走走停停, 熙熙攘攘, 忙忙碌碌, 不知何畏.

Sed Debug: Sedsed

上一篇把html转成rst,但是页面之间的链接都断了。需要在标题前加上一个TAG,最终效果如下:

1
2
3
4
5
6
7

.. _Creating Objects in New Mappings:

Creating Objects in New Mappings
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ :ref:`Creating Objects in New Mappings`

想使用sed来实现这个功能,需要利用一些sed的高级功能,但默认sed是不能调试。这里使用sedsed来查看每一个操作的模式空间和缓冲空间,有点类似print调试。对于理解 sed 很有帮助,特别是对理解缓冲区和模式区数据的处理。

安装 sedsed

1
2
cd /opt/
git clone https://github.com/aureliojargas/sedsed

看看实际的调试输出:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
[root@ansible sedsed]# echo -e "one\ntwo\nthree\nfour" | ./sedsed.py -d -f test/scripts/sort.gnu.sed 
PATT:one$
HOLD:$
COMM:H
PATT:one$
HOLD:\none$
COMM:$ !d
PATT:two$
HOLD:\none$
COMM:H
PATT:two$
HOLD:\none\ntwo$
COMM:$ !d
PATT:three$
HOLD:\none\ntwo$
COMM:H
PATT:three$
HOLD:\none\ntwo\nthree$
COMM:$ !d
PATT:four$
HOLD:\none\ntwo\nthree$
COMM:H
PATT:four$
HOLD:\none\ntwo\nthree\nfour$
COMM:$ !d
PATT:four$
HOLD:\none\ntwo\nthree\nfour$
COMM:g
PATT:\none\ntwo\nthree\nfour$
HOLD:\none\ntwo\nthree\nfour$
COMM:s/.//
PATT:one\ntwo\nthree\nfour$
HOLD:\none\ntwo\nthree\nfour$
COMM:s/\n/&L&l/g
PATT:one\nL\nltwo\nL\nlthree\nL\nlfour$
HOLD:\none\ntwo\nthree\nfour$
COMM:s/^/\\Na/
PATT:\naone\nL\nltwo\nL\nlthree\nL\nlfour$
HOLD:\none\ntwo\nthree\nfour$
COMM:s/\nL/\\NA/
PATT:\naone\nA\nltwo\nL\nlthree\nL\nlfour$
HOLD:\none\ntwo\nthree\nfour$
COMM:s/$/\\NL/
PATT:\naone\nA\nltwo\nL\nlthree\nL\nlfour\nL$
HOLD:\none\ntwo\nthree\nfour$
COMM:b start
COMM:/\nA$/ b exit
COMM:s/\nb/\\Nl/
PATT:\naone\nA\nltwo\nL\nlthree\nL\nlfour\nL$
HOLD:\none\ntwo\nthree\nfour$
COMM:s/\nB/\\NL/
PATT:\naone\nA\nltwo\nL\nlthree\nL\nlfour\nL$
HOLD:\none\ntwo\nthree\nfour$
COMM:s/\(\na.*\nA\)\nl\([^\n]*\)\nL/\1\\Nb\2\\NB/
PATT:\naone\nA\nbtwo\nB\nlthree\nL\nlfour\nL$
HOLD:\none\ntwo\nthree\nfour$
COMM::sort
COMM:h
......

[root@ansible sedsed]# (date +'%w %d' ; date +'%-m %Y') | ./sedsed.py -d -f test/scripts/cal.sed
......

网上的一案例

看到一个论坛帖子上用sed实现 删除匹配的前两行和后三行 ,看的不是很明白,帖子仅注意介绍流程,至于数据到底是怎么样的没有讲。如果知道 sedsed 这工具的话,运行一遍就全部清楚了:

sedsed.py 处理 + 加号有点问题,所以这里就处理匹配的前两行,看看具体的数据是怎么流转的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
[root@ansible sedsed]# echo -e "1\n2\n3\n4\n5\n6\n7\n8\n9\n10" | ./sedsed.py -d '/5/d;:go;1,2!{P;N;D};N;bgo' 
PATT:1$
HOLD:$
COMM:/5/ d
PATT:1$
HOLD:$
COMM::go
COMM:1,2 !{
COMM:N
PATT:1\n2$
HOLD:$
COMM:b go
COMM:1,2 !{
COMM:N
PATT:1\n2\n3$
HOLD:$
COMM:b go
COMM:1,2 !{
COMM:P
1
PATT:1\n2\n3$
HOLD:$
COMM:N
PATT:1\n2\n3\n4$
HOLD:$
COMM:D
PATT:2\n3\n4$
HOLD:$
COMM:/5/ d
PATT:2\n3\n4$
HOLD:$
COMM::go
COMM:1,2 !{
COMM:P
2
PATT:2\n3\n4$
HOLD:$
COMM:N
PATT:2\n3\n4\n5$
HOLD:$
COMM:D
PATT:3\n4\n5$
HOLD:$
COMM:/5/ d
PATT:6$
HOLD:$
COMM:/5/ d
PATT:6$
HOLD:$
COMM::go
COMM:1,2 !{
COMM:P
6
PATT:6$
HOLD:$
COMM:N
PATT:6\n7$
HOLD:$
COMM:D
PATT:7$
HOLD:$
COMM:/5/ d
PATT:7$
HOLD:$
COMM::go
COMM:1,2 !{
COMM:P
7
PATT:7$
HOLD:$
COMM:N
PATT:7\n8$
HOLD:$
COMM:D
PATT:8$
HOLD:$
COMM:/5/ d
PATT:8$
HOLD:$
COMM::go
COMM:1,2 !{
COMM:P
8
PATT:8$
HOLD:$
COMM:N
PATT:8\n9$
HOLD:$
COMM:D
PATT:9$
HOLD:$
COMM:/5/ d
PATT:9$
HOLD:$
COMM::go
COMM:1,2 !{
COMM:P
9
PATT:9$
HOLD:$
COMM:N
PATT:9\n10$
HOLD:$
COMM:D
PATT:10$
HOLD:$
COMM:/5/ d
PATT:10$
HOLD:$
COMM::go
COMM:1,2 !{
COMM:P
10
PATT:10$
HOLD:$
COMM:N
10

可以看到 PATT 模式空间把前面两行连到一起了,匹配到 5 的时刻其实模式空间的内容为 3\n4\n5,然后执行 d 这就相当于删除前两行了。

该命令会多输出最后一行:由于到最后一行,N 又读取了一次下一行(读到结束符),直接就返回没有执行 D 了。sed 文档中的描述如下:

D' If pattern space contains no newline, start a normal new cycle as if thed’ command was issued. Otherwise, delete text in the pattern space up to the first newline, and restart cycle with the resultant pattern space, without reading a new line of input.

N' Add a newline to the pattern space, then append the next line of input to the pattern space. If there is no more input thensed’ exits without processing any more commands.

修复就是:读到最后一行的时刻就不读下一行了:

1
[root@ansible sedsed]# echo -e "1\n2\n3\n4\n5\n6\n7\n8\n9\n10" | sed '/5/,+3d;:go;1,2!{P;$!N;D};N;bgo' 

加标签

Sphinx可以通过 ref 来访问整个文档中定义的标签。所以只需要在每个标题前加上TAG,然后把链接引用修改成 ref 的方式即可。

1
2
3
4
5
6
7
# 文档加TAG:
sed -i ' h;N; /\n=\+$/{ x;s/.*/.. _&:\n/;p; x };  P;D ' $(find . -name '*.rst')
sed -i ' h;N; /\n-\+$/{ x;s/.*/.. _&:\n/;p; x };  P;D ' $(find . -name '*.rst')


# 修改链接引用:
sed 's/\(`[[:alnum:] ]*`\)_/:ref:\1/ ' $(find . -name '*.rst')

–END

Gitlab on Docker

1
2
3
4
5
6
7
8
9
10
11
12
13
./docker-download-mirror.sh sameersbn/redis sameersbn/gitlab:10.1.4 sameersbn/postgresql:9.6-2

# 最好,每个 docker-compose.yml 放不同的目录名称下!!
mkdir gitlab
cd !*

wget https://raw.githubusercontent.com/sameersbn/docker-gitlab/master/docker-compose.yml
sed -i '/GITLAB_HOST/s/.*/    - GITLAB_HOST=192.168.193.8/' docker-compose.yml 

docker-compose up -d

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload

–END

使用Sphinx生成/管理文档

很多开源的软件都使用Sphinx来进行文档的管理,其中Ansible就是其中一个。

Sphinx使用 类MarkDown的reStructuredText格式 来进行内容的编写,然后使用 sphinx-build 命令来生成html文件。

安装、入门

1
2
3
4
sudo apt-get install python-pip
sudo pip install Sphinx

sphinx-quickstart

引用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

*重点(emphasis)通常显示为斜体*
`解释文字(interpreted text)通常显示为斜体`

**重点强调(strong emphasis)通常显示为粗体**

``行内文本(inline literal)通常显示为等宽文本,空格可以保留,但是换行不可以。``

章节头部由下线(也可有上线)和包含标点的标题 组合创建, 其中下线要至少等于标准文本的长度。
可以表示标题的符号有 =、-、`、:、'、"、~、^、_ 、* 、+、 #、<、> 。
对于相同的符号,有上标是一级标题,没有上标是二级标题。
标题最多分六级,可以自由组合使用。

# with overline, for parts
* with overline, for chapters
=, for sections
-, for subsections
^, for subsubsections
", for paragraphs

主题

1
2
3
sudo pip install sphinx_rtd_theme

sed -i "/html_theme/s/.*/html_theme = 'sphinx_rtd_theme'/" conf.py

管理历史文档

先使用 html2rest 把html转成reStructuredText格式。

1
2
3
4
5
6
7
8
9
10
11
12
sudo pip install html2rest

#JSON:原始文档层次结构
  [
  { "id": "a16", "pId": "a", "name": "Administration", "file": "output/AdministrativeDocumentation.html" }, 
  { "id": "a1617", "pId": "a16", "name": "Basic Configuration Guide" },
  { "id": "a161718", "pId": "a1617", "name": "Configuring Deployments", "file": "output/ConfiguringDeployments.html" }
  ]

cat administration.json | jq '.[].file' | sed 's/"//g' | while read line ; do cp "$line" administration.origin/  ; done
cd administration.origin
ls | while read f ; do html2rest $f >"../administration.rst/${f%%.*}.rst" ; done

这仅仅是把html转换成了reStructuredText格式,当然我们还可以做多一些的操作:把文件结构也创建出来。

脚本内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash

JSON_FILE=~/administration.json

function children(){
local id=$1

local name="$( cat "$JSON_FILE" | jq '.[] | select(.id=="'$id'")' | jq '.name' | sed 's/"//g' )"
echo "id: $id, name: $name"

local filename="$( echo $name | sed 's/[^[:alnum:]]//g' )"

if [ ! -f "$filename.rst" ] ; then
cat > "$filename.rst" <<EOF
$name
======================================

EOF
fi

local nodes="$( cat "$JSON_FILE" | jq '.[] | select(.pId=="'$id'")' )"

if [ "x$nodes" == "x" ] ; then 
  return 1
fi

# if have children, create folder and toc
local foldername="$( echo $name | sed 's/[^[:alnum:]]//g' )"
local names="$( echo "$nodes" | jq ".name" | sed 's/[^[:alnum:]]//g' )"
local ids="$( echo "$nodes" | jq ".id" | sed 's/[^[:alnum:]]//g' )"

if ! grep '.. toctree::' "$foldername.rst" ; then
cat >>"$foldername.rst" <<EOF

Contents:

.. toctree::
   :maxdepth: 3
   :titlesonly:
   :glob:
   
$( echo "$names" | sed "s#^#   $foldername/#" ) 

EOF
fi

mkdir -p "$foldername"
pushd "$foldername"

while read cid
do 
  children $cid
done < <(echo "$ids")

popd

}


children a

然后执行该命令,把目录、目录索引、临时文件创建好:

1
2
cd ~/administration
./docs-gen.sh

然后就是把最开始转换的rst文件拷贝过来:

1
2
3
4
5
6
7
8
9
10
cd ../administration.rst

ls | while read f ; do 
filename="$(echo $f | sed 's/.rst$//' | sed 's/[^[:alnum:]]//g' ).rst" ; 
find ../administration/ -name "$filename" -exec /bin/cp -f $f {} \;  ;  
done

#再执行一遍docs-gen.sh,把目录的索引再(确认)添加一次
cd ../administration
./docs-gen.sh

完后生成 make html ,直接打开 _build/html/index.html 查看下内容。

最后就是根据具体情况,做一些细微的调整了。

MISC

–END

使用TeamviewerVPN访问公司内网

一直以来都只是用Teamviewer的图形界面,如果仅仅针对单台机器操作还是蛮OK的。但是如果想要访问远程的整个集群,那就为难了。

以前通过 公司的跳板机 ,然后连接 内网搭建的VPN 来实现 透明 的访问公司的环境。也折腾过自己买一台aliyun的机器搞一个外网IP,然后通过SSH的反向代理来间接的跳转访问公司内网,但成本都还是比较高的。

既然Teamviewer提供了一种远程访问的方式,那么能不能通过Teamviewer来实现代理,继而类似VPN的方式在家访问公司内网呢?

备注:一般都是双保险啊,Teamviewer和Anydesk都放一个!!!

安装

Teamviewer是提供了VPN的访问方式,需要在安装的时刻 选择【显示高级设置】,在下一步中选择【使用Teamviewer VPN】。连接的 两台主机都需要安装Teamviewer VPN 的功能!!!

使用VPN

访问内网

如果是Linux的话,可以在iptables上面配置SNAT,但是Linux Teamviewer暂时不支持VPN功能。 并且公司运行Teamviewer的机器是WIN7,不能通过运行nat命令(server版本才有)来设置转发。最后功夫不负有心人,找到了在win7下可以设置NAT的方法:

转发配置

  1. 连接的两台机器都启动 Routing an Remote Access 系统服务。(修改注册表IPEnableRouter的,不弄也行)
  2. 在公司Teamviwer机器上,下载并安装 NAT配置工具
  3. 在公司Teamviwer机器上,打开配置工具 WinpkFilter - Internet Gateway ,配置 本地连接 为Provider, Teamviewer VPN 为Client,然后启动 Start NAT。

  1. 在本地机器上,添加route,把访问 公司内网IP 的数据转到公司Teamviewer VPN,这样我们就可以透明的访问公司的所有机器了。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#网关填公司Teamviewer端的IP地址!!!
C:\Windows\system32>route add 192.168.193.0 mask 255.255.255.0 7.138.125.65 metric 1

C:\Windows\system32>ping 192.168.193.110

正在 Ping 192.168.193.110 具有 32 字节的数据:
来自 192.168.193.110 的回复: 字节=32 时间=22ms TTL=63
来自 192.168.193.110 的回复: 字节=32 时间=21ms TTL=63
来自 192.168.193.110 的回复: 字节=32 时间=21ms TTL=63

192.168.193.110 的 Ping 统计信息:
    数据包: 已发送 = 3,已接收 = 3,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 21ms,最长 = 22ms,平均 = 21ms

完美,所有的事情Teamviewer都帮想到了并且实现了。

把上面的全部操作写到一个脚本,以后直接使用管理员权限运行即可:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
winse@DESKTOP-ADH7K1Q:~/bigendian$ cat VPN-Route.bat
@setlocal enableextensions enabledelayedexpansion
@echo on

rem https://community.teamviewer.com/t5/Knowledge-Base/Are-there-parameters-to-start-TeamViewer/ta-p/4135
rem teamviewer.exe -i <ID> -P <Password> [-m fileTransfer/vpn]
start "teamviewer" "C:\Program Files (x86)\TeamViewer\TeamViewer.exe"

set teamvpnipaddr=7.138.125.65

:loop
ping -n 1 !teamvpnipaddr! | find "TTL"
if not errorlevel 1 goto :run
if errorlevel 1 goto :endloop
:endloop
ping -n 2 127.0.0.1 >nul: 2>nul:
cls
goto :loop

:run
route delete 192.168.193.0
route add 192.168.193.0 mask 255.255.255.0 !teamvpnipaddr! metric 1

endlocal

pause

参考的原文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Hello everybody, I investigated a lot for this issue.
Establish a VPN session with TeamViewer to my home pc (remote side) and try to get access to this local network from my working place (local side).
I found an solution i never read anywhere before. Since Windows 7 has removed NAT option using netsh it is difficult to solve it with windows on board tools only.
- Install TeamViewer incl. VPN driver on both sides, activate unattended access on the remote side (my home pc). Use the button Show advanced options, and go to Advanced network options … Install VPN driver
- Install WinPkFilter Device Driver on remote side (my home pc) and restart (http://www.nat32.com/v2/install.htm Download installer: http://www.ntkernel.com/downloads/winpkflt_rtl.zip . NAT32 you don't need. This WinPkFilter package contains a simple GUI to configure the NAT between the VPN interface (client) and the remote side LAN interface (provider). see following hints ...
- Windows: Start RemoteAccess - service 'Routing an Remote Access'  and set to automatic (local/remote side).
- Optional: On the remote side (my home pc), the registry has to be modified. Start the registry editor for example by Regedt32, and browse to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters Set the parameter IPEnableRouter to “1”. Using console or batch as admin: reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "IPEnableRouter" /t REG_DWORD /d "1". On my system it worked without this option, but according internet forums it seems to be recommended.
- Now create a remote desktop session to your home pc and start also the VPN connection within this TeamViewer session (Menu / Extras / VPN). I created a free TeamViewer account and added all pc's to my computers to make the access to my machines easier.
- On remode side (my home pc) where WinPkFilter is installed start the Internet Gateway GUI of WinPkFilter: Start / Programms / WinpkFilter / Internet Gateway. Select (double click) the ethernet adapter of your local privat lan and set NAT Status to 'Provider'. Select the TeamViewer VPN adapter and set NAT Status to 'client'. Press 'Start NAT'
 - On local side (my working place) Add a route to the local side (my working place) to give access to several devices that have the same subnet, add the route like this:

route add <base IP of remote devices> mask 255.255.255.0 <IP of Teamviewer VPN on remote PC> 
metric 1

Example (home lan ip range: 192.168.2.x / TeamViewer VPN IP in home pc (remote side) 7.37.88.245
route add 192.168.2.0 mask 255.255.255.0 7.37.88.245 metric 1 <ENTER>
route add 192.168.2.0 mask 255.255.255.0 7.37.88.245 metric 1 -p <ENTER> (if persistent)
Do delete the route route delete 192.168.2.0
Now you should have access to your private home network. Good luck and have fun.

–END

Windows Run Ubuntu

最新版的Windows已经可以安装ubuntu了,算是微软开源后的一个阶段性的成果了。

功能和windows兼容性很强(不像cygwin),软链接、文件权限都是和系统一致的。并且基本所有ubuntu的功能都可以使用,安装jekyll、docker都很顺利。同时打开系统的程序也很方便。非常赞和值得程序员去尝试!!

本文后面会逐渐增加使用过程中的一些操作,今天先更新系统安装、octopress安装、docker安装。

系统安装

直接去微软的官网下载最新版系统ISO,然后安装系统 专业版 (教育版比较干净一些,但是网上没有破解方式啊)。

Ubuntu

安装Ubuntu

最新版的Ubuntu已经进入到稳定版。直接打开商店,搜索Ubuntu,然后安装即可。大概200M的样子,很快就安装了。然后Launch会初始化创建用户。

相关的一些有用的文档:

安装mintty

CMD方式操作Ubuntu太难受了,mintty操作就像SecurtCRT一样,简单方便。安装 wsltty-1.8.0-install ,使用mintty来运行ubuntu。

默认mintty的配置放在 %APPDATA%\wsltty。在子目录theme下可以 http://ciembor.github.io/4bit/ 下载一个主题放到该目录下,然后再mintty配置页面选择该主题。

系统文件

root挂载点:C:\Users\<user>\AppData\Local\lxss or C:\Users\<username>\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState

安装Jekyll

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# https://superuser.com/questions/116625/recursively-change-owner-windows-7
#takeown /f "C:\path\to\folder" /r
#icacls "C:\path\to\folder" /reset /T
用powershell管理员权限 "提"权
PS E:\winsegit\octopress> takeown /F . /R
修改就旧系统的文件属性:
PS E:\winsegit\octopress> cacls *.* /T /G Everyone:F

sudo apt-get update
sudo apt-get install ruby-bundler
sudo apt-get install ruby-dev
sudo apt-get install make
sudo apt-get install gcc
bundle install

sudo gem update
sudo gem uninstall rake
sudo gem install rake -v 10.5.0
sudo apt-get install nodejs
   
rake preview

winse@DESKTOP-ADH7K1Q:~/winsegit/octopress$ rake preview
/usr/lib/ruby/vendor_ruby/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /mnt/c/Windows/System32 in PATH, mode 040777
Starting to watch source with Jekyll and Compass. Starting Rack on port 4000
/usr/lib/ruby/vendor_ruby/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /mnt/c/Windows/System32 in PATH, mode 040777
/usr/lib/ruby/vendor_ruby/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /mnt/c/Windows/System32 in PATH, mode 040777
/var/lib/gems/2.3.0/gems/liquid-2.6.1/lib/liquid/htmltags.rb:43: warning: key "index0" is duplicated and overwritten on line 46
[2017-10-29 22:48:09] INFO  WEBrick 1.3.1
[2017-10-29 22:48:09] INFO  ruby 2.3.1 (2016-04-26) [x86_64-linux-gnu]
[2017-10-29 22:48:09] INFO  WEBrick::HTTPServer#start: pid=39 port=4000
Configuration file: /mnt/e/winsegit/octopress/_config.yml
            Source: source
       Destination: public
      Generating...
                    done.
                  

上面warning提示也有对应的Issue,也没所谓暂时不理: https://github.com/Microsoft/WSL/issues/1426

安装docker

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
winse@DESKTOP-ADH7K1Q:~$ uname -r
4.4.0-43-Microsoft
winse@DESKTOP-ADH7K1Q:~$ uname -a
Linux DESKTOP-ADH7K1Q 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014 x86_64 x86_64 x86_64 GNU/Linux

winse@DESKTOP-ADH7K1Q:~$  sudo apt-get install \
     apt-transport-https \
     ca-certificates \
     curl \
     software-properties-common

winse@DESKTOP-ADH7K1Q:~$ lsb_release -cs
xenial
winse@DESKTOP-ADH7K1Q:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK
winse@DESKTOP-ADH7K1Q:~$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

winse@DESKTOP-ADH7K1Q:~$ sudo apt-get update

winse@DESKTOP-ADH7K1Q:~$ sudo apt-get install docker-ce

winse@DESKTOP-ADH7K1Q:~$ sudo service docker start
 * Starting Docker: docker                                                                                                                     [ OK ]
winse@DESKTOP-ADH7K1Q:~$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
winse@DESKTOP-ADH7K1Q:~$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
winse@DESKTOP-ADH7K1Q:~$

运行windows系统应用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
winse@DESKTOP-ADH7K1Q:~$ ln -s /mnt/e/local/usr/share/npp/notepad++.exe text

winse@DESKTOP-ADH7K1Q:~$ cp -r ../winse-cygwin/new_post.sh ./
winse@DESKTOP-ADH7K1Q:~$ cat new_post.sh
cd ~/winsegit/octopress/
rake new_post["$1"] | tail -1 | awk -F: '{print $2}' | while read line
do
name=${line#source/_posts/}
newpath=source/_stash/$name
mv $line $newpath

echo -e "\n\n--END" >>$newpath

~/text $newpath &
done

winse@DESKTOP-ADH7K1Q:~$ ./new_post.sh "windows run ubuntu"
/usr/lib/ruby/vendor_ruby/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /mnt/c in PATH, mode 040777
mkdir -p source/_posts

重新配置git

用powershell修改原来的权限后,然后用shell来进行设置。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#powershell
takeown /F . /R
cacls *.* /T /G Everyone:F

#ubuntu shell
winse@DESKTOP-ADH7K1Q:~$ cp -r ../winse-cygwin/.ssh ./

winse@DESKTOP-ADH7K1Q:~$ cd .ssh
winse@DESKTOP-ADH7K1Q:~/.ssh$ chmod 600 id_rsa authorized_keys
winse@DESKTOP-ADH7K1Q:~/.ssh$ chmod 644 id_rsa.pub config

winse@DESKTOP-ADH7K1Q:~/winsegit/octopress/_deploy$ rm -rf *
winse@DESKTOP-ADH7K1Q:~/winsegit/octopress/_deploy$ git clone git@github.com:winse/winse.github.com.git ./

winse@DESKTOP-ADH7K1Q:~/winsegit/octopress$ git config --global user.email winseliu@qq.com
winse@DESKTOP-ADH7K1Q:~/winsegit/octopress$ git config --global user.name winse

winse@DESKTOP-ADH7K1Q:~/winsegit/octopress$ rake preview
winse@DESKTOP-ADH7K1Q:~/winsegit/octopress$ sh public.git.sh

–END