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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
#!/bin/sh

setupver="v2020.10.15(Beta 2)"


# [v2020.10.15(Beta)]
# * 加入簡體中文支援
# * 簡體中文模式:使用百度來測試網路連接,並提供純粹安裝模式
# * Beta 2 修正bug...
#
# [v2020.09.29 beta 2]
# * 增加自行輸入還原檔版本功能
# * 增加指定下載還原檔時,可以先刪除現有 rammus_recovery.bin 功能


tmp=0
while [ $tmp -eq 0 ]  ; do
    echo "       "
    echo "選擇語言        : C) 繁體中文"
    echo "選擇語言        : S) 簡體中文 (將進行純安裝模式)"
    echo "Select Language : E) English"
    read -p " -> (C/S/E)" lang

    case $lang in
         [Cc]* ) lang=C;tmp=1;;
         [Ss]* ) lang=S;tmp=1;;
         [Ee]* ) Lang=E;tmp=1;;
    esac
done


echo "   " > .tmp


echo "        "

clear
 
 if [ $lang = S ]; then
    wget -q --spider https://www.baidu.com/
else
    wget -q --spider http://google.com  
fi


if [ $? -eq 0 ]; then

    if [ $lang != S ]; then
    
    dodl=N

        tmp=0
        while [ $tmp -eq 0 ]  ; do

            clear
            
            if [ $lang = C ]; then
                echo "     [Chrome OS 安裝助理]   $setupver"
                echo "     "
                echo " 《還原映像檔 版本選擇》"
                echo " (1) rammus   : 建議 4 代以上 Intel 處理器"
                echo " (2) samus    : 3代以下 Intel 處理器"
                echo " (3) grunt    : AMD Stoney Ridge 處理器"
                echo " -------------------------------------------- "
                echo " (4) eve      : Google Pixelbook"
                echo " (5) nami     : Acer Chromebook 13 etc..."
                echo " (6) nocturne : Google Pixel Slate "
                echo " (7) octopus  : ASUS Chromebook Flip C214 etc.."
                echo " -------------------------------------------- "
                echo " (8) 略過映像檔下載"
                echo " (9) 自行輸入映像檔版本(風險:不做防錯處理)"
                echo " -------------------------------------------- "
                read -p "選擇映像檔版本:" tmp            
            else
                echo "     [Chrome OS Setup Assistant]   $setupver"
                echo "     "
                echo " >Select Recovery image< "
                echo " (1) rammus   : Recommand for 4th-gen Intel cpu or newer"
                echo " (2) samus    : 3rd-gen Intel cpu or older"
                echo " (3) grunt    : AMD Stoney Ridge"
                echo " -------------------------------------------- "
                echo " (4) eve      : Google Pixelbook"
                echo " (5) nami     : Acer Chromebook 13 etc..."
                echo " (6) nocturne : Google Pixel Slate "
                echo " (7) octopus  : ASUS Chromebook Flip C214 etc.."
                echo " -------------------------------------------- "
                echo " (8) Pass image downloading "
                echo " (9) User defined board (No error proofing)"
                echo " -------------------------------------------- "
                read -p "Choice your device:" tmp
            fi

            case $tmp in
                1 ) img=rammus;tmp=1;;
                2 ) img=samus;tmp=1;;
                3 ) img=grunt;tmp=1;;
                4 ) img=eve;tmp=1;;
                5 ) img=nami;tmp=1;;
                6 ) img=nocturne;tmp=1;;
                7 ) img=octopus;tmp=1;;
                8 ) img=none;tmp=1;;
                
                9 ) tmp=1

                echo "      "

                if [ $lang = C ]; then
                    echo "請輸入指定的還原映像檔版本。 例如,reef";
                else
                    echo "Please enter Image board. For e.g. reef";
                fi
                
                read img;;

            esac
            
        done
        
        
        echo "        "

        echo "#!/bin/sh" > _setup.sh

        if [ $img != none ]; then



            if [ -f "rammus_recovery.bin" ]; then 


                if [ $lang = C ]; then
                    read -p "rammus_recovery.bin 已經存在,要先刪除嗎? (Y/N)" tmp
                else
                    read -p "rammus_recovery.bin already exist. Delete it? (Y/N)" tmp
                fi
                
                case $tmp in
                    [Yy]* ) rm rammus_recovery.bin
                            echo "... OK~s"
                            ;;
                esac

                echo "      "

            fi



            if [ $lang = C ]; then
                echo "檢查還原映像檔..."
            else
                echo "Checking Recovery Image... "
            fi

            wget -O .tmp -q https://cros.tech/device/$img

            tr "\"><" "\n\r" < .tmp | grep .zip  | tail -n 1 | sed -e 's/\//\n/g' | tail -n 1 | sed -e 's/.bin.zip//g' 

            tr "\"><" "\n\r" < .tmp | grep .zip  | tail -n 1 | sed -e 's/\//\nifn\=/g' | tail -n 1 | sed -e 's/.bin.zip//g'  >> _setup.sh
            tr "\"><" "\n\r" < .tmp | grep .zip  | tail -n 1 | sed -e 's/http/iur\=http/g'  >> _setup.sh

            dodl=Y

            echo wget \$iur >> _setup.sh
            echo unzip \$ifn.bin.zip >> _setup.sh
            echo mv \$ifn.bin rammus_recovery.bin >> _setup.sh
            echo rm \$ifn.bin.zip  >> _setup.sh

        fi


        # ====================================================================================================


        echo "        "

        if [ $lang = C ]; then
            read -p "要下載 brunch 框架嗎? (Y/N)" tmp
        else
            read -p "Download brunch? (Y/N)" tmp
        fi
        
        case $tmp in
            [Nn]* ) tmp=N;;
        esac
        
        echo "        "


        if [ $tmp != N ]; then

            echo "        "

            if [ $lang = C ]; then
                echo "檢查最新版的 Brunch..."
            else
                echo "Checking latest Brunch..."

            fi
            
            wget -O .tmp -q https://github.com/sebanc/brunch/releases/latest

            dodl=Y

            grep .tar.gz"" .tmp | cut -d '"' -f 2 -s | sed -n '1p' | cut -d '/' -f 7 | sed -e 's/.tar.gz//' ;


            grep .tar.gz"" .tmp | cut -d '"' -f 2 -s | sed -n '1p' | sed -e 's/\/sebanc/https:\/\/github.com\/sebanc/' | sed -e 's/http/bur\=http/g'  >> _setup.sh

            grep .tar.gz"" .tmp | cut -d '"' -f 2 -s | sed -n '1p' | sed -e 's/\//\nbfn=/g' | tail -n 1 | sed -e 's/.tar.gz//g' >> _setup.sh


            echo wget \$bur >> _setup.sh
            echo tar zxvf \$bfn.tar.gz >> _setup.sh


            if [ $lang = C ]; then
                read -p "要保留 brunch 框架壓縮檔嗎? (Y/N)" tmp
            else
                read -p "keep brunch archive? (Y/N)" tmp
            fi
            
            case $tmp in
                [Yy]* ) tmp=N;;
                * ) echo rm \$bfn.tar.gz  >> _setup.sh ;;
            esac
            
            echo "        "

            echo unset ifn  >> _setup.sh
            echo unset iur  >> _setup.sh


        fi



        if [ $dodl = Y ]; then
        
            echo "     "

            if [ $lang = C ]; then
                echo "     "
                echo "讓我們開始下載吧~"
            else
                echo "Let's start download~ "
            fi

            echo "                    "
            
            sleep 3

            sh _setup.sh
            
        else

            sleep 3

        fi


        # ====================================================================================================

    fi



    clear

    tmp=0
    while [ $tmp -eq 0 ]  ; do

        if [ $lang = C ]; then
            echo "     [Chrome OS 安裝助理]   $setupver"
            echo " (1) 安裝到硬碟"
            echo " (2) 安裝到指定分割區"
            echo " (3) 不裝了"
            echo " -------------------------------------------- "
            read -p "請選擇:" way

        elif [ $lang = S ]; then
            echo "     [Chrome OS 安裝助理]   $setupver"
            echo " (1) 安裝到硬盤"
            echo " (2) 安裝到指定分區"
            echo " (3) 不裝了"
            echo " -------------------------------------------- "
            read -p "請選擇:" way            

        else
            echo "     [Chrome OS Setup Assistant]   $setupver"
            echo " (1) install to a disk"
            echo " (2) install to a partition"
            echo " (3) Do Nothing"
            echo " -------------------------------------------- "
            read -p "Choice your action:" way

        fi

        case $way in
        
         1 ) tmp=1

            sudo apt-get update
            sudo apt-get install pv
            sudo apt-get install cgpt


            if [ $lang = C ]; then
                echo "         "
                echo "    【磁碟列表】     "
                lsblk -d | more
                echo "           "
                echo "請輸入欲安裝 Chrome OS 的硬碟名稱。 例如,sda";
            elif [ $lang = C ]; then
                echo "         "
                echo "    【磁盤列表】     "
                lsblk -d | more
                echo "           "
                echo "請輸入欲安裝 Chrome OS 的硬碟名稱。 例如,sda";
            else
                echo "         "
                echo "    【Disk List】     "
                lsblk -d | more
                echo "           "
                echo "Enter the disk you want Chrome OS install to. Eg: sda";
            fi
            read instdisk
            sudo bash chromeos-install.sh -src rammus_recovery.bin -dst /dev/$instdisk;;

         2 ) tmp=1

            sudo add-apt-repository ppa:danielrichter2007/grub-customizer -y
            sudo apt-get update
            sudo apt-get install figlet
            sudo apt-get install pv
            sudo apt-get install cgpt
            sudo apt-get install gparted
            sudo apt-get install grub-customizer


            if [ $lang = C ]; then
                echo "         "
                echo "將開啟磁碟分割工具,請在程式中確認安裝分割區的位置與狀態(如 sda5,需為 NTFS 格式)…";
                sellp 5
                sudo gparted
                echo "請輸入Chrome OS多重啟動安裝的分區名稱。 例如,sda5";
            elif [ $lang = S ]; then
                echo "         "
                echo "將開啟磁碟分割工具,請在程式中確認安裝分割區的位置與狀態(需為 NTFS 格式)…";
                sellp 5
                sudo gparted
                echo "請輸入Chrome OS多重啟動安裝的分區名稱。 例如,sda5";
            else
                echo "         "
                echo "It will load gparted, please sure the partition you want to install( e.g. sda5 with NTFS)";
                sellp 5
                sudo gparted
                echo "Please enter partition name for Chrome OS multi boot install. For e.g. sda5";
            fi
            
            read partition
            
            sudo sfdisk -l /dev/$partition
            
            size=$(sudo fdisk -l /dev/$partition | awk '$1=="Disk" && $2 ~ /^\/dev\/.*/ {print int($3)}')
            
            while true; do
                if [ $lang = C ]; then
                    read -p "您是否要在 $partition 上格式化並安裝chrome os (輸入 yes 繼續)" yn
                elif [ $lang = S ]; then
                    read -p "您是否要在 $partition 上格式化並安裝chrome os (輸入 yes 繼續)" yn
                else
                    read -p "Do you wish to format and install chrome os on $partition?(type yes to continue)" yn
                fi

                case $yn in

                [Yy]* ) 
	                
	                if [ $lang = C ]; then
	                    echo "好的,在 $partition 上繼續安裝";
	                elif [ $lang = S ]; then
	                    echo "好的,在 $partition 上繼續安裝";
	                else
	                    echo "Ok, Proceeding installation on $partition";
	                fi
	                
	                mkdir -p ~/tmpmount;
	                sudo mount /dev/$partition ~/tmpmount;
	                sudo bash chromeos-install.sh -src rammus_recovery.bin -dst ~/tmpmount/chromos.img -s $size;
	                sudo umount ~/tmpmount;
	                
	                if [ $lang = C ]; then
	                    echo "在 grub 設定程式中,將上面的區域貼至 grub 選單項";
	                elif [ $lang = S ]; then
	                    echo "在 grub 設定程式中,將上面的區域貼至 grub 選單項";
	                else
	                    echo "Copy the above grub menu entry in grub customizer";
	                fi
                    echo "img_part=/dev................initramfs.img"
	                echo "       "
                    
	                sudo grub-customizer;
	                break;;
                
                [Nn]* ) exit;;
                
                * ) 
                
	                if [ $lang = C ]; then
	                    echo "請回答 yes 或 no。"
                    elif [ $lang = S ]; then
	                    echo "請回答 yes 或 no。"
	                else
	                    echo "Please answer yes or no."
	                fi
	                ;;
                
                esac

            done;;


        * ) tmp=1;;

        esac

    done




    echo "        "

    if [ $lang = C ]; then
        echo "完成,感謝使用~"
        echo "---------------------------------------------------------"
        echo "                 《銘謝》       "
        echo "* Brunch 專案"
        echo "     https://sites.google.com/view/brunch-project/home"
        echo "               "
        echo "* Chrome OS 支援"
        echo "     https://support.google.com/chromebook/?hl=zh-Hant"
        echo "               "
    elif [ $lang = S ]; then
        echo "完成,感謝使用~"
        echo "---------------------------------------------------------"
        echo "                 《銘謝》       "
        echo "* Brunch 專案"
        echo "     https://sites.google.com/view/brunch-project/home"
        echo "               "
        echo "* Chrome OS 支援"
        echo "     https://support.google.com/chromebook/?hl=zh-Hant"
        echo "               "
    else
        echo "Done.Thanks for using~ "
        echo "---------------------------------------------------------"
        echo "                  [Thanks]       "
        echo "* Brunch Project"
        echo "     https://sites.google.com/view/brunch-project/home"
        echo "               "
        echo "* Chrome OS Support"
        echo "     https://support.google.com/chromebook"
        echo "               "
    fi
 

    if [ -f "_setup.sh" ]; then rm _setup.sh ; fi
    if [ -f ".tmp" ]; then rm .tmp ; fi


    unset img
    unset tmp
    unset lang
    unset instdisk
    unset setupver
    unset dodl
    unset way

else

    if [ $lang = C ]; then
        echo "網路不通,請檢查之!"
    elif [ $lang = S ]; then
        echo "網路不通,請檢查之!"
    else
        echo "Not connected yet, please check!"
    fi

fi