]> git.ipfire.org Git - ipfire-2.x.git/blame - src/initscripts/system/partresize
suricata: Change midstream policy to "pass-flow"
[ipfire-2.x.git] / src / initscripts / system / partresize
CommitLineData
a6d0d790 1#!/bin/sh
66c36198
PM
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
946a27a2 5# Copyright (C) 2007-2023 IPFire Team <info@ipfire.org> #
66c36198
PM
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
a6d0d790
AF
21
22. /etc/sysconfig/rc
23. ${rc_functions}
24
25case "${1}" in
26 start)
a2454679 27 if [ -e "/.partresize" ]; then
6b566244 28
a2454679
MT
29 boot_mesg "Mounting root file system in read/write mode ..."
30 mount -o remount,rw / > /dev/null
31 evaluate_retval
a6d0d790 32
8f49959d
AF
33 # check if serial console enabled
34 scon="off";
35 if [ ! "$(grep "console=ttyS0" /proc/cmdline)" == "" ]; then
36 scon="on";
37 fi
99f2c695
AF
38 if [ -e /sys/class/dmi/id/product_name ]; then
39 IFS= read -r DMI_PRODUCT_NAME < /sys/class/dmi/id/product_name;
40 case ${DMI_PRODUCT_NAME} in
41 APU|apu[1-4]|PC\ Engines\ apu[1-4] )
42 scon="on";
43 ;;
44 esac
45 fi
8f49959d 46
a09578f4
MT
47 # Enable the serial console on all systems on AWS EC2, Oracle Cloud,
48 # Azure and Google Compute Platform
49 if running_on_ec2 || running_on_oci || running_on_azure || running_on_gcp; then
bc503715 50 scon="on"
f24ce455 51 journal="on"
bc503715
MT
52 fi
53
75c9d8c2 54 mount /boot > /dev/null
fa5e921c 55 case "$(< /proc/device-tree/model )" in
2f3af8c0 56 FriendlyElec\ NanoPi?R1* )
75c9d8c2 57 # Install AP6112 wlan config on NanoPi R1
fa5e921c
AF
58 cp -f /lib/firmware/brcm/brcmfmac43430-sdio.AP6212.txt \
59 /lib/firmware/brcm/brcmfmac43430-sdio.txt
97f4b514
AF
60 cp -f /lib/firmware/brcm/brcmfmac43430a0-sdio.ONDA-V80_PLUS.txt \
61 /lib/firmware/brcm/brcmfmac43430a0-sdio.txt
fa5e921c 62 ;;
2f3af8c0 63 FriendlyElec\ NanoPi?R2* )
75c9d8c2
AF
64 # Generate MAC address at first boot
65 SWMAC=`printf "%1x2:%02x:%02x:%02x:%02x" $[RANDOM%16] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256]`
66 echo ethaddr=$SWMAC:00 >> /boot/uEnv.txt
67 echo eth1addr=$SWMAC:01 >> /boot/uEnv.txt
68 ;;
2f3af8c0 69 FriendlyElec\ NanoPi?R4* )
75c9d8c2
AF
70 # Generate MAC address at first boot
71 SWMAC=`printf "%1x2:%02x:%02x:%02x:%02x" $[RANDOM%16] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256]`
72 echo ethaddr=$SWMAC:00 >> /boot/uEnv.txt
73 echo eth1addr=$SWMAC:01 >> /boot/uEnv.txt
74 ;;
946a27a2
AF
75 Xunlong\ Orange\ Pi\ R1\ Plus* )
76 # Generate MAC address at first boot
77 # This board should have mac addresses in rom but uboot
78 # doesnt set it for fist nic
79 SWMAC=`printf "%1x2:%02x:%02x:%02x:%02x" $[RANDOM%16] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256]`
80 echo ethaddr=$SWMAC:00 >> /boot/uEnv.txt
81 echo eth1addr=$SWMAC:01 >> /boot/uEnv.txt
82 ;;
fa5e921c
AF
83 esac 2>/dev/null
84
6b566244
AF
85 if [ -e /boot/grub/grub.cfg ]; then
86 # swtich permanent to serial console if it was selected on first boot
8f49959d 87 if [ "${scon}" = "on" ]; then
6b566244
AF
88 # Enable also serial console on GRUB
89 echo "GRUB_TERMINAL=\"serial console\"" >> /etc/default/grub
90 echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> /etc/default/grub
91 sed -i -e "s|panic=10|& console=ttyS0,115200n8|g" /etc/default/grub
92 fi
43829df3
MT
93
94 # Re-generate GRUB configuration
95 /usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg
6b566244
AF
96 fi
97 umount /boot > /dev/null
98
a2454679 99 # Detect device
c0504c5c 100 mount | while read -r dev tmp1 mountpoint tmp2; do
a2454679
MT
101 [ "${dev}" = "rootfs" ] && continue
102
103 if [ "${mountpoint}" = "/" ]; then
104 # Find root partition number
105 part_num="${dev: -1}"
a6d0d790 106
a2454679
MT
107 # Find path to the root device
108 root_dev="${dev::-1}"
109 if [ ! -b "${dev::-1}" -a "${root_dev: -1}" = "p" ]; then
110 root_dev="${dev::-2}"
111 fi
6450609d 112
f24ce455
AF
113 # Check if the device support smart
114 smartctl --smart=on "${root_dev}" > /dev/null
115 if [ ${?} = 0 ]; then
116 journal="on"
117 fi
118
119 # Enable journal
120 if [ "${journal}" = "on" ]; then
121 boot_mesg "Create journal on "${dev}" ..."
122 tune2fs -O has_journal "${dev}"
123 fi
124
a2454679
MT
125 boot_mesg "Growing root partition to maximum size..."
126 echo -e ',+' | sfdisk --no-reread -f -N${part_num} "${root_dev}" 2>/dev/null
a6d0d790 127
a2454679
MT
128 # The filesystem should be resized after
129 # this operation
130 touch /.resizefs
a6d0d790 131
a2454679
MT
132 # Remove marker
133 rm -f /.partresize
134
135 # Reboot
136 boot_mesg "Rebooting system..."
137 mount -o remount,ro / &>/dev/null
138 sleep 15
139 reboot -f
140 fi
c0504c5c 141 done
a2454679 142 fi
a6d0d790
AF
143 ;;
144 *)
145 echo "Usage: ${0} {start}"
146 exit 1
147 ;;
148esac