|
1 | 1 | #!/usr/bin/env bash |
2 | | -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 2 | +set -euo pipefail |
| 3 | +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
3 | 4 |
|
4 | 5 | source "$DIR/argparse.bash" || exit 1 |
5 | 6 | argparse "$@" <<EOF || exit 1 |
6 | 7 |
|
7 | 8 | parser.add_argument('dest', help="The destination folder") |
8 | 9 | parser.add_argument('-g', '--get_image', action='store_true', |
9 | 10 | help='Pick a number [default %(default)s]') |
| 11 | +parser.add_argument('-v', '--variant', action='store', |
| 12 | + choices=['raspios_lite_armhf', 'raspios_lite_arm64'], |
| 13 | + default='raspios_lite_armhf', |
| 14 | + help='Which variant to use [default: %(default)s]') |
10 | 15 | EOF |
11 | 16 |
|
12 | | -echo Settings: |
13 | | -echo making dstro in "$DEST" |
| 17 | +case $DEST in |
| 18 | + *"-"*) |
| 19 | + echo "Error, destination folder cannot contain a dash" |
| 20 | + exit 1 |
| 21 | + ;; |
| 22 | + *" "*) |
| 23 | + echo "Error, destination folder cannot contain a space" |
| 24 | + exit 1 |
| 25 | + ;; |
| 26 | + *) |
| 27 | + ;; |
| 28 | +esac |
14 | 29 |
|
15 | | -DIST_NAME=$(basename "$DEST") |
| 30 | +echo Settings: |
| 31 | +echo "making dstro in ${DEST}" |
| 32 | +echo "variant: ${VARIANT}" |
16 | 33 |
|
17 | 34 | for a in "${MULTIPLE[@]}"; do |
18 | 35 | echo " $a" |
19 | 36 | done |
20 | 37 |
|
21 | | -if [ -d ${DEST} ]; then |
| 38 | +if [ -d "${DEST}" ]; then |
22 | 39 | echo "Error, folder already exists: ${DEST}" |
23 | 40 | exit 1 |
24 | 41 | fi |
25 | 42 |
|
26 | | -if [ -f ${DEST} ]; then |
| 43 | +if [ -f "${DEST}" ]; then |
27 | 44 | echo "Error, file already exists: ${DEST}" |
28 | 45 | exit 1 |
29 | 46 | fi |
30 | 47 |
|
31 | | -cp -a ${DIR}/dist_generators/dist_example "${DEST}" |
32 | | -chown $USER:$USER -R ${DEST} |
| 48 | +cp -a "${DIR}/dist_generators/dist_example" "${DEST}" |
| 49 | +chown -R "${USER}":"$(id -gn "${USER}")" "${DEST}" |
33 | 50 |
|
34 | | -${DIR}/dist_generators/dist_example_script "${DEST}" |
| 51 | +"${DIR}/dist_generators/dist_example_script" "${DEST}" |
35 | 52 |
|
36 | 53 | "$DIR/update-custompios-paths" "${DEST}/src" |
37 | 54 |
|
38 | | -if [ $GET_IMAGE ]; then |
39 | | - echo "Downloading latest Raspbian image" |
40 | | - |
41 | | - CURRENT_RASPBIAN=$(curl https://downloads.raspberrypi.org/raspios_lite_armhf/images/ | grep raspios | tail -n 1 | awk -F "href=\"" '{print $2}' | awk -F "/" '{print $1}') |
| 55 | +if [ "$GET_IMAGE" ]; then |
| 56 | + echo -n "Downloading latest Raspbian image" |
| 57 | + |
| 58 | + CURRENT_RASPBIAN=$(curl -s "https://downloads.raspberrypi.org/${VARIANT}/images/" | grep raspios | tail -n 1 | awk -F "href=\"" '{print $2}' | awk -F "/" '{print $1}') |
42 | 59 | if [ $? -ne 0 ]; then |
43 | | - echo "error getting date" |
| 60 | + echo -e "\nerror getting date" |
44 | 61 | exit 1 |
45 | 62 | fi |
46 | | - CURRENT_RASPBIAN_FILE=$(curl http://downloads.raspberrypi.org/raspios_lite_armhf/images/${CURRENT_RASPBIAN}/ | grep .xz | head -n 1 | awk -F "href=\"" '{print $2}' | awk -F "\">" '{print $1}') |
47 | | - curl -L -o "${DEST}/src/image/${CURRENT_RASPBIAN_FILE}" https://downloads.raspberrypi.org/raspios_lite_armhf/images/${CURRENT_RASPBIAN}/${CURRENT_RASPBIAN_FILE} |
| 63 | + CURRENT_RASPBIAN_FILE="$(curl -s "http://downloads.raspberrypi.org/${VARIANT}/images/${CURRENT_RASPBIAN}"/ | grep .xz | head -n 1 | awk -F "href=\"" '{print $2}' | awk -F "\">" '{print $1}')" |
| 64 | + if [ $? -ne 0 ]; then |
| 65 | + echo -e "\nerror getting file name" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | + CURRENT_RASPBIAN_URL="https://downloads.raspberrypi.org/${VARIANT}/images/${CURRENT_RASPBIAN}/${CURRENT_RASPBIAN_FILE}" |
| 69 | + echo " from ${CURRENT_RASPBIAN_URL}" |
| 70 | + curl -L -o "${DEST}/src/image/${CURRENT_RASPBIAN_FILE}" "${CURRENT_RASPBIAN_URL}" |
48 | 71 | fi |
49 | | - |
|
0 commit comments