]> git.ipfire.org Git - ipfire-2.x.git/blob - src/scripts/backupiso
suricata: Change midstream policy to "pass-flow"
[ipfire-2.x.git] / src / scripts / backupiso
1 #!/bin/sh
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
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 ###############################################################################
21
22 # FIXME: edit this lines before release
23 IPFVER=2.29
24 COREVER=$(cat /opt/pakfire/db/core/mine)
25
26 arch=$(uname -m)
27
28 case "${arch}" in
29 aarch64|x86_64)
30 ;;
31 *)
32 echo "Arch is not supported" >&2
33 exit 1
34 ;;
35 esac
36
37 URL="https://downloads.ipfire.org/releases/ipfire-2.x/$IPFVER-core$COREVER/"
38 ISO="ipfire-$IPFVER-core$COREVER-$arch.iso"
39
40 makeiso() {
41 local dir="${1}"
42 local output="${2}"
43
44 local args=
45
46 # Add EFI options when EFI image is present
47 if [ -e "${dir}/boot/isolinux/efiboot.img" ]; then
48 args="${args} -eltorito-alt-boot -e boot/isolinux/efiboot.img -no-emul-boot"
49 fi
50
51 # Compose ISO
52 mkisofs -J -r -V "IPFire ${IPFVER} ${arch}" \
53 -b boot/isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table \
54 -c boot/isolinux/boot.catalog \
55 ${args} ${dir} > ${output}
56
57 # Add DOS paritition table
58 if [ -e "${dir}/boot/isolinux/efiboot.img" ]; then
59 isohybrid --uefi ${output}
60 else
61 isohybrid ${output}
62 fi
63
64 return 0
65 }
66
67 if [ -z $1 ]; then
68 echo usage: $0 backup-file
69 exit
70 fi
71
72 TS=$1
73
74 mkdir -p /var/tmp/backupiso
75 cd /var/tmp/backupiso
76
77 if [ ! -f ${ISO} ]
78 then
79 echo "Fetching ${URL}${ISO}"
80 wget --quiet -c ${URL}${ISO}
81 fi
82
83 echo "Fetching ${URL}${ISO}.b2"
84 wget --quiet -O ${ISO}.b2 ${URL}${ISO}.b2
85
86 echo "Checking BLAKE2 checksum of ${ISO}"
87 b2sum --status -c ${ISO}.b2
88 if [ $? -eq 0 ] || [ $? -eq 24 ]
89 then
90 echo "BLAKE2 checksum is OK"
91 else
92 echo "BLAKE2 checksum mismatch"
93 echo "Fetching again ${URL}${ISO}"
94 wget --quiet -O ${ISO} ${URL}${ISO}
95 echo "Checking BLAKE2 checksum of ${ISO} again"
96 b2sum --status -c ${ISO}.b2
97 if [ $? -eq 0 ] || [ $? -eq 24 ]
98 then
99 echo "BLAKE2 checksum is OK"
100 else
101 echo "BLAKE2 checksum mismatch"
102 echo "aborting backup because BLAKE2 checksum mismatch"
103 exit 1
104 fi
105 fi
106 rm ${ISO}.b2
107
108 echo "Remastering iso"
109 mkdir -p backupiso.tmp.${TS}
110 mount -o loop ${ISO} backupiso.tmp.${TS}
111 cp -pr backupiso.tmp.${TS} backupiso.${TS}
112 umount backupiso.tmp.${TS}
113 rm -r backupiso.tmp.${TS}
114
115 # Copy backup file to disk
116 cp "/var/ipfire/backup/${TS}.ipf" "backupiso.${TS}/backup.ipf"
117
118 # Add a version tag
119 touch "backupiso.${TS}/backup-${TS}.media"
120
121 echo "Running mkisofs"
122 makeiso backupiso.${TS} $(basename ${ISO} .iso)-${TS}.iso
123
124 echo "Cleaning up"
125 rm -rf backupiso.${TS}