Skip to content

Commit eeed54b

Browse files
authored
Merge pull request #191 from whi-tw/improve_macos_compatibility
`make_custom_pi_os` improvements
2 parents ac8e285 + cc05702 commit eeed54b

File tree

2 files changed

+60
-31
lines changed

2 files changed

+60
-31
lines changed
Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
#!/usr/bin/env bash
2+
set -euo pipefail
23
DEST_FOLDER="$1"
34

4-
DIST_NAME=$(basename $DEST_FOLDER)
5+
DIST_NAME=$(basename "${DEST_FOLDER}")
56

6-
pushd "${DEST_FOLDER}" > /dev/null
7-
pushd src/modules > /dev/null
8-
mv example ${DIST_NAME,,}
9-
pushd ${DIST_NAME,,} > /dev/null
10-
DIST_NAME_UPPER=$(echo $DIST_NAME | awk '{print toupper($0)}')
11-
sed -i "s/EXAMPLE_VAR/${DIST_NAME_UPPER}_VAR/g" config start_chroot_script
12-
popd > /dev/null
13-
popd > /dev/null
14-
pushd src > /dev/null
15-
sed -i "s/export DIST_NAME=.*/export DIST_NAME=${DIST_NAME}/g" config
16-
sed -i "s/example/${DIST_NAME,,}/g" config
17-
popd > /dev/null
18-
popd > /dev/null
7+
if which gsed >/dev/null; then # use gnu sed if available (macos)
8+
SED="gsed"
9+
else
10+
SED="sed"
11+
fi
12+
13+
pushd "${DEST_FOLDER}" >/dev/null || exit 1
14+
pushd src/modules >/dev/null || exit 1
15+
mv example "${DIST_NAME,,}"
16+
pushd "${DIST_NAME,,}" >/dev/null || exit 1
17+
DIST_NAME_UPPER=$(echo "${DIST_NAME}" | awk '{print toupper($0)}')
18+
${SED} -i "s/EXAMPLE_VAR/${DIST_NAME_UPPER}_VAR/g" config start_chroot_script
19+
popd >/dev/null || exit 1
20+
popd >/dev/null || exit 1
21+
pushd src >/dev/null || exit 1
22+
${SED} -i "s/export DIST_NAME=.*/export DIST_NAME=${DIST_NAME}/g" config
23+
${SED} -i "s/example/${DIST_NAME,,}/g" config
24+
popd >/dev/null || exit 1
25+
popd >/dev/null || exit 1

src/make_custom_pi_os

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,71 @@
11
#!/usr/bin/env bash
2-
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2+
set -euo pipefail
3+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
34

45
source "$DIR/argparse.bash" || exit 1
56
argparse "$@" <<EOF || exit 1
67
78
parser.add_argument('dest', help="The destination folder")
89
parser.add_argument('-g', '--get_image', action='store_true',
910
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]')
1015
EOF
1116

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
1429

15-
DIST_NAME=$(basename "$DEST")
30+
echo Settings:
31+
echo "making dstro in ${DEST}"
32+
echo "variant: ${VARIANT}"
1633

1734
for a in "${MULTIPLE[@]}"; do
1835
echo " $a"
1936
done
2037

21-
if [ -d ${DEST} ]; then
38+
if [ -d "${DEST}" ]; then
2239
echo "Error, folder already exists: ${DEST}"
2340
exit 1
2441
fi
2542

26-
if [ -f ${DEST} ]; then
43+
if [ -f "${DEST}" ]; then
2744
echo "Error, file already exists: ${DEST}"
2845
exit 1
2946
fi
3047

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}"
3350

34-
${DIR}/dist_generators/dist_example_script "${DEST}"
51+
"${DIR}/dist_generators/dist_example_script" "${DEST}"
3552

3653
"$DIR/update-custompios-paths" "${DEST}/src"
3754

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}')
4259
if [ $? -ne 0 ]; then
43-
echo "error getting date"
60+
echo -e "\nerror getting date"
4461
exit 1
4562
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}"
4871
fi
49-

0 commit comments

Comments
 (0)