initial version of membership card creation script
[fsf-member-card-builder.git] / live-usb-loader.sh
CommitLineData
25b16ae2
AE
1#!/bin/bash
2#
3# Copyright (C) 2012-2020 Ruben Rodriguez <ruben@trisquel.info>
4# Copyright (C) 2020 Andrew Engelbrecht <andrew@fsf.org>
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19#
20
21set -e
22
23usage(){
24echo You need to run this script as root
25echo Usage: sudo $0 distro.iso /dev/sdX
26echo Example: sudo $0 foobar_5.0_i386.iso /dev/sdb
27echo
28echo WARNING!: this script will delete all data on the whole disk you pass as the second parameter. Make sure it is your USB drive and not your internal hard drive!
29echo ANOTHER WARNING!: This script can bite your dog. Use it with care, backup your data.
30exit 1
31}
32
33[ $(id -u) != 0 ] && usage
34[ $# != 2 ] && usage
35
36ISO=$1
37DEV=$2
38PERSISTENCESIZE=4096 # Size of the persistence file, in MB
39
40ISOTMP=$(mktemp -d)
41DEVTMP=$(mktemp -d)
42
43umount $DEV* || true
44mount -o loop $ISO $ISOTMP
45
46# Create FAT32 LBA partition taking all disk
47echo 'start=2048, type=c' | sfdisk $DEV
48mkfs.vfat -I -F32 ${DEV}1 -n FSF-LIVE
49
50# Copy the data
51mount ${DEV}1 $DEVTMP
52cp -vr $ISOTMP/* $ISOTMP/.disk $DEVTMP || true
53
54cp -vr $DEVTMP/isolinux $DEVTMP/syslinux
55mv $DEVTMP/syslinux/isolinux.cfg $DEVTMP/syslinux/syslinux.cfg
56
57# Create persistency file
58# dd if=/dev/zero of=$DEVTMP/casper-rw bs=1M count=$PERSISTENCESIZE oflag=sync status=progress
59# mkfs.ext4 -L casper-rw -F $DEVTMP/casper-rw
60# sed -i 's/noprompt --/noprompt persistent --/' $DEVTMP/syslinux/txt.cfg $DEVTMP/isolinux/txt.cfg
61
62umount $DEVTMP
63umount $ISOTMP
64
65rmdir $DEVTMP
66rmdir $ISOTMP
67
68# Set up bootloader, requires syslinux 4x
69# https://mirror.fsf.org/trisquel/pool/main/s/syslinux/syslinux-common_4.05+dfsg-6+deb8u1_all.deb
70# https://mirror.fsf.org/trisquel/pool/main/s/syslinux/syslinux_4.05+dfsg-6+deb8u1_amd64.deb
71syslinux ${DEV}1
72dd conv=notrunc if=/usr/lib/syslinux/mbr.bin bs=440 count=1 of=$DEV
73parted $DEV set 1 boot on
74
75eject $DEV
76sync
77