fwupd/contrib/setup
Mario Limonciello cc8eb5ca8c trivial: Merge python steps from contrib/setup into helper script
This avoids having to hardcode profile targets in multiple places
and also fixes the confusing entry points into scripts both by
arguments and environment variables.

It also makes the setup script a lot more debuggable and scalable.

OS detection is a lot more robust, where it will try to use pip to
set up the distro python package, and if pip is missing try to install
it.

If OS detection fails now, a user can use --os on contrib/setup for
specifying it.
2021-09-17 10:59:35 -05:00

127 lines
2.6 KiB
Bash
Executable File

#!/bin/bash -e
# Setup the repository and local system for development
cd "$(dirname "$0")/.."
HELPER=./contrib/ci/fwupd_setup_helpers.py
HELPER_ARGS="-y"
setup_deps()
{
read -p "Install build dependencies? (y/n) " question
if [ "$question" = "y" ]; then
$(which sudo) python3 $HELPER install-dependencies $HELPER_ARGS -y
fi
}
setup_run_dev()
{
read -p "Set up dbus activated daemon and PolicyKit actions from /usr/local? (y/n) " question
if [ "$question" = "y" ]; then
./contrib/prepare-system /usr/local install
fi
}
setup_vscode()
{
# Add default vscode settings if not existing
SETTINGS_FILE=./.vscode/settings.json
SETTINGS_TEMPLATE_FILE=./contrib/vscode/settings.json
if [ ! -f "$SETTINGS_FILE" ]; then
mkdir ./.vscode
echo "Copy $SETTINGS_TEMPLATE_FILE to $SETTINGS_FILE."
cp "$SETTINGS_TEMPLATE_FILE" "$SETTINGS_FILE"
fi
}
setup_git()
{
echo "Configuring git environment"
git config include.path ../.gitconfig
}
install_pip()
{
package=$1
args=$2
if ! python3 -m pip install $package $args; then
$(which sudo) python3 $HELPER install-pip $HELPER_ARGS -y
fi
#try once more
python3 -m pip install $package
}
setup_precommit()
{
echo "Configuring pre-commit hooks"
python3 -m venv venv
source venv/bin/activate
install_pip pre-commit
pre-commit install
}
check_markdown()
{
if ! python3 $HELPER test-markdown; then
install_pip markdown --upgrade
fi
}
detect_os()
{
for i in "$@"; do
case $i in
--os=*)
OS="${i#*=}"
shift
;;
--debug)
DEBUG=1
shift
;;
*)
;;
esac
done
if [ -z $OS ]; then
OS=$(python3 $HELPER detect-profile)
if [ -z "$OS" ]; then
install_pip distro
OS=$(python3 $HELPER detect-profile)
fi
echo "Using OS profile $OS to setup"
fi
if [ -n "$OS" ];then
HELPER_ARGS="$HELPER_ARGS --os $OS"
fi
if [ -n "$DEBUG" ]; then
set -x
HELPER_ARGS="$HELPER_ARGS --debug"
fi
}
#needed for arguments for some commands
detect_os "$@"
#if interactive install build deps and prepare environment
if [ -t 2 ]; then
case $OS in
debian|ubuntu|arch|fedora)
setup_deps
setup_run_dev
;;
void)
setup_deps
;;
esac
check_markdown
setup_vscode
fi
#always setup pre-commit
setup_precommit
#always setup git environment
setup_git