-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrpiarchppp
1371 lines (1348 loc) · 42.8 KB
/
rpiarchppp
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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Advanced script to install and configure Arch with ppp on indicated sdcardforarch
# More info and newest @ http://www.github.com/iugamarian/raspberrypisetup
# Version 1.73 tested and it works
# Forked from ShorTie <[email protected]>
# Brought to you by iugamarian <[email protected]>
# Configuration - choose here carefuly
sdcardforarch=/dev/sdwhat # Before running, lsblk to indicate card here
enablepppoe=0
installlxde=0
installmate=1
rpiversionnumber=0 # version, not revision: 0 = autodetect, 1 = BCM2835, 2 = BCM2836
insaneoverclock=0 # Overclock if set to 1. Set to 0 to avoid this.
# Keep over_voltage to 0 to keep warranty.
# Recommended to have active cooling if overclock. I have a fan on top.
# And have a power supply with minimum current of 2A . I have 3A.
# According to https://www.raspberrypi.org/forums/viewtopic.php?p=176865#p176865
# having an over_voltage of 0 ensures the warranty bit is not set
# (force_turbo || current_limit_override || temp_limit>85) && over_voltage>0
pppusername="userppp"
ppppassword="paswordppp"
pppprovider="isp"
# Use a minimum 8 GB card as I also make a swap partition of 512 MB. Down in "Fdisk area".
#********** END Configuration **************************************************************
# Check to see if device is indicated
if [ `echo $sdcardforarch | grep sdwhat |wc -c` -eq 0 ]; then
echo ""
echo "The drive to move root to is $sdcardforarch."
echo ""
else
lsblk
echo ""
echo "Specify the drive by editing the beginning of this script."
echo ""
exit 1
fi
# Check to see if running as root
echo -e "\nChecking for root."
if [ `id -u` != 0 ]; then
echo "Not root."
echo -e "Need to be run as root.\n"
echo " Try 'sudo sh rpiarchppp' as a user. Exiting."
echo ""
exit 1
else
echo "Root."
fi
# Noting time when started
start_time=$(date)
echo ""
echo ""
# Pi check
if [ `cat /proc/cpuinfo | grep BCM |wc -c` -eq 0 ]; then
echo "Not running on a Raspberry Pi."
rpirunningon=0
# exit 1
else
echo "Running on a Raspberry Pi."
rpirunningon=1
fi
echo ""
rpiversioncorrect=0
#Selecting version
if [ $rpiversionnumber -eq 0 ]; then
# Autodetect
rpiversioncorrect=1
echo "Autodetecting Raspberry Pi version..."
if [ $rpirunningon -eq 1 ]; then
# Running on a Pi or Pi 2 during autodetect
echo "The the cpu of this Raspberry Pi is:"
echo ""
if [ `cat /proc/cpuinfo | grep ARMv6 |wc -c` -eq 0 ]; then
echo "BCM2836 ARMv7 Raspberry Pi 2"
rpiversion="armv7h"
else
rpiversion="unknown"
fi
if [ `cat /proc/cpuinfo | grep ARMv7 |wc -c` -eq 0 ]; then
echo "BCM2835 ARMv6 Raspberry Pi"
rpiversion="armv6h"
else
version="unknown"
fi
if [ "$rpiversion" = "unknown" ]; then
echo "Can't autodetect Raspberry Pi version while running on one."
echo "Choose rpiversionnumber=1 or rpiversionnumber=2 in configuration."
echo "Exiting."
echo ""
exit 1
fi
else
# Not running on Pi or Pi 2 during autodetect
echo ""
echo "Can't autodetect Raspberry Pi version when not running on one."
echo "Choose rpiversionnumber=1 or rpiversionnumber=2 in configuration."
echo "Exiting."
echo ""
exit 1
fi
# End of autodetect
else
echo "Not autodetecting Raspberry Pi version."
# End of no autodetect message
fi
if [ $rpiversionnumber -eq 1 ]; then
rpiversion="armv6h"
rpiversioncorrect=1
fi
if [ $rpiversionnumber -eq 2 ]; then
rpiversion="armv7h"
rpiversioncorrect=1
fi
if [ $rpiversioncorrect -eq 0 ]; then
# Incorrect rpiversionnumber
echo "Chosen rpiversionnumber is not 0 1 or 2."
echo "Choose rpiversionnumber=1 or rpiversionnumber=2 in configuration."
echo "Exiting."
echo ""
exit 1
fi
# End of selecting version
echo ""
echo "Selected Arch architecture is:"
echo ""
echo ""
echo $rpiversion
echo ""
echo ""
echo "============================================================"
echo ""
sleep 2
# Allowing dd to be able to clear MBR (permission)
viewsudouser=`logname`
viewroot=""
# A string echo "" is seen by wc as having 1 character so n+1, and a failed grep has a wc of 0
if [ `echo $viewsudouser | grep "root" |wc -c` != 0 ] && [ `echo $viewsudouser |wc -c` = 5 ]; then
viewroot="root"
fi
# On Arch a no login name gives a wc of 1
if [ `echo $viewsudouser |wc -c` = 1 ]; then
viewroot="root"
fi
# On other systems no login name maybe gives no login name
if [ `echo $viewsudouser | grep "no login name" |wc -c` != 0 ]; then
viewroot="root"
fi
if [ `echo $viewroot |wc -c` != 1 ]; then
echo ""
echo "Only root."
echo "Adding root to the disk group."
echo""
usermod -G disk --append root
else
echo ""
echo "Sudo is used by a user named $viewsudouser."
echo "Adding user named $viewsudouser to the disk group."
echo ""
usermod -G disk --append $viewsudouser
fi
echo ""
echo "Checking for programs that are needed:"
echo ""
# If on Arch this commands install them
pacman -Syu --noconfirm
sleep 2
pacman -S --noconfirm --needed base-devel dosfstools wget libarchive
sleep 2
sync
# On other distributions the user installs them
neededprograms=""
if [ `which fdisk |wc -c` != 0 ]; then
echo "Found fdisk."
else
neededprograms+="fdisk "
fi
if [ `which mkfs.vfat |wc -c` != 0 ]; then
echo "Found mkfs.vfat."
else
neededprograms+="mkfs.vfat "
fi
if [ `which wget |wc -c` != 0 ]; then
echo "Found wget."
else
neededprograms+="wget "
fi
if [ `which bsdtar |wc -c` != 0 ]; then
echo "Found bsdtar."
else
neededprograms+="bsdtar "
fi
echo ""
if [ "$neededprograms" = "" ]; then
echo "All needed programs available."
else
echo "Missing needed programs, install them:"
echo ""
echo $neededprograms
echo ""
echo "On Arch fdisk is in util-linux which is in base-devel."
echo ""
echo "On Arch mkfs.vfat is in dosfstools and bsdtar is in libarchive."
echo ""
echo "Exiting."
echo ""
exit 1
fi
# Detecting availability of indicated device
if ! (fdisk -l | grep $sdcardforarch); then
echo "Can't find ($sdcardforarch). Insert and indicate it."
echo "No files. Only devices. Exiting."
echo ""
exit 1
else
echo "Found indicated device $sdcardforarch."
echo ""
fi
echo ""
echo "============================================================"
echo ""
sleep 2
# Safety unmounting of possible partitions, logicals can start from 5
echo "Unmounting partitions, up to 9, with or without p in front:"
echo ""
umount "$sdcardforarch"1
umount "$sdcardforarch"2
umount "$sdcardforarch"3
umount "$sdcardforarch"4
umount "$sdcardforarch"5
umount "$sdcardforarch"6
umount "$sdcardforarch"7
umount "$sdcardforarch"8
umount "$sdcardforarch"9
umount "$sdcardforarch"p1
umount "$sdcardforarch"p2
umount "$sdcardforarch"p3
umount "$sdcardforarch"p4
umount "$sdcardforarch"p5
umount "$sdcardforarch"p6
umount "$sdcardforarch"p7
umount "$sdcardforarch"p8
umount "$sdcardforarch"p9
swapoff "$sdcardforarch"1
swapoff "$sdcardforarch"2
swapoff "$sdcardforarch"3
swapoff "$sdcardforarch"4
swapoff "$sdcardforarch"5
swapoff "$sdcardforarch"6
swapoff "$sdcardforarch"7
swapoff "$sdcardforarch"8
swapoff "$sdcardforarch"9
swapoff "$sdcardforarch"p1
swapoff "$sdcardforarch"p2
swapoff "$sdcardforarch"p3
swapoff "$sdcardforarch"p4
swapoff "$sdcardforarch"p5
swapoff "$sdcardforarch"p6
swapoff "$sdcardforarch"p7
swapoff "$sdcardforarch"p8
swapoff "$sdcardforarch"p9
echo ""
sleep 5
echo ""
echo "Deleting MBR and fat allocation table general area with dd:"
# Need to dd more because fat filesystems may get confused about random
# data in their first part where they store the fat allocation table
dd if=/dev/zero of=$sdcardforarch bs=1M count=32 iflag=fullblock
echo ""
echo ""
echo "Partitioning indicated device:"
echo ""
# On fdisk older than 25, setting bootable flag adds 1 after a: "a,1" < 25, "a" >= 25
# But I follow the archlinuxarm instructions which don't set booteble flag
# "Fdisk area". Be careful about the new lines (Enter).
fdisk $sdcardforarch <<EOF
o
n
+140M
t
c
n
+512M
n
w
EOF
# Finished partitioning. Be careful about the new lines (Enter).
sleep 5
echo ""
echo "=================================================="
echo ""
echo ""
echo "Detecting if the device is seen as a mmcblk so that partitions have a p in front"
echo ""
if [ `echo $sdcardforarch | grep mmcblk |wc -c` != 0 ]; then
echo ""
echo "Partition numbers have a p in front of them..."
bootpart="$sdcardforarch"p1
swappart="$sdcardforarch"p2
rootpart="$sdcardforarch"p3
else
echo ""
echo "Partition numbers don't have a p in front of them..."
bootpart="$sdcardforarch"1
swappart="$sdcardforarch"2
rootpart="$sdcardforarch"3
fi
echo ""
echo -n "Boot partition is "
echo $bootpart
echo -n "Swap partition is "
echo $swappart
echo -n "Root partition is "
echo $rootpart
echo ""
echo ""
echo "Formatting partitions:"
echo ""
mkfs.vfat -n BOOTRPI $bootpart
mkswap $swappart
# Disabling lazy options so that all inodes get written now not bit by bit later.
mke2fs -t ext4 -m 0 -F -O ^64bit -L ARCHRPI -E lazy_itable_init=0,lazy_journal_init=0 $rootpart
echo ""
echo "Mounting partitions:"
echo ""
mkdir sdcardforarch
mount $rootpart sdcardforarch
mkdir sdcardforarch/boot
mount $bootpart sdcardforarch/boot
echo ""
echo "=================================================="
echo ""
sleep 2
sync
sleep 2
echo "Downloading Arch image with wget:"
echo ""
echo ""
if [ "$rpiversion" = "armv6h" ]; then
# The nl mirror is faster but does not have os/
wget -c http://de4.mirror.archlinuxarm.org/os/ArchLinuxARM-rpi-latest.tar.gz
echo "Unpacking Arch image into the root partition with bsdtar... wait... (armv6h)"
bsdtar -xpf ArchLinuxARM-rpi-latest.tar.gz -C sdcardforarch
fi
if [ "$rpiversion" = "armv7h" ]; then
# The nl mirror is faster but does not have os/
wget -c http://de4.mirror.archlinuxarm.org/os/ArchLinuxARM-rpi-2-latest.tar.gz
echo "Unpacking Arch image into the root partition with bsdtar... wait... (armv7h)"
bsdtar -xpf ArchLinuxARM-rpi-2-latest.tar.gz -C sdcardforarch
fi
sleep 2
sync
sleep 2
echo ""
echo "Detecting exact names for ppp package and it's dependencies:"
echo ""
# The version of a package changes the link when updated to a mirror
# To have the links we need to know their current version
# If you don't have ppp you can't connect to internet if you don't have router and it's pppoe
# Belive me, no internet is a disaster, pacman needs it's mirrors. This is the solution.
# No pacstrap - raspbian would need too many configuration changes and would be crippled (if errors).
# "ppp" depends on "libpcap" which depends on "libnl" which then has all it needs from root.
# So the install order needs to be: libnl -> libpcap -> ppp
# Offline install is done later one by one by script with pacman -U package
coredblink=http://de7.mirror.archlinuxarm.org/"$rpiversion"/core/core.db.tar.gz
wget $coredblink
mkdir archcoredbextract
bsdtar -xpf core.db.tar.gz -C archcoredbextract
namelibnl=`ls archcoredbextract | grep libnl`
namelibpcap=`ls archcoredbextract | grep libpcap`
nameppp=`ls archcoredbextract | grep ppp`
echo $namelibnl
echo $namelibpcap
echo $nameppp
#And the links are:
linklibnl=http://de7.mirror.archlinuxarm.org/"$rpiversion"/core/"$namelibnl"-"$rpiversion".pkg.tar.xz
linklibpcap=http://de7.mirror.archlinuxarm.org/"$rpiversion"/core/"$namelibpcap"-"$rpiversion".pkg.tar.xz
linkppp=http://de7.mirror.archlinuxarm.org/"$rpiversion"/core/"$nameppp"-"$rpiversion".pkg.tar.xz
echo ""
echo "Downloading the packages into the installed /root dir:"
######Directory changing beginning
mkdir sdcardforarch/root
cd sdcardforarch/root
wget -c $linklibnl
wget -c $linklibpcap
wget -c $linkppp
echo ""
echo "Generating install scripts install* to run after login:"
#Back to the names now... adding the -armv7h.pkg.tar.xz though
# ... for #!/bin/bash if I put "" gives me an error because of the !
if [ $enablepppoe -eq 1 ]; then
echo '#!/bin/bash' > install1ppp.sh
cat <<EOF >> install1ppp.sh
echo ""
echo "Installing ppp..."
echo ""
sleep 2
sync
sleep 2
pacman -U --noconfirm --needed $namelibnl-$rpiversion.pkg.tar.xz
pacman -U --noconfirm --needed $namelibpcap-$rpiversion.pkg.tar.xz
pacman -U --noconfirm --needed $nameppp-$rpiversion.pkg.tar.xz
sleep 1
ln -s /etc/ppp/peers/$pppprovider /etc/ppp/peers/provider
sleep 1
cp /etc/ppp/pap-secrets.pacorig /etc/ppp/pap-secrets
cp /etc/ppp/chap-secrets.pacorig /etc/ppp/chap-secrets
sleep 2
sync
sleep 2
echo ""
echo "Stopping systemd messages that need to run systemctl daemon reload:"
echo ""
poff -a
# All of this is needed, including sleeps, to make systemd stop giving this messages
sleep 1
systemctl daemon-reload
sleep 5
sync
sleep 2
systemctl stop systemd-networkd
systemctl disable systemd-networkd
systemctl stop systemd-timesyncd
systemctl disable systemd-timesyncd
systemctl stop ppp@$pppprovider.service
systemctl disable ppp@$pppprovider.service
systemctl stop [email protected]
systemctl disable [email protected]
systemctl stop [email protected]
systemctl disable [email protected]
sleep 5
sync
sleep 2
systemctl daemon-reload
sleep 5
sync
sleep 2
systemctl enable systemd-networkd
systemctl start systemd-networkd
systemctl enable systemd-timesyncd
systemctl start systemd-timesyncd
systemctl enable [email protected]
systemctl start [email protected]
systemctl enable [email protected]
systemctl start [email protected]
systemctl enable ppp@$pppprovider.service
systemctl start ppp@$pppprovider.service
sleep 5
sync
sleep 2
systemctl daemon-reload
sleep 5
sync
sleep 2
poff -a
sleep 2
systemctl daemon-reload
sleep 5
sync
sleep 2
systemctl stop ppp@$pppprovider.service
systemctl disable ppp@$pppprovider.service
sleep 2
systemctl daemon-reload
sleep 5
sync
sleep 2
systemctl enable ppp@$pppprovider.service
systemctl start ppp@$pppprovider.service
sleep 5
sync
sleep 2
systemctl daemon-reload
sleep 3
sync
sleep 2
systemctl daemon-reload
sleep 5
sync
sleep 2
echo ""
echo "Completed installing ppp."
echo ""
echo "Internet is available if configuration is correct."
echo ""
echo "But if not paid in time or in a hotel it will be redirected by dns."
echo ""
echo "============================================================"
echo ""
echo "Running systemctl status ppp@$provider.service"
echo ""
systemctl status ppp@$pppprovider.service
sleep 2
systemctl daemon-reload
sleep 5
sync
sleep 2
systemctl daemon-reload
sleep 5
sync
sleep 2
echo ""
echo "If warning is in the middle then incorrect configuration of user and password."
echo ""
echo "If warning is last then the network cable is disconnected or not well inserted."
echo ""
echo "Repeat this script until no more warnings appear in systemctl status."
sleep 2
sync
EOF
chmod a+x install1ppp.sh
fi
# ... for #!/bin/bash if I put "" gives me an error because of the !
echo '#!/bin/bash' > install2upgrade.sh
cat <<EOF >> install2upgrade.sh
echo ""
echo "Upgrading system... if redirected error 404 will appear..."
echo ""
sync
sleep 2
pacman -Syu --noconfirm
sleep 2
echo ""
echo "Completed upgrading system."
echo ""
echo "Rebooting so that all upgrades run in the memory too."
echo ""
sync
sleep 2
sync
sleep 8
reboot
EOF
chmod a+x install2upgrade.sh
# ... for #!/bin/bash if I put "" gives me an error because of the !
echo '#!/bin/bash' > install3console.sh
cat <<EOF >> install3console.sh
echo ""
# Making sure package lists are up to date right now
pacman -Syu --noconfirm
sleep 2
# Packages only for the Raspberry Pi or ArchLinuxARM (comment if installing on something else)
pacman -S --noconfirm --needed libbcm2835 xf86-video-fbturbo-git kodi-rbp omxplayer packer
# Console packages - fdisk is in util-linux which is in base-devel
pacman -S --noconfirm --needed base base-devel arch-install-scripts dosfstools ddrescue mtools libarchive pkgfile iotop gptfdisk parted mkinitcpio mkinitcpio-busybox upower mc libnewt newt-syrup openssh openssl wiringpi espeak mpg123 flac lame youtube-dl imagemagick git wget libx264 mediainfo ncdu vorbis-tools elinks
sleep 2
echo "Configuring boot and /etc/fstab to use UUID for partitions."
echo ""
# The UUID is determined in rpiarchppp as sed can't execute or show variable
sed -i 's/\/dev\/mmcblk0p3/UUID=`blkid -s UUID -o value $rootpart`/g' /boot/cmdline.txt
sed -i 's/rootwait/rootwait initrd=0x01f00000/g' /boot/cmdline.txt
echo "initramfs initrd 0x01f00000" >> /boot/config.txt
genfstab -U / > /etc/fstab
echo ""
echo "Making an initramfs giving the kernel the ability to boot by UUID."
echo ""
echo "This is done automatically for every kernel update."
echo ""
sed -i 's/ block / /g' /etc/mkinitcpio.conf
sed -i 's/udev/udev block/g' /etc/mkinitcpio.conf
sleep 2
sync
sleep 2
mkinitcpio -k \$(uname -r) -g /boot/initrd
sleep 2
sync
sleep 2
# Hack to allow mc to open videos with omxplayer
cp /usr/lib/mc/ext.d/video.sh /usr/lib/mc/ext.d/video.sh.old
echo '#!/bin/sh' > /usr/lib/mc/ext.d/video.sh
echo "omxplayer \"\\\${MC_EXT_FILENAME}\"" >> /usr/lib/mc/ext.d/video.sh
echo ""
echo "Added mc option to open all videos with omxplayer."
echo ""
pkgfile --update
sleep 2
# Omxplayer available as oi for all users
ln -s /usr/bin/omxplayer /usr/bin/oi
# Root aliases, used only by root
cp /root/.bash_profile /root/.bash_profile.old
echo "[[ -f ~/.bashrc ]] && . ~/.bashrc" > /root/.bash_profile
echo 'alias pk="TMPDIR=/root/tmp/pkgs/ EDITOR=nano packer"' >> /root/.bashrc
echo 'alias yt="youtube-dl -f mp4/best"' >> /root/.bashrc
. ~/.bashrc
echo ""
echo "Added link oi -> omxplayer and root aliases yt -> youtube-dl and pk -> packer."
echo ""
echo "Rebooting to have initrd loaded."
sleep 2
sync
sleep 8
reboot
EOF
chmod a+x install3console.sh
echo '#!/bin/bash' > install4autologinroot.sh
cat <<EOF >> install4autologinroot.sh
echo ""
echo "Activating autologin root... not recomended but maybe cool..."
echo ""
echo "If you want to keep ssh and have a user, stop this script with (ctrl + c)"
echo ""
sleep 3
echo "5"
echo ""
sleep 2
echo "4"
echo ""
sleep 2
echo "3"
echo ""
sleep 2
echo "2"
echo ""
sleep 2
echo "1"
echo ""
sleep 5
echo "Too late..."
echo ""
sync
sleep 1
systemctl stop sshd.service
systemctl disable sshd.service
echo ""
echo "Wait..."
sleep 1
sync
sleep 1
systemctl daemon-reload
sleep 5
sync
sleep 3
rm /etc/systemd/system/getty.target.wants/[email protected]
cp /lib/systemd/system/[email protected] /etc/systemd/system/[email protected]
sed -i 's/--noclear/--autologin root --noclear/g' /etc/systemd/system/[email protected]
echo ";[email protected]" >> /etc/systemd/system/[email protected]
ln -s /etc/systemd/system/[email protected] /etc/systemd/system/getty.target.wants/[email protected]
sleep 1
echo ""
echo "Hack for autologing into root console and disabling ssh activated."
echo ""
echo "If you want to build packages, it's hard to be root, you need to:"
echo ""
echo "1) Edit /usr/bin/makepkg"
echo ""
echo " a) Add 'asroot' in OPT_LONG=()"
echo " b) Comment and add a sleep 1 inside if (( EUID == 0 ))"
echo ""
echo "2) Use packer to install packages from aur"
echo ""
echo "To avoid tmpfs for /tmp used by packer (large git repositories)"
echo 'alias packer="TMPDIR=/root/tmp/pkgs/ EDITOR=nano /usr/bin/packer"'
echo "Use the alias packer in .bashrc."
echo ""
sleep 2
sync
sleep 2
EOF
chmod a+x install4autologinroot.sh
# ... for #!/bin/bash if I put "" gives me an error because of the !
echo '#!/bin/bash' > install5moverootusb.sh
cat <<EOF >> install5moverootusb.sh
drivetomoverootto=/dev/sdwhat
echo ""
echo ""
echo "After running install3console.sh, the kernel is able to boot by UUID."
echo ""
echo "Arch needs to update hundreds of megabytes of packages every week."
echo ""
echo "As sdcard is very slow, each update lasts a very long time."
echo ""
echo "A solution is to move the / (root) partition to an external usb drive."
echo ""
echo "External rotating harddisk or ssd hardisk is faster than a usb stick."
echo ""
if [ \`echo \$drivetomoverootto | grep sdwhat |wc -c\` -eq 0 ]; then
echo "The drive to move root to is \$drivetomoverootto."
else
lsblk
echo ""
echo "Specify the drive by editing the beginning of this script."
echo ""
exit 1
fi
echo ""
echo "If you want to keep / (root) on sdcard, stop this script with (ctrl + c)"
echo ""
echo "DON'T WANT \$drivetomoverootto TO BE DESTROYED NOW, stop this script with (ctrl + c)"
echo ""
sleep 3
echo "10"
sleep 1
echo "9"
sleep 1
echo "8"
sleep 1
echo "7"
sleep 1
echo "6"
sleep 1
echo ""
echo "DON'T WANT \$drivetomoverootto TO BE DESTROYED NOW, stop this script with (ctrl + c)"
echo ""
echo "5"
sleep 1
echo "4"
sleep 1
echo "3"
sleep 1
echo "2"
sleep 1
echo "1"
sleep 2
echo "Too late..."
echo ""
sleep 2
sync
sleep 2
# Detecting availability of indicated device to move root to
if ! (fdisk -l | grep \$drivetomoverootto); then
echo "Can't find (\$drivetomoverootto). Insert and indicate it."
echo "No files. Only devices. Exiting."
echo ""
exit 1
else
echo "Found device \$drivetomoverootto."
echo ""
fi
echo ""
echo "============================================================"
echo ""
umount newrootforarch
rm -rf newrootforarch
sleep 2
sync
sleep 2
# Safety unmounting of possible partitions, logicals can start from 5
echo "Unmounting partitions, up to 9, with or without p in front:"
echo ""
umount "\$drivetomoverootto"1
umount "\$drivetomoverootto"2
umount "\$drivetomoverootto"3
umount "\$drivetomoverootto"4
umount "\$drivetomoverootto"5
umount "\$drivetomoverootto"6
umount "\$drivetomoverootto"7
umount "\$drivetomoverootto"8
umount "\$drivetomoverootto"9
umount "\$drivetomoverootto"p1
umount "\$drivetomoverootto"p2
umount "\$drivetomoverootto"p3
umount "\$drivetomoverootto"p4
umount "\$drivetomoverootto"p5
umount "\$drivetomoverootto"p6
umount "\$drivetomoverootto"p7
umount "\$drivetomoverootto"p8
umount "\$drivetomoverootto"p9
swapoff "\$drivetomoverootto"1
swapoff "\$drivetomoverootto"2
swapoff "\$drivetomoverootto"3
swapoff "\$drivetomoverootto"4
swapoff "\$drivetomoverootto"5
swapoff "\$drivetomoverootto"6
swapoff "\$drivetomoverootto"7
swapoff "\$drivetomoverootto"8
swapoff "\$drivetomoverootto"9
swapoff "\$drivetomoverootto"p1
swapoff "\$drivetomoverootto"p2
swapoff "\$drivetomoverootto"p3
swapoff "\$drivetomoverootto"p4
swapoff "\$drivetomoverootto"p5
swapoff "\$drivetomoverootto"p6
swapoff "\$drivetomoverootto"p7
swapoff "\$drivetomoverootto"p8
swapoff "\$drivetomoverootto"p9
echo ""
sleep 3
echo ""
echo "Deleting MBR and fat allocation table general area with dd:"
# Need to dd more because fat filesystems may get confused about random
# data in their first part where they store the fat allocation table
dd if=/dev/zero of=\$drivetomoverootto bs=1M count=32 iflag=fullblock
echo ""
echo ""
echo "Partitioning indicated device to move root to:"
echo ""
# On fdisk older than 25, setting bootable flag adds 1 after a: "a,1" < 25, "a" >= 25
# But I follow the archlinuxarm instructions which don't set booteble flag
# "Fdisk area". Be careful about the new lines (Enter).
fdisk \$drivetomoverootto <<EOG
o
n
+2048M
n
w
EOG
# Finished partitioning. Be careful about the new lines (Enter).
sleep 5
echo ""
echo "=================================================="
echo ""
echo ""
echo "Detecting if the device is seen as a mmcblk so that partitions have a p in front"
echo ""
if [ \`echo \$drivetomoverootto | grep mmcblk |wc -c\` != 0 ]; then
echo ""
echo "Partition numbers have a p in front of them..."
moveswapto="\$drivetomoverootto"p1
moverootto="\$drivetomoverootto"p2
else
echo ""
echo "Partition numbers don't have a p in front of them..."
moveswapto="\$drivetomoverootto"1
moverootto="\$drivetomoverootto"2
fi
echo ""
echo -n "New swap partition is:"
echo \$moveswapto
echo ""
echo -n "New root partition is:"
echo \$moverootto
echo ""
echo ""
echo "Formatting partitions:"
echo ""
mkswap \$moveswapto
# Disabling lazy options so that all inodes get written now not bit by bit later.
mke2fs -t ext4 -m 0 -F -O ^64bit -L ARCHRPIROOT -E lazy_itable_init=0,lazy_journal_init=0 \$moverootto
echo ""
echo "Mounting partitions:"
echo ""
mkdir newrootforarch
mount \$moverootto newrootforarch
echo ""
echo "=================================================="
echo ""
sleep 2
echo ""
echo "Copying root to new location, wait..."
echo ""
sync
sleep 2
sync
sleep 2
cp -ax / newrootforarch
sync
sleep 2
sync
sleep 2
# /boot in new root needs to be empty, as it is a mount point
rm -rf newrootforarch/boot/*
# Configuring /etc/fstab in new root
cp /boot/cmdline.txt /boot/cmdline.oldroot
echo "sed -i 's/UUID=\`blkid -s UUID -o value \/dev\/mmcblk0p2\`/UUID=\`blkid -s UUID -o value $moveswapto\`/g' newrootforarch/etc/fstab" > sedtempfilefstabconf.sh
echo "sed -i 's/UUID=\`blkid -s UUID -o value \/dev\/mmcblk0p3\`/UUID=\`blkid -s UUID -o value $moverootto\`/g' /boot/cmdline.txt" >> sedtempfilefstabconf.sh
echo "sed -i 's/UUID=\`blkid -s UUID -o value \/dev\/mmcblk0p3\`/UUID=\`blkid -s UUID -o value $moverootto\`/g' newrootforarch/etc/fstab" >> sedtempfilefstabconf.sh
echo ""
sleep 2
sync
sleep 2
sh sedtempfilefstabconf.sh
echo ""
sync
sleep 2
echo "Backup of /boot for this moment in time, the kernel"
echo ""
echo "modules in this old root are for the same version."
echo ""
mkdir /oldboot
mkdir newrootforarch/oldboot
cp -r /boot/* /oldboot
cp -r /boot/* newrootforarch/oldboot
sleep 2
sync
sleep 2
umount newrootforarch
rm -rf newrootforarch
rm sedtempfilefstabconf.sh
sleep 2
sync
sleep 2
echo ""
echo "Restore old boot (old root becomes stable) with:"
echo "rm -rf /boot/* && cp -r -v /oldboot/* /boot"
echo ""
echo "Restore old root (unstable after kernel update) with:"
echo ""
echo "cp /boot/cmdline.oldroot /boot/cmdline.txt"
sleep 2
echo ""
echo "Rebooting so that the new usb root will be online."
echo ""
sleep 2
sync
sleep 8
EOF
chmod a+x install5moverootusb.sh
# ... for #!/bin/bash if I put "" gives me an error because of the !
echo '#!/bin/bash' > install6xorg.sh
# Having cat with EOF inside, it is needed to use something else like EOG
cat <<EOF >> install6xorg.sh
echo ""
echo "Installing xorg..."
echo ""
sleep 2
# Making sure package lists are up to date right now
pacman -Syu --noconfirm
sleep 2
# Sound packages
pacman -S --noconfirm --needed alsa-utils alsa-plugins pulseaudio pulseaudio-alsa paprefs pavucontrol timidity++ timidity-freepats
sleep 2
# Xorg packages
pacman -S --noconfirm --needed xorg-xinput unrar unzip zip unarj p7zip gzip bzip2 xarchiver mesa-libgl ttf-freefont ttf-dejavu xorg-server xorg-xinit libksane xsane-gimp inkscape phonon-qt4-gstreamer phonon-qt5-gstreamer gparted audacious gimp libreoffice-still jre8-openjdk jdk8-openjdk xsane xorg-xrefresh fltk openbox gvfs
sleep 2
# Graphic applications
pacman -S --noconfirm chromium firefox midori gpicview transmission-gtk mediainfo-gui xine-ui gnome-alsamixer file-roller audacious texlive-bin evince calligra
# Game packages
pacman -S --noconfirm --needed openra kobodeluxe klines fltk-games
sleep 2
sync
sleep 2
echo ""
sed -i 's/chromium %U/chromium --no-sandbox --user-data-dir \/var\/cache\/chromiumdir %U/g' /usr/share/applications/chromium.desktop
# Kodi leaves a blank screen when exiting, this hack fixes that
mkdir /usr/bin
mkdir /root/.kodi
mkdir /root/.kodi/temp/
echo '#!/bin/bash' > /usr/bin/kodiexitfixroot
echo '' >> /usr/bin/kodiexitfixroot
echo "if [[ \\\$(tail -1 /root/.kodi/temp/kodi.log | grep \"application stopped...\") ]]; then" >> /usr/bin/kodiexitfixroot
echo ' killall kodi.bin' >> /usr/bin/kodiexitfixroot
echo ' mv /root/.kodi/temp/kodi.log /root/.kodi/temp/kodi.old.log' >> /usr/bin/kodiexitfixroot
echo ' sleep 1 && chvt 2 && sleep 1 && chvt 1' >> /usr/bin/kodiexitfixroot
echo 'fi' >> /usr/bin/kodiexitfixroot
# check depmod is not replaced and repair it again if it has
echo 'if [[ \`cat /usr/bin/depmod |grep "mkinitcpio" |wc -c\` = 0 ]]; then' >> /usr/bin/kodiexitfixroot
# in case replacing is still in progress
echo ' sleep 2' >> /usr/bin/kodiexitfixroot
echo ' rename depmod depmodbin /usr/bin/depmod' >> /usr/bin/kodiexitfixroot
echo " echo '#!/bin/bash' > /usr/bin/depmod" >> /usr/bin/kodiexitfixroot
# checking if more parameters or not, when one, for sure it's kernel version, when more, depmodbin alone
echo " echo 'if [[ \\\`echo \\\$2 |wc -c\\\` != 1 ]]; then' >> /usr/bin/depmod" >> /usr/bin/kodiexitfixroot
echo ' echo " depmodbin \\\$1 \\\$2 \\\$3 \\\$4 \\\$5 \\\$6 \\\$7 \\\$8 \\\$9" >> /usr/bin/depmod' >> /usr/bin/kodiexitfixroot
echo ' echo "else" >> /usr/bin/depmod' >> /usr/bin/kodiexitfixroot
# Indicating new version instead of current version
echo ' echo " depmodbin \\\$1" >> /usr/bin/depmod' >> /usr/bin/kodiexitfixroot
echo ' echo " mkinitcpio -k \\\$1 -g /boot/initrd" >> /usr/bin/depmod' >> /usr/bin/kodiexitfixroot
echo ' echo "fi" >> /usr/bin/depmod' >> /usr/bin/kodiexitfixroot
echo ' echo "exit 0" >> /usr/bin/depmod' >> /usr/bin/kodiexitfixroot
echo ' chmod a+x /usr/bin/depmod' >> /usr/bin/kodiexitfixroot
echo 'fi' >> /usr/bin/kodiexitfixroot
echo "sed -i 's/chromium %U/chromium --no-sandbox --user-data-dir \\\/var\\\/cache\\\/chromiumdir %U/g' /usr/share/applications/chromium.desktop" >> /usr/bin/kodiexitfixroot
echo "exit 0" >> /usr/bin/kodiexitfixroot
chmod a+x /usr/bin/kodiexitfixroot
# Arch uses systemd timers not cron by default
cat <<EOG > /etc/systemd/system/kodiexitfixroot.timer
[Unit]
Description=kodiexitfixroot timer
[Timer]
# Every 10 seconds
OnCalendar=*-*-* *:*:0/10
Unit=kodiexitfixroot.service
[Install]
WantedBy=timers.target
EOG
cat <<EOG > /etc/systemd/system/kodiexitfixroot.service
[Unit]
Description=kodiexitfixroot service
[Service]
Type=oneshot
ExecStart=/bin/bash /usr/bin/kodiexitfixroot
EOG
sleep 1
systemctl daemon-reload
sleep 3
systemctl enable kodiexitfixroot.timer
systemctl start kodiexitfixroot.timer
sleep 2
sync
sleep 2
# Disable automatic smart testing because hdds are slower for five minutes after each detection: