Kaynağa Gözat

Allow running with sudo or as root instead of fakeroot

It works around a problem with fakeroot as seen in github pull
request #6.

Pack rootfs
tar: rootfs/usr/lib/opkg/info/dropbear.conffiles: Cannot readlink: Invalid argument
tar: rootfs/usr/lib/opkg/info/dropbear.control: Cannot readlink: Invalid argument
tar: Exiting with failure status due to previous errors
Tarball built: bin/openwrt-18.06.1-x86-64-lxd.tar.gz
Mikael Magnusson 6 yıl önce
ebeveyn
işleme
8b67a2a907
2 değiştirilmiş dosya ile 30 ekleme ve 6 silme
  1. 3 3
      README
  2. 27 3
      build.sh

+ 3 - 3
README

@@ -19,11 +19,11 @@ Refer to the top of build.sh.
 
 Usage
 -----
-./build.sh [-a|--arch <x86_64|i686|aarch64>] [-v|--version <version>] [-p|--packages <packages>] [-f|--files] [--help]
+./build.sh [-a|--arch x86_64|i686|aarch64] [-v|--version <version>] [-p|--packages <packages>] [-f|--files] [-t|--type lxd|plain] [-s|--super fakeroot|sudo] [--help]
 
 Example
 -------
-./build.sh -v 18.06.1
-lxc image import bin/openwrt-18.06.1-x86-64-lxd.tar.gz --alias openwrt
+./build.sh -v 18.06.2
+lxc image import bin/openwrt-18.06.2-x86-64-lxd.tar.gz --alias openwrt
 lxc launch openwrt router
 lxc exec router passwd root

+ 27 - 3
build.sh

@@ -6,16 +6,17 @@ arch_lxd=x86_64
 ver=18.06.2
 dist=openwrt
 type=lxd
+super=fakeroot
 
 # Workaround for Debian/Ubuntu systems which use C.UTF-8 which is unsupported by OpenWrt
 export LC_ALL=C
 
 usage() {
-	echo "Usage: $0 [-a|--arch <x86_64|i686|aarch64>] [-v|--version <version>] [-p|--packages <packages>] [-f|--files] [-t|--type lxd|plain] [--help]"
+	echo "Usage: $0 [-a|--arch x86_64|i686|aarch64] [-v|--version <version>] [-p|--packages <packages>] [-f|--files] [-t|--type lxd|plain] [-s|--super fakeroot|sudo] [--help]"
 	exit 1
 }
 
-temp=$(getopt -o "a:v:p:f:t:" -l "arch:,version:,packages:,files:,type:,help" -- "$@")
+temp=$(getopt -o "a:v:p:f:t:s:" -l "arch:,version:,packages:,files:,type:,super:,help" -- "$@")
 eval set -- "$temp"
 while true; do
 	case "$1" in
@@ -42,6 +43,16 @@ while true; do
 		*)
 			usage;;
 		esac;;
+	-s|--super)
+		super="$2"
+		shift 2
+
+		case "$super" in
+		fakeroot|sudo)
+			;;
+		*)
+			usage;;
+		esac;;
 	--help)
 		usage;;
 	--)
@@ -226,7 +237,20 @@ build_tarball() {
 	for pkg in $pkgdir/*.ipk; do
 		allpkgs=" $pkg"
 	done
-	fakeroot scripts/build_rootfs.sh $rootfs $opts -o $tarball --arch=${arch} --subarch=${subarch} --packages="${allpkgs}" --files="${files}"
+
+	local cmd="scripts/build_rootfs.sh"
+	if test `id -u` != 0; then
+		case "$super" in
+			sudo)
+				cmd="sudo --preserve-env=SDK $cmd"
+				;;
+			*)
+				cmd="$super $cmd"
+				;;
+		esac
+	fi
+
+	$cmd $rootfs $opts -o $tarball --arch=${arch} --subarch=${subarch} --packages="${allpkgs}" --files="${files}"
 }
 
 build_metadata() {