From c0bb67915bed486c6057b86759b25f21064102dc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= <karel.koci@nic.cz>
Date: Tue, 28 May 2019 13:16:58 +0200
Subject: [PATCH] compile_pkgs: don't run it under sudo and build everything

Parameter -e is now obsolete and by default, we want to build everything.
Removed it from turris-build.conf.example

Because of that we or users don't need to select packages in make
menuconfig which we or they want to build. Now each package will be selected
but not compiled which depends on user choice.

Also, compile_pkgs shouldn't be run under root or with sudo. Do it as
normal user.
---
 compile_pkgs              | 13 +++++--------
 turris-build.conf.example |  2 --
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/compile_pkgs b/compile_pkgs
index 9ea69d709..6d4b3576c 100755
--- a/compile_pkgs
+++ b/compile_pkgs
@@ -75,7 +75,6 @@ openwrt_feed() {
 # Configuration variables
 . "$src_dir/defaults.sh"
 FORCE="" # Force build
-EVERYTHING="" # Set this variable to build all packages not only minimal set
 CLONE_DEEP="" # Set this variable to clone OpenWRT tree in full depth not just latest commit
 BUILD_ARGS=() # Additional arguments passed to OpenWRT make call (note that this is for all make calls in OpenWRT)
 BUILD_JOBS="$(nproc)" # Number of jobs to be passed to make calls
@@ -188,8 +187,6 @@ available_commands+=( ["configure"]="Recreates configuration for target boards"
 configure() {
 	_report "Creating default configuration"
 	[ -n "${TARGET_BOARD}" ] || _die "No board selected!"
-	local everything
-	[ "$EVERYTHING" = yes ] && everything=y || everything=n
 	cat "${src_dir}"/configs/common/* "${src_dir}/configs/${TARGET_BOARD}"/* > ./.config
 	{
 		echo "CONFIG_DEVEL=y"
@@ -201,8 +198,8 @@ configure() {
 		echo "CONFIG_VERSION_HOME_URL=\"https://www.turris.cz/\""
 		echo "CONFIG_VERSION_BUG_URL=\"https://gitlab.labs.nic.cz/groups/turris/-/issues\""
 		echo "CONFIG_VERSION_SUPPORT_URL=\"https://www.turris.cz/support/\""
-		echo "CONFIG_ALL_KMODS=$everything"
-		echo "CONFIG_ALL=$everything"
+		echo "CONFIG_ALL_KMODS=y"
+		echo "CONFIG_ALL=y"
 	} >> .config
 	_make defconfig diffconfig
 	OPENWRT_ARCH="$(sed -n 's|^CONFIG_TARGET_BOARD="\([^"]*\)"|\1|p' .config)"
@@ -562,7 +559,6 @@ print_help() {
 	echo "Compile TurrisOS packages. This script fetches, patches and configures OpenWRT tree."
 	echo
 	echo "Primary options:"
-	echo "	-e		Build everything, not just minimal set"
 	echo "	-t BOARD	Set target board to BOARD. This is required for almost all commands."
 	echo "	-jNUM		Number of jobs in paralel to be run. In default number of CPUs is used."
 	echo "	-a ARG		Add build arguments - passed directly to make. This option can be specified multiple times."
@@ -591,7 +587,7 @@ steps=()
 while [ $# -gt 0 ]; do
 	case "$1" in
 		-e)
-			EVERYTHING="yes"
+			echo "-e option is obsoleted and execution now always runs as with this option." >&2
 			;;
 		-j*)
 			BUILD_JOBS="${1#-j}"
@@ -647,8 +643,9 @@ while [ $# -gt 0 ]; do
 	shift
 done
 
-[ ${#steps[@]} -gt 0 ] || steps=( "${DEFAULT_STEPS[@]}" )
+[ "$(id -u)" != 0 ] || _die "Build should not be run under root!"
 
+[ ${#steps[@]} -gt 0 ] || steps=( "${DEFAULT_STEPS[@]}" )
 for step in "${steps[@]}"; do
 	"$step"
 done
diff --git a/turris-build.conf.example b/turris-build.conf.example
index d5a933536..2bef5f754 100644
--- a/turris-build.conf.example
+++ b/turris-build.conf.example
@@ -8,8 +8,6 @@
 # This file is sourced to bash script (compile_pkgs) so you can use any bash
 # compatible syntax here.
 
-# Set this variable to build all packages not only minimal set
-EVERYTHING=y
 # Number of jobs to be passed to make calls
 BUILD_JOBS="$(nproc)"
 # Path to private signing key
-- 
GitLab