WIP ppl-os building tools
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

118 lines
3.0 KiB

#!/bin/bash
TEST_SNAP="H4sIANNl+VsAA+3SzWoDIRQFYNc+xd1l1XSczDjgc+QFzMQEy2hEnUIoeffqQH8WDd0klNDzLbygFxWPyevwzO6rKYa+r1UMffO9fmBisxlkK9uhFawRolRG/Z3vtZhT1pGIOT1a83K977f1B5Vq/nUYoz7k9Vm76eZn1IBl113Nv23lZ/5Sln8iOtFJRs3Nb/KDf56/184oyiblp/oL+KuJyZ68opVYNyueZud0PCvalg5aOvYmjdGGvHR9TfNj1PuyVXnO3WT4ePIH640zPte5aMfMuQ4hKXq7cB50zElxWk6ulShM89GWLb2d+F+/CgAAAAAAAAAAAAAAAAAAAADAY3gHvsPMsQAoAAA="
die() {
echo -e "ERROR: $1" 1>&2
exit 2
}
if [ ! -z "$ENABLE_SIGNING" ]; then
ENABLE_SIGNING=true
else
ENABLE_SIGNING=false
fi
if [ "x$1" == "xread" ]; then
if [ ! -e .config ]; then
die "No config found. Run '$ bash conf-tool.sh'"
fi
. .config
echo "${!2}"
exit
fi
signing_key=$(snap keys | tail -n 1 | sed "s| |\n|g" | head -n 1) # value if no key exists: "No"
user_email=$(snap whoami | sed "s|email: ||g") # value if not signed in: "-"
read_prompt() {
read -p "> Enter $1 (default $2$3): " val
if [ -z "$val" ]; then
val="$2"
fi
echo "< $val"
}
if [ "$user_email" == "-" ]; then
die "User email is not set up. Please run:\n\n\t$ snap login"
fi
if $ENABLE_SIGNING; then
if [ "$signing_key" == "No" ]; then
die "Signing key is not set up. https://tutorials.ubuntu.com/tutorial/create-your-own-core-image#3"
fi
else
signing_key="-"
fi
echo
echo "Testing snap building support..."
tmp=$(mktemp -d)
o="$PWD"
cd "$tmp"
echo "$TEST_SNAP" | base64 -d | tar xz
OUT=$(snapcraft 2>&1 || /bin/true)
if [[ "$OUT" = "Native builds"* ]]; then
echo "$OUT" | tail -n 1
echo "Testing cleanbuild..."
OUT=$(snapcraft cleanbuild 2>&1 || /bin/true)
if [[ "$OUT" = "Failed to initialize container"* ]]; then
echo "$OUT" 1>&2
die "Quitting as neither native backend nor container backend works."
elif [[ "$OUT" = "Error: Get"* ]]; then
if [[ "$OUT" = *"connect: permission denied"* ]]; then
die "User not in lxd group. Run '$ sudo addgroup $(whoami) lxd', re-login and try again!"
else
echo "$OUT" 1>&2
die "LXD isn't properly configured!"
fi
else
echo "Using container building"
SNAP_BUILD=cleanbuild
fi
else
echo "Using native building"
SNAP_BUILD=build
fi
echo
cd "$o"
rm -rf "$tmp"
dev_user=$(echo "$user_email" | sed "s|@.*||g")
read_prompt "Device channel" "edge" # TODO: switch to "stable"/"beta" once released for rpi3
channel="$val"
read_prompt "Device environment" "dev" " - use prod for production"
dev_env="$val"
read_prompt "Development device username" "$dev_user" " - taken from user email"
dev_user="$val"
read_prompt "Development device address" "localhost" " - for qemu emulation"
dev_addr="$val"
read_prompt "Development device port" "8022" " - for qemu emulation, use 22 for real device"
dev_port="$val"
vals="CHANNEL=$channel
ENV=$dev_env
DEVICE_IP=$dev_addr
DEVICE_USERNAME=$dev_user
DEVICE_PORT=$dev_port
ENABLE_SIGNING=$ENABLE_SIGNING
USER_KEY=$signing_key
USER_EMAIL=$user_email
SNAP_BUILD=$SNAP_BUILD"
echo "
$vals
"
read -p "Is this correct [y/N]:" v
if [[ "$v" == [yY]* ]]; then
echo "$vals" > .config
else
echo
bash $0
fi