Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions src/dist_generators/dist_example_script
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
#!/usr/bin/env bash
set -euo pipefail
DEST_FOLDER="$1"

DIST_NAME=$(basename $DEST_FOLDER)
DIST_NAME=$(basename "${DEST_FOLDER}")

pushd "${DEST_FOLDER}" > /dev/null
pushd src/modules > /dev/null
mv example ${DIST_NAME,,}
pushd ${DIST_NAME,,} > /dev/null
DIST_NAME_UPPER=$(echo $DIST_NAME | awk '{print toupper($0)}')
sed -i "s/EXAMPLE_VAR/${DIST_NAME_UPPER}_VAR/g" config start_chroot_script
popd > /dev/null
popd > /dev/null
pushd src > /dev/null
sed -i "s/export DIST_NAME=.*/export DIST_NAME=${DIST_NAME}/g" config
sed -i "s/example/${DIST_NAME,,}/g" config
popd > /dev/null
popd > /dev/null
if which gsed >/dev/null; then # use gnu sed if available (macos)
SED="gsed"
else
SED="sed"
fi

pushd "${DEST_FOLDER}" >/dev/null || exit 1
pushd src/modules >/dev/null || exit 1
mv example "${DIST_NAME,,}"
pushd "${DIST_NAME,,}" >/dev/null || exit 1
DIST_NAME_UPPER=$(echo "${DIST_NAME}" | awk '{print toupper($0)}')
${SED} -i "s/EXAMPLE_VAR/${DIST_NAME_UPPER}_VAR/g" config start_chroot_script
popd >/dev/null || exit 1
popd >/dev/null || exit 1
pushd src >/dev/null || exit 1
${SED} -i "s/export DIST_NAME=.*/export DIST_NAME=${DIST_NAME}/g" config
${SED} -i "s/example/${DIST_NAME,,}/g" config
popd >/dev/null || exit 1
popd >/dev/null || exit 1
56 changes: 39 additions & 17 deletions src/make_custom_pi_os
Original file line number Diff line number Diff line change
@@ -1,49 +1,71 @@
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
set -euo pipefail
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

source "$DIR/argparse.bash" || exit 1
argparse "$@" <<EOF || exit 1

parser.add_argument('dest', help="The destination folder")
parser.add_argument('-g', '--get_image', action='store_true',
help='Pick a number [default %(default)s]')
parser.add_argument('-v', '--variant', action='store',
choices=['raspios_lite_armhf', 'raspios_lite_arm64'],
default='raspios_lite_armhf',
help='Which variant to use [default: %(default)s]')
EOF

echo Settings:
echo making dstro in "$DEST"
case $DEST in
*"-"*)
echo "Error, destination folder cannot contain a dash"
exit 1
;;
*" "*)
echo "Error, destination folder cannot contain a space"
exit 1
;;
*)
;;
esac

DIST_NAME=$(basename "$DEST")
echo Settings:
echo "making dstro in ${DEST}"
echo "variant: ${VARIANT}"

for a in "${MULTIPLE[@]}"; do
echo " $a"
done

if [ -d ${DEST} ]; then
if [ -d "${DEST}" ]; then
echo "Error, folder already exists: ${DEST}"
exit 1
fi

if [ -f ${DEST} ]; then
if [ -f "${DEST}" ]; then
echo "Error, file already exists: ${DEST}"
exit 1
fi

cp -a ${DIR}/dist_generators/dist_example "${DEST}"
chown $USER:$USER -R ${DEST}
cp -a "${DIR}/dist_generators/dist_example" "${DEST}"
chown -R "${USER}":"$(id -gn "${USER}")" "${DEST}"

${DIR}/dist_generators/dist_example_script "${DEST}"
"${DIR}/dist_generators/dist_example_script" "${DEST}"

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

if [ $GET_IMAGE ]; then
echo "Downloading latest Raspbian image"
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}')
if [ "$GET_IMAGE" ]; then
echo -n "Downloading latest Raspbian image"

CURRENT_RASPBIAN=$(curl -s "https://downloads.raspberrypi.org/${VARIANT}/images/" | grep raspios | tail -n 1 | awk -F "href=\"" '{print $2}' | awk -F "/" '{print $1}')
if [ $? -ne 0 ]; then
echo "error getting date"
echo -e "\nerror getting date"
exit 1
fi
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}')
curl -L -o "${DEST}/src/image/${CURRENT_RASPBIAN_FILE}" https://downloads.raspberrypi.org/raspios_lite_armhf/images/${CURRENT_RASPBIAN}/${CURRENT_RASPBIAN_FILE}
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}')"
if [ $? -ne 0 ]; then
echo -e "\nerror getting file name"
exit 1
fi
CURRENT_RASPBIAN_URL="https://downloads.raspberrypi.org/${VARIANT}/images/${CURRENT_RASPBIAN}/${CURRENT_RASPBIAN_FILE}"
echo " from ${CURRENT_RASPBIAN_URL}"
curl -L -o "${DEST}/src/image/${CURRENT_RASPBIAN_FILE}" "${CURRENT_RASPBIAN_URL}"
fi