Permalink
Browse files

scripts/*: sync with Entware-ng

  • Loading branch information...
The-BB committed Oct 11, 2017
1 parent ac2d1f4 commit acdb1d99f11edc90d5ca8d56e9a1897795d0518b
@@ -70,26 +70,29 @@ _relpath() {
done
}
_wrapper() {
cat <<-EOT | ${CC:-gcc} -x c -o "$1" -
_runas_so() {
cat <<-EOT | ${CC:-gcc} -x c -fPIC -shared -o "$1" -
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
const char *self = argv[0];
const char *target = argv[1];
int mangle_arg0(int argc, char **argv, char **env) {
char *arg0 = getenv("RUNAS_ARG0");
if (argc < 3) {
fprintf(stderr, "Usage: %s executable arg0 [args...]\n", self);
return 1;
if (arg0) {
argv[0] = arg0;
unsetenv("RUNAS_ARG0");
}
return execv(target, argv + 2);
return 0;
}
__attribute__((section(".init_array")))
static void *mangle_arg0_constructor = &mangle_arg0;
EOT
[ -x "$1" ] || {
echo "compiling wrapper failed" >&2
echo "compiling preload library failed" >&2
exit 5
}
}
@@ -113,13 +116,13 @@ for BIN in "$@"; do
_ln "../lib" "$DIR/usr/lib"
}
[ ! -x "$DIR/lib/runas" ] && {
_wrapper "$DIR/lib/runas"
[ ! -x "$DIR/lib/runas.so" ] && {
_runas_so "$DIR/lib/runas.so"
}
LDSO=""
[ -n "$LDD" ] && [ -x "$BIN" ] && file "$BIN" | grep -sqE "ELF.*executable" && {
[ -n "$LDD" ] && [ -x "$BIN" ] && file "$BIN" | grep -sqE "ELF.*(executable|interpreter)" && {
for token in $("$LDD" "$BIN" 2>/dev/null); do
case "$token" in */*.so*)
case "$token" in
@@ -150,7 +153,9 @@ for BIN in "$@"; do
cat <<-EOF > "$BIN"
#!/usr/bin/env bash
dir="\$(dirname "\$0")"
exec "\$dir/${REL:+$REL/}$LDSO" --library-path "\$dir/${REL:+$REL/}" "\$dir/${REL:+$REL/}runas" "\$dir/.${BIN##*/}.bin" "\$0" "\$@"
export RUNAS_ARG0="\$0"
export LD_PRELOAD="\$dir/${REL:+$REL/}runas.so"
exec "\$dir/${REL:+$REL/}$LDSO" --library-path "\$dir/${REL:+$REL/}" "\$dir/.${BIN##*/}.bin" "\$@"
EOF
chmod ${VERBOSE:+-v} 0755 "$BIN"
View
@@ -16,7 +16,7 @@
@ARGV > 2 or die "Syntax: $0 <target dir> <filename> <hash> <url filename> [<mirror> ...]\n";
my $url_filename;
my $target = shift @ARGV;
my $target = glob(shift @ARGV);
my $filename = shift @ARGV;
my $file_hash = shift @ARGV;
$url_filename = shift @ARGV unless $ARGV[0] =~ /:\/\//;
@@ -88,6 +88,7 @@ ($)
}
my $hash_cmd = hash_cmd();
# $hash_cmd or die "Cannot find appropriate hash command, ensure the provided hash is either a MD5 or SHA256 checksum.\n";
sub download
{
@@ -195,8 +196,8 @@ sub cleanup
} elsif ($mirror =~ /^\@APACHE\/(.+)$/) {
push @mirrors, "https://mirror.netcologne.de/apache.org/$1";
push @mirrors, "https://mirror.aarnet.edu.au/pub/apache/$1";
push @mirrors, "https://mirror.csclub.uwaterloo.ca/apache/$1";
push @mirrors, "http://mirror.cogentco.com/pub/apache/$1";
push @mirrors, "http://mirror.csclub.uwaterloo.ca/apache/$1";
push @mirrors, "http://mirror.navercorp.com/apache/$1";
push @mirrors, "http://ftp.jaist.ac.jp/pub/apache/$1";
push @mirrors, "ftp://apache.cs.utah.edu/apache.org/$1";
@@ -207,17 +208,17 @@ sub cleanup
push @mirrors, "https://raw.githubusercontent.com/$1";
}
} elsif ($mirror =~ /^\@GNU\/(.+)$/) {
push @mirrors, "https://mirrors.rit.edu/gnu/$1";
push @mirrors, "https://mirror.csclub.uwaterloo.ca/gnu/$1";
push @mirrors, "https://mirror.netcologne.de/gnu/$1";
push @mirrors, "http://ftp.kddilabs.jp/GNU/gnu/$1";
push @mirrors, "http://www.nic.funet.fi/pub/gnu/gnu/$1";
push @mirrors, "http://mirror.internode.on.net/pub/gnu/$1";
push @mirrors, "http://mirror.navercorp.com/gnu/$1";
push @mirrors, "ftp://mirror.csclub.uwaterloo.ca/gnu/$1";
push @mirrors, "ftp://mirrors.rit.edu/gnu/$1";
push @mirrors, "ftp://download.xs4all.nl/pub/gnu/";
} elsif ($mirror =~ /^\@SAVANNAH\/(.+)$/) {
push @mirrors, "https://mirror.netcologne.de/savannah/$1";
push @mirrors, "http://mirror.csclub.uwaterloo.ca/nongnu/$1";
push @mirrors, "https://mirror.csclub.uwaterloo.ca/nongnu/$1";
push @mirrors, "http://ftp.acc.umu.se/mirror/gnu.org/savannah/$1";
push @mirrors, "http://nongnu.uib.no/$1";
push @mirrors, "http://ftp.igh.cnrs.fr/pub/nongnu/$1";
@@ -242,7 +243,7 @@ sub cleanup
push @mirrors, "ftp://www.mirrorservice.org/sites/ftp.kernel.org/pub/$dir";
}
} elsif ($mirror =~ /^\@GNOME\/(.+)$/) {
push @mirrors, "http://mirror.csclub.uwaterloo.ca/gnome/sources/$1";
push @mirrors, "https://mirror.csclub.uwaterloo.ca/gnome/sources/$1";
push @mirrors, "http://ftp.acc.umu.se/pub/GNOME/sources/$1";
push @mirrors, "http://ftp.kaist.ac.kr/gnome/sources/$1";
push @mirrors, "http://www.mirrorservice.org/sites/ftp.gnome.org/pub/GNOME/sources/$1";
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
# Copyright (C) 2006-2012 OpenWrt.org
set -x
[ $# == 5 -o $# == 6 ] || {
echo "SYNTAX: $0 <file> <kernel size> <kernel directory> <rootfs size> <rootfs image> [<align>]"
exit 1
}
OUTPUT="$1"
KERNELSIZE="$2"
KERNELDIR="$3"
ROOTFSSIZE="$4"
ROOTFSIMAGE="$5"
ALIGN="$6"
rm -f "$OUTPUT"
head=16
sect=63
cyl=$(( ($KERNELSIZE + $ROOTFSSIZE) * 1024 * 1024 / ($head * $sect * 512)))
# create partition table
set `ptgen -o "$OUTPUT" -h $head -s $sect -p ${KERNELSIZE}m -p ${ROOTFSSIZE}m ${ALIGN:+-l $ALIGN} ${SIGNATURE:+-S 0x$SIGNATURE}`
KERNELOFFSET="$(($1 / 512))"
KERNELSIZE="$2"
ROOTFSOFFSET="$(($3 / 512))"
ROOTFSSIZE="$(($4 / 512))"
[ -n "$PADDING" ] && dd if=/dev/zero of="$OUTPUT" bs=512 seek="$ROOTFSOFFSET" conv=notrunc count="$ROOTFSSIZE"
dd if="$ROOTFSIMAGE" of="$OUTPUT" bs=512 seek="$ROOTFSOFFSET" conv=notrunc
make_ext4fs -J -l "$KERNELSIZE" "$OUTPUT.kernel" "$KERNELDIR"
dd if="$OUTPUT.kernel" of="$OUTPUT" bs=512 seek="$KERNELOFFSET" conv=notrunc
rm -f "$OUTPUT.kernel"
View
@@ -2,7 +2,7 @@ package metadata;
use base 'Exporter';
use strict;
use warnings;
our @EXPORT = qw(%package %srcpackage %category %subdir %preconfig %features %overrides clear_packages parse_package_metadata parse_target_metadata get_multiline @ignore);
our @EXPORT = qw(%package %srcpackage %category %subdir %preconfig %features %overrides clear_packages parse_package_metadata parse_target_metadata get_multiline @ignore %usernames %groupnames);
our %package;
our %preconfig;
@@ -13,6 +13,11 @@ our %features;
our %overrides;
our @ignore;
our %usernames;
our %groupnames;
our %userids;
our %groupids;
sub get_multiline {
my $fh = shift;
my $prefix = shift;
@@ -31,6 +36,58 @@ sub confstr($) {
return $conf;
}
sub parse_package_metadata_usergroup($$$$$) {
my $makefile = shift;
my $typename = shift;
my $names = shift;
my $ids = shift;
my $spec = shift;
my $name;
my $id;
# the regex for name is taken from is_valid_name() of package shadow
if ($spec =~ /^([a-z_][a-z0-9_-]*\$?)$/) {
$name = $spec;
$id = -1;
} elsif ($spec =~ /^([a-z_][a-z0-9_-]*\$?)=(\d+)$/) {
$name = $1;
$id = $2;
} else {
warn "$makefile: invalid $typename spec $spec\n";
return 0;
}
if ($id =~ /^[1-9]\d*$/) {
if ($id >= 65536) {
warn "$makefile: $typename $name id $id >= 65536";
return 0;
}
if (not exists $ids->{$id}) {
$ids->{$id} = {
name => $name,
makefile => $makefile,
};
} elsif ($ids->{$id}{name} ne $name) {
warn "$makefile: $typename $name id $id is already taken by $ids->{$id}{makefile}\n";
return 0;
}
} elsif ($id != -1) {
warn "$makefile: $typename $name has invalid id $id\n";
return 0;
}
if (not exists $names->{$name}) {
$names->{$name} = {
id => $id,
makefile => $makefile,
};
} elsif ($names->{$name}{id} != $id) {
warn "$makefile: id of $typename $name collides with that defined defined in $names->{$name}{makefile}\n";
return 0;
}
return 1;
}
sub parse_target_metadata($) {
my $file = shift;
my ($target, @target, $profile);
@@ -128,6 +185,8 @@ sub clear_packages() {
%category = ();
%features = ();
%overrides = ();
%usernames = ();
%groupnames = ();
}
sub parse_package_metadata($) {
@@ -262,6 +321,17 @@ sub parse_package_metadata($) {
/^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type} = $1;
/^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label} = $1;
/^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
/^Require-User:\s*(.*?)\s*$/ and do {
my @ugspecs = split /\s+/, $1;
for my $ugspec (@ugspecs) {
my @ugspec = split /:/, $ugspec, 2;
parse_package_metadata_usergroup($makefile, "user", \%usernames, \%userids, $ugspec[0]) or return 0;
if (@ugspec > 1) {
parse_package_metadata_usergroup($makefile, "group", \%groupnames, \%groupids, $ugspec[1]) or return 0;
}
}
};
}
close FILE;
return 1;
@@ -1,4 +1,4 @@
#/bin/sh
#!/bin/sh
#
# Copyright (C) 2011 OpenWrt.org
#
View

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit acdb1d9

Please sign in to comment.