# Building the Go38Box

* [MoodleBox 官網](https://moodlebox.net/en/)
* [MoodleBox Github](https://github.com/martignoni/moodlebox)

Go38Box修改自MoodleBox，而MoodleBox一開始就是設定在Raspberry Pi 3上執行運作，讓使用者可以隨身帶著一個Raspberry Pi 3及行動電源就可以使用Moodle教學平台，MoodleBox官網有做動的img檔可供使用者下載，然後燒錄到Raspberry Pi 3，或者可以透過手動建置的方式，在剛開始官方所提供的是一步一步的指令去修改設定，接著又轉換成使用script自動安裝(github中切換到[Branch:https](https://github.com/GXiangCo/moodlebox/tree/https))，現在則改用Ansbile自動化組態管理把Moodle安裝到Raspberry Pi 3中，而Go38Box的溫濕度也透過Ansible自動化組態管理來做安裝設定，安裝及設定的方式和Moodlebox一樣，所以以下就依Moodlebox官方的安裝步驟做說明

在官方的Github中有以下10點的安裝步驟

To build a MoodleBox from scratch with this script, you need a Raspberri Pi 3 (Wi-Fi!) and follow these instructions.

1. Clone Rasbpian Stretch Lite on your microSD card.
2. Create a`ssh`file on the`boot`partition, e.g. using`touch ssh`
3. Insert the microSD card into your Raspberry
4. Connect your Raspberry to your Ethernet network and boot it.
5. [Install Ansible](http://docs.ansible.com/intro_installation.html) on your computer.
6. [Clone this repository](https://github.com/martignoni/moodlebox.git) to your local drive.
7. Create a`keys`directory in the repository folder and copy your public key into it, under the name`id_rsa.pub`.
8. Get the IP address of your RaspberryPi and change it in the`hosts.yml`file. Do not change anything else, unless you know what you're doing. You're on your own.
9. Run`ansible-playbook moodlebox.yml`from the repository folder.
10. Wait 30–50 minutes, depending on your SD card and Internet bandwidth. You're done.

### 1. Clone Rasbpian Stretch Lite on your microSD card.

在Raspberry Pi 3的話就是直接到官方網站下載[Raspian Stretch Lite](https://www.raspberrypi.org/downloads/raspbian/)(<https://www.raspberrypi.org/downloads/raspbian/>)，不論是Raspberry Pi 3B還是3B Plus，請下載最新版的Release Date是2018-04-08(2018-04-18-raspbian-stretch-lite.zip)，下載完成後檔案的副檔名為zip，不用解壓縮直接用燒錄軟體選該zip檔即可，Mac作業系統可以使用[Etcher](https://etcher.io)軟體燒錄到microSD卡中，Windows作業系統可以使用[Win32DiskImager](https://sourceforge.net/projects/win32diskimager/)燒錄。

### 2. Create a ssh file on thebootpartition, e.g. using touch ssh

此動作在燒錄到microSD卡後，要先執行指令「touch ssh」產生ssh檔案開機後會啟動ssh服務，Mac作業系統打開終端機執行指令「touch /Volumes/boot/ssh」，Windows作業系統打開檔案總管，找到磁碟機名稱為boot的磁碟編號，例如磁碟機編號為「G」，打開命令提示字元，執行指令「touch G:\ssh」會在該磁碟內建立ssh檔，在Windows下燒錄完成或者重新把microSD插入電腦後，出現「需要格式化磁碟機…」的視窗，請不要執行格式化。

### 3. Insert the microSD card into your Raspberry

系統燒錄完成後，接著就是把microSD卡插入設備的microSD插槽，Raspberry Pi 3直接把microSD卡推到最底就可以，取出的方式是直接拔出microSD。

### 4. Connect your Raspberry to your Ethernet network and boot it

Raspberry Pi 3內建RJ-45網路介面，這個步驟只要把網路線線上，及插上電源，會自動開機。

### 5. [Install Ansible](http://docs.ansible.com/intro_installation.html) on your computer.

目前Ansible測試於Mac系統，請參考[Mac 安裝 Ansible ](https://gxiangco.gitbook.io/raspberry-pi-temperature/mac_install_ansible)的安裝步驟，如果是要在Windows系統需要透過類似VirtualBox建立Linux虛擬機器並且安裝Ansible。

### 6. [Clone this repository](https://github.com/martignoni/moodlebox.git) to your local drive.

在本機電腦中安裝好Ansible後，接著就是從GitHub上Clone Repository(復製儲存庫)，moodlebox官方的github網址「<https://github.com/martignoni/moodlebox>」，git的網址「<https://github.com/martignoni/moodlebox.git>」，如果安裝於Raspberry Pi 3請直接clone官方的設定檔即可，那這邊要修改網址，目前Go38Box專案存放在「<https://git.go38.net/go38/go38box-temperature.git>」

打開終端機，然後切換到要存放的路徑，輸入指令「git clone <https://git.go38.net/go38/go38box-temperature.git>」

```
allen-mbp:temp allen$ git clone https://git.go38.net/go38/go38box-temperature.git
Cloning into 'go38box-temperature'...
Username for 'https://git.go38.net': chen412@gmail.com
Password for 'https://chen412@gmail.com@git.go38.net':
remote: Counting objects: 132, done.
remote: Compressing objects: 100% (101/101), done.
remote: Total 132 (delta 8), reused 117 (delta 3)
Receiving objects: 100% (132/132), 1.06 MiB | 2.38 MiB/s, done.
Resolving deltas: 100% (8/8), done.
```

切換路徑到go38box-tempe，檢查是否有檔案

```
allen-mbp:temp allen$ ls
go38box-temperature/
allen-mbp:temp allen$ cd go38box-temperature/
allen-mbp:go38box-temperature allen$ ls
CHANGELOG.md*       README.md*          go38box.yml*        roles/
CODE_OF_CONDUCT.md* ansible.cfg*        hosts.yml*          rootaccount.yml*
CONTRIBUTING.md*    buildgo38box.yml*   keys/               setup.cfg*
LICENSE.md*         default.config.yml* library/            util/
allen-mbp:go38box-temperature allen$
```

### 7. Create a`keys`directory in the repository folder and copy your public key into it, under the name`id_rsa.pub`

這個步驟主要讓Raspberry Pi 3或Banana Pi M64可以免輸入密碼登入，讓Ansible執行安裝過程中不用再輸入密碼，首先在moodlebox-bpi目錄中建立一個名稱為keys的資料夾

```
allen-mba:moodlebox-bpi allen$ pwd
/Users/allen/github/moodlebox-bpi
allen-mba:moodlebox-bpi allen$ mkdir keys
allen-mba:moodlebox-bpi allen$ ls
CHANGELOG.md        README.md        hosts.yml        roles
CODE_OF_CONDUCT.md    ansible.cfg        keys            rootaccount.yml
CONTRIBUTING.md        buildmoodlebox.yml    library            setup.cfg
LICENSE.md        default.config.yml    moodlebox.yml        util
allen-mba:moodlebox-bpi allen$
```

使用ssh-keygen指令產生公開金鑰，產生過程會問要儲存的路徑及密碼，都不設定，用預設值即可，注意一下預設存放的路徑，一般都是在使用者帳號下的「.ssh」資料夾中，ssh-keygen產生過程如下：

```
allen-mba:~ allen$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/allen/.ssh/id_rsa):
Created directory '/Users/allen/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/allen/.ssh/id_rsa.
Your public key has been saved in /Users/allen/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:nCpzaCPq6waI3KTpm0sq+Yfoxku/ENVcL2gKX2ZLJrE allen@allen-mba.local
The key's randomart image is:
+---[RSA 2048]----+
|   .   .         |
|    = o .        |
| . E @ . .       |
|  +.X ....       |
|+.=o .  S        |
|++.. . .         |
|+*..* o          |
|B*=o.=           |
|X@*+.            |
+----[SHA256]-----+
```

執行完ssh-keygen後，預設檔名為id\_rsa，會產生兩個檔案id\_rsa及id\_rsa.pub於「使用者目錄/.ssh」中，確認一下是否有產生所要的檔案，如下：

```
allen-mba:~ allen$ ls -al ~/.ssh/
total 16
drwx------   4 allen  staff   128  3  7 15:28 .
drwxr-xr-x+ 53 allen  staff  1696  3  7 15:27 ..
-rw-------   1 allen  staff  1675  3  7 15:28 id_rsa
-rw-r--r--   1 allen  staff   403  3  7 15:28 id_rsa.pub
```

idrsa為私鑰，這就如登入的密碼，此檔案是放在本機電腦中，而id\_rsa.pub為公鑰，此檔案要放在遠端的電腦中認證用，所以要把id\_rsa.pub檔案複製到所建立的「keys」資料夾中，在執行Ansible時，會把此檔案放到遠端的設備中，最後檢查keys資料夾中是否有id\_rsa.pub檔

```
allen-mba:~ allen$ cp ~/.ssh/id_rsa.pub ~/temp/allen-mbp:go38box-t-bpi/keys/
allen-mba:~ allen$ ls ~/temp/allen-mbp:go38box-t-bpi/keys/
id_rsa.pub
```

### 8. Get the IP address of your RaspberryPi and change it in the`hosts.yml`file. Do not change anything else, unless you know what you're doing. You're on your own.

接著要設定Go38Box專案中的「hosts.yml」檔，此檔案主要是設定要連線的設備ip及登入的帳號及密碼，原始內容如下：

```
all:
  hosts:
    moodlebox:
      ansible_host: '192.168.1.212'
      ansible_user: 'pi'
      ansible_password: 'raspberry'
```

如同官方文件的說明，只要修改設備的ip，就是hosts.yml中的ansible\_host參數，其他如果不知道或沒必要請不要修改。

如果Raspberry Pi 3在沒有外接螢幕的狀況下要如何連線並且取得設備的ip呢？接下來就試範當設備燒錄好後，接上網路線並且開機後要如何連線取得設備ip，注意本機電腦和遠端的設備需要在同一個網段下。

Raspberry Pi 3

在終端機中執行指令「ssh <pi@raspberrypi.local>」，預設密碼為「raspberry」

```
allen-mba:~ allen$ ssh pi@raspberrypi.local
The authenticity of host 'raspberrypi.local (fe80::5f74:cb72:5324:c40b%en0)' can't be established.
ECDSA key fingerprint is SHA256:rvM07WHr9gcI+KOY1sr7+m3IpvakmgMRnpGt6tP2i8w.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'raspberrypi.local,fe80::5f74:cb72:5324:c40b%en0' (ECDSA) to the list of known hosts.
pi@raspberrypi.local's password:
Linux raspberrypi 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Mar  7 09:23:27 2018

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.
```

使用「ifconfig」指令查詢

```
pi@raspberrypi:~ $ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.3  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::5f74:cb72:5324:c40b  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:b6:d3:08  txqueuelen 1000  (Ethernet)
        RX packets 26122  bytes 3209257 (3.0 MiB)
        RX errors 0  dropped 64  overruns 0  frame 0
        TX packets 278  bytes 37615 (36.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether b8:27:eb:e3:86:5d  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
```

使用「ip addr」指令查詢

```
pi@raspberrypi:~ $ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:b6:d3:08 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.3/24 brd 192.168.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::5f74:cb72:5324:c40b/64 scope link
       valid_lft forever preferred_lft forever
3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether b8:27:eb:e3:86:5d brd ff:ff:ff:ff:ff:ff
```

### 9. Run`ansible-playbook moodlebox.yml`from the repository folder.

將目錄切換到Go38Box專案目錄，然後執行以下的指令開始執行安裝作業

Raspberry Pi 3

```
ansible-playbook moodlebox.yml
```

### 10. Wait 30–50 minutes, depending on your SD card and Internet bandwidth. You're done.

整個安裝過程大約30\~50分鐘，這個時間會因為使用的microSD卡讀寫的速度與網路頻寬的速度而有所不同。

* [透過Ansible安裝Go38Box](https://gxiangco.gitbook.io/raspberry-pi-temperature/ansible_playbook)

## 進入Go38Box溫濕度網站

以上十個步驟完成後，會自動重開機，打開網址就可以看到目前溫濕度的資訊

* Raspberry Pi 3預設網址：<http://go38box.local>

![](https://326572801-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdydZQ-x81-SQ8XuBk9%2F-LdydabJht7DXYEyRYFn%2F-LdydigbDMg0E4zBV9s9%2Fweb01.png?generation=1556903033246003\&alt=media)

## SSH進入Go38Box

如果要ssh到安裝好的Go38Box時，連線的網址會不同，被修改go38box.local，連線網址及帳號密碼，請參照下方的對照表

### 連線網址對照表

| 設備連線網址         | 官方預設值             | 安裝Go38Box     |
| -------------- | ----------------- | ------------- |
| Raspberry Pi 3 | raspberrypi.local | go38box.local |

### 連線的帳號密碼對照表

| 設備連線帳號 / 密碼    | 官方預設值            | 安裝Go38Box             |
| -------------- | ---------------- | --------------------- |
| Raspberry Pi 3 | pi  /  raspberry | go38box  /  Go38box4$ |

連線後的畫面會多一個樹梅派的logo，正常連線後會看到如下圖的畫面，會顯示一些資訊，但這個資訊目前設定是每10分鐘更新一次，第一行有日期時間，就是資料更新的時間！

![](https://326572801-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdydZQ-x81-SQ8XuBk9%2F-LdydabJht7DXYEyRYFn%2F-LdydigdNTmcdO3n_8ys%2Fgo38box-ssh.png?generation=1556903032613273\&alt=media)
