docs/gnulinux/encrypted_debian: don't tell the user to choose their own LV name
[libreboot.git] / download
1 #!/bin/bash
2
3 #  download script: Download the programs used in libreboot, that
4 #                   aren't distributed in the git repository.
5 #
6 #       Copyright (C) 2014, 2015 Leah Rowe <info@minifree.org>
7 #       Copyright (C) 2015 Klemens Nanni <contact@autoboot.org>
8 #
9 #    This program is free software: you can redistribute it and/or modify
10 #    it under the terms of the GNU General Public License as published by
11 #    the Free Software Foundation, either version 3 of the License, or
12 #    (at your option) any later version.
13 #
14 #    This program is distributed in the hope that it will be useful,
15 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 #    GNU General Public License for more details.
18 #
19 #    You should have received a copy of the GNU General Public License
20 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 #
22
23 [ "x${DEBUG+set}" = 'xset' ] && set -v
24 set -u -e
25
26 download="resources/scripts/helpers/download"
27
28 # echo "${programs##*/}" ; echo "${programs%/*}"
29 programs="$(for program in ${download}/*; do printf "%s\n" "${program##*/}"; done)"
30
31 noconfirm="0"
32
33 help () {
34         printf "%s\n\n" "./download program(s) # programs are space separated, if specifing multiple programs"
35         printf "possible values for 'programs':\nall:\n%s\n\n" "${programs}"
36         printf "Example (download everything): ./download all\n"
37         printf "Example (download flashrom): ./download flashrom\n"
38         printf "Example (download coreboot): ./download coreboot\n"
39         printf "Example (download coreboot and flashrom): ./download coreboot flashrom\n"
40         printf "Example (lists all available downloadable components): ./download list\n"
41 }
42
43 if [ $# -lt 1 ]; then
44         printf "ERROR: download script: no argument given.\n"
45         help
46         exit 1
47 fi
48
49 if [ "${1}" = "--noconfirm" ] || [ "${1}" = "-y" ]; then
50         noconfirm="1"
51         shift 1
52 fi
53
54 case "${1}" in
55         all)
56                 ;;
57         list)
58                 printf "possible values for 'programs':\nall\n%s\n\n" "${programs}"
59                 exit 
60                 ;;
61         help)
62                 help
63                 exit 
64                 ;;
65         *)
66                 for program in "${@}"; do
67                         printf "%s" "${programs}\n" | grep -wq "${program}" || (printf "ERROR: Invalid program '%s'. See ./download help.\n" "${program}"; exit 1)
68                 done
69                 programs="${*}"
70                 ;;
71 esac
72
73 for program in ${programs}; do
74
75         if [ "${noconfirm}" = "0" ]; then
76                 printf "Use \"./download --noconfirm\" or \"./download -y\" if you want to be rid of these confirmation dialogues.\n\n"
77                 if [ -d "${program}/" ]; then
78             if [ "${program}" = "seabios" ]; then
79                 # temporary hack. download grub also downloads seabios,
80                 # which breaks automated build when running ./download all
81                 # Later on, we'll delete the seabios download script
82                 # and grub download script and replace both with
83                 # a download seagrub script
84
85                             rm -Rf "${program:?}" && printf "Old %s directory deleted.\n\n" "${program}"
86             else
87                             printf "A %s/ directory already exists, delete it? [yN]: " "${program}"
88                         read -r answer
89                         if [ "${answer}" = "y" ]; then
90                                 rm -Rf "${program:?}" && printf "Old %s directory deleted.\n\n" "${program}"
91                         else
92                                 printf "%s directory not deleted, and therefore not replaced.\n" "${program}"
93                                 continue
94                         fi
95             fi
96                 fi
97         fi
98
99         "${download}/${program}"
100 done