2cdef0094a74bc81546282a98b8ffee23dded1e5
[people/pmueller/ipfire-2.x.git] / src / scripts / backupiso
1 #!/bin/sh
2 arch=$(uname -m)
3
4 makeiso() {
5         local dir="${1}"
6         local output="${2}"
7
8         local args="-J -r -V 'ipfire backup ${TS}' \
9                 -b boot/isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table \
10                 -c boot/isolinux/boot.catalog"
11
12         # Add EFI options when EFI image is present
13         if [ -e "${dir}/boot/isolinux/efiboot.img" ]; then
14                 args="${args} -eltorito-alt-boot -e boot/isolinux/efiboot.img -no-emul-boot"
15         fi
16
17         # Compose ISO
18         mkisofs ${args} ${dir} > ${output}
19
20         # Add DOS paritition table
21         if [ -e "${dir}/boot/isolinux/efiboot.img" ]; then
22                 isohybrid --uefi ${output}
23         else
24                 isohybrid ${output}
25         fi
26
27         return 0
28 }
29
30 case $arch in
31         i?86)
32                 arch="i586"
33                 echo "Your arch is $arch"
34                 ;;
35         x86_64)
36                 arch="x86_64"
37                 echo "Your arch is $arch"
38                 ;;
39         *)
40                 echo "Arch is not supported"
41                 exit 1
42                 ;;
43 esac
44
45 COREVER=$(cat /opt/pakfire/db/core/mine)
46 # FIXME: edit this lines before release
47 URL="https://downloads.ipfire.org/releases/ipfire-2.x/2.21-core$COREVER/"
48 ISO="ipfire-2.21.$arch-full-core$COREVER.iso"
49
50 if [ -z $1 ]; then
51         echo usage: $0 backup-file
52         exit
53 fi
54
55 TS=$1
56
57 mkdir -p /var/tmp/backupiso
58 cd /var/tmp/backupiso
59
60 if [ ! -f ${ISO} ]
61 then
62         echo "Fetching ${URL}${ISO}"
63         wget --quiet -c ${URL}${ISO}
64 fi
65
66 echo "Fetching ${URL}${ISO}.md5"
67 wget --quiet -O ${ISO}.md5 ${URL}${ISO}.md5
68
69 echo "Checking md5 of ${ISO}"
70 md5sum --status -c ${ISO}.md5
71 if [ $? -eq 0 ] || [ $? -eq 24 ]
72 then
73         echo "md5 is OK"
74 else
75         echo "md5 mismatch"
76         echo "Fetching again ${URL}${ISO}"
77         wget --quiet -O ${ISO} ${URL}${ISO}
78         echo "Checking again md5 of ${ISO}"
79         md5sum --status -c ${ISO}.md5
80         if [ $? -eq 0 ] || [ $? -eq 24 ]
81         then
82                 echo "md5 is OK"
83         else
84                 echo "md5 mismatch"
85                 echo "aborting backup because md5 mismatch"
86                 exit 1
87         fi
88 fi
89 rm ${ISO}.md5
90
91 echo "Remastering iso"
92 mkdir -p backupiso.tmp.${TS}
93 mount -o loop ${ISO} backupiso.tmp.${TS}
94 cp -pr backupiso.tmp.${TS} backupiso.${TS}
95 umount backupiso.tmp.${TS}
96 rm -r backupiso.tmp.${TS}
97
98 # Copy backup file to disk
99 cp "/var/ipfire/backup/${TS}.ipf" "backupiso.${TS}/backup.ipf"
100
101 echo "Running mkisofs"
102 makeiso backupiso.${TS} $(basename ${ISO} .iso)-${TS}.iso
103
104 echo "Cleaning up"
105 rm -rf backupiso.${TS}