Skip to content

Commit

Permalink
20150909
Browse files Browse the repository at this point in the history
  • Loading branch information
marinelli committed May 10, 2017
1 parent 1d1f439 commit fecb406
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 85 deletions.
43 changes: 12 additions & 31 deletions opt/local/bin/bootstrap
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/bin/sh

. /opt/local/lib/optlocal.sh
. /opt/local/lib/pkg.sh
. /opt/local/lib/dns.sh
. /opt/local/lib/sys.sh
. /opt/local/lib/shell.sh

for lib in optlocal pkg dns sys shell ; do
. "/opt/local/lib/${lib}.sh"
done

wait_for_seconds 20

Expand All @@ -20,52 +17,38 @@ optlocal copy dest=/ << EOF
etc/passwd etc/shadow etc/group
etc/hosts etc/profile etc/rc.local
etc/sysupgrade.conf etc/sysctl.conf
etc/init.d/boot
EOF

find /opt/local/etc/profile.d/ -type f \! -name \*.off | \
optlocal link dest=/

optlocal copy dest=/ << EOF
etc/init.d/boot
EOF

find /opt/local/etc/config/ -type f \! -name \*.off | \
optlocal copy dest=/

disable_and_stop_daemon odhcpd

disable_and_stop_daemon dnsmasq

disable_and_stop_daemon dropbear

optlocal replace dest=/ etc/dropbear/dropbear_dss_host_key
optlocal replace dest=/ etc/dropbear/dropbear_rsa_host_key
which dropbear >/dev/null && ! pidof sshd >/dev/null && {
proctl start dropbear
}

proctl reload system
proctl reload network
proctl reload firewall

wait_for_seconds 10

dns_temp_enable

pidof ntpd >/dev/null && proctl stop sysntpd
/usr/sbin/ntpd -nqN \
-p 0.europe.pool.ntp.org -p 1.europe.pool.ntp.org \
-p 2.europe.pool.ntp.org -p 3.europe.pool.ntp.org \
>/dev/null 2>&1
proctl start sysntpd

## opkg
optlocal link dest=/ << EOF
etc/opkg.conf
etc/opkg/distfeeds.conf
EOF

while true ; do
opkg update >/dev/null 2>&1 && break
opkg --verbosity=0 update && break
sleep 5
done
##


## mksh
Expand All @@ -74,13 +57,9 @@ pkg_installed mksh && change_user_shell root /bin/mksh
##


## dropbear
disable_and_stop_daemon dropbear
## openssh
pkg_installed dropbear && pkg_remove dropbear
##


## openssh
pkg_install openssh-server openssh-moduli openssh-client

disable_and_stop_daemon sshd
Expand All @@ -95,6 +74,7 @@ proctl start sshd

## dnsmasq
pkg_installed dnsmasq && pkg_remove dnsmasq

pkg_install dnsmasq-full

disable_and_stop_daemon dnsmasq
Expand Down Expand Up @@ -151,4 +131,5 @@ pkg_remove \
dns_temp_disable

proctl reload network
proctl reload firewall

24 changes: 12 additions & 12 deletions opt/local/bin/check-openwrt-mirror
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@


export_required_commands 'cut wget md5sum'
export_required_commands 'gzip grep sed'


OPENWRT_SITE='http://downloads.openwrt.org/snapshots/trunk/'


OPENWRT_ARCH='ar71xx/generic'

if [ ! -z "$1" ] ; then
OPENWRT_ARCH="$1"
if [ -z "$2" ] ; then
OPENWRT_ARCH=$( sed -rn 's-^DISTRIB_TARGET=\x27(.*)\x27$-\1-p' /etc/openwrt_release )
else
OPENWRT_ARCH="$2"
fi


OPENWRT_MIRROR='garr'

if [ ! -z "$2" ] ; then
OPENWRT_MIRROR="$2"
if [ -z "$1" ] ; then
printf '!!! %s\n' "you need to pass the mirror name: garr or brrr"
exit 1
else
OPENWRT_MIRROR="$1"
fi

case "$OPENWRT_MIRROR" in
Expand All @@ -29,8 +29,8 @@ case "$OPENWRT_MIRROR" in
garr)
MIRROR_SITE='http://mirror1.mirror.garr.it/mirrors/openwrt/snapshots/trunk/'
;;
reversiva)
MIRROR_SITE='http://reversiva.net:10080/openwrt/snapshots/trunk/'
brrr)
MIRROR_SITE='https://brrr.fr/openwrt/snapshots/trunk/'
;;
*)
MIRROR_SITE="$OPENWRT_MIRROR"
Expand Down
41 changes: 35 additions & 6 deletions opt/local/bin/proctl
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,47 @@
EXIT_FAILURE=1
EXIT_SUCCESS=0

SERVICE="/etc/init.d/$2"
INITS_PATH='/etc/init.d'

COMMAND="$1"
INITSCRIPT="$2"

if [ "x" == "x$2" ] ; then
if [ "" == "$2" ] ; then
printf '>>> Syntax: proctl <command> <initscript>\n'
exit $EXIT_FAILURE
fi

if [ -x "${SERVICE}" ] ; then
exec "${SERVICE}" "${COMMAND}"
else
printf '>>> `%s´ not found\n' "${SERVICE}"
INITSCRIPT_PATH="${INITS_PATH}/${INITSCRIPT}"

if [ ! -x "${INITSCRIPT_PATH}" ] ; then
printf '>>> proctl: %s has not been found\n' "$INITSCRIPT"
exit $EXIT_FAILURE
fi

if [ "$COMMAND" == "initpath" ] ; then
printf '%s\n' "$INITSCRIPT_PATH"
exit $EXIT_SUCCESS
fi

if [ "$COMMAND" == "progname" ] ; then
PROGNAME=$( sed -rn 's-^PROG=(.+)$-\1-p' "$INITSCRIPT_PATH" )
PROGNAME="${PROGNAME##*/}"

if [ "$PROGNAME" != "" ] ; then
printf '%s\n' "$PROGNAME"
exit $EXIT_SUCCESS
else
exit $EXIT_FAILURE
fi
fi

if [ "$COMMAND" == "progpath" ] ; then
PROGNAME=$( sed -rn 's-^PROG=(.+)$-\1-p' "$INITSCRIPT_PATH" )

which "$PROGNAME" 2>/dev/null

exit $?
fi

exec "$INITSCRIPT_PATH" "$COMMAND"

1 change: 0 additions & 1 deletion opt/local/etc/opkg.conf

This file was deleted.

1 change: 1 addition & 0 deletions opt/local/etc/opkg/distfeeds.conf
6 changes: 6 additions & 0 deletions opt/local/etc/opkg/opkg-brrr-https.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
src/gz chaos_calmer_base https://brrr.fr/openwrt/snapshots/trunk/ar71xx/generic/packages/base
src/gz chaos_calmer_luci https://brrr.fr/openwrt/snapshots/trunk/ar71xx/generic/packages/luci
src/gz chaos_calmer_management https://brrr.fr/openwrt/snapshots/trunk/ar71xx/generic/packages/management
src/gz chaos_calmer_packages https://brrr.fr/openwrt/snapshots/trunk/ar71xx/generic/packages/packages
src/gz chaos_calmer_routing https://brrr.fr/openwrt/snapshots/trunk/ar71xx/generic/packages/routing
src/gz chaos_calmer_telephony https://brrr.fr/openwrt/snapshots/trunk/ar71xx/generic/packages/telephony
4 changes: 0 additions & 4 deletions opt/local/etc/opkg/opkg-garr-http.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
dest root /
dest ram /tmp
lists_dir ext /var/opkg-lists
option overlay_root /overlay
src/gz chaos_calmer_base http://mirror1.mirror.garr.it/mirrors/openwrt/snapshots/trunk/ar71xx/generic/packages/base
src/gz chaos_calmer_luci http://mirror1.mirror.garr.it/mirrors/openwrt/snapshots/trunk/ar71xx/generic/packages/luci
src/gz chaos_calmer_management http://mirror1.mirror.garr.it/mirrors/openwrt/snapshots/trunk/ar71xx/generic/packages/management
Expand Down
4 changes: 0 additions & 4 deletions opt/local/etc/opkg/opkg-openwrt-http.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
dest root /
dest ram /tmp
lists_dir ext /var/opkg-lists
option overlay_root /overlay
src/gz chaos_calmer_base http://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/packages/base
src/gz chaos_calmer_luci http://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/packages/luci
src/gz chaos_calmer_management http://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/packages/management
Expand Down
4 changes: 0 additions & 4 deletions opt/local/etc/opkg/opkg-openwrt-https.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
dest root /
dest ram /tmp
lists_dir ext /var/opkg-lists
option overlay_root /overlay
src/gz chaos_calmer_base https://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/packages/base
src/gz chaos_calmer_luci https://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/packages/luci
src/gz chaos_calmer_management https://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/packages/management
Expand Down
10 changes: 0 additions & 10 deletions opt/local/etc/opkg/opkg-reversiva-http.conf

This file was deleted.

39 changes: 29 additions & 10 deletions opt/local/etc/rc.bootstrap
Original file line number Diff line number Diff line change
@@ -1,36 +1,55 @@
#!/bin/sh

###
_CUR_SCRIPT='rc.bootstrap'
###


_FIRSTBOOT_FILE='/tmp/firstboot'
_BOOTSTRAP_PATH='/tmp/bootstrap'

if [ -f "$_FIRSTBOOT_FILE" ] ; then
_BUSYBOX=$( which busybox )
test -f "$_BOOTSTRAP_PATH" && rm "$_BOOTSTRAP_PATH"
test -d "$_BOOTSTRAP_PATH" || mkdir -p "$_BOOTSTRAP_PATH"

if [ "$?" -eq 0 ] ; then
_LOGIN_CMD=$( which /opt/local/bin/login || printf /bin/sh )
_CUR_CMD_PATH=$( which dropbear )

"$_BUSYBOX" telnetd -p 10023 -l "$_LOGIN_CMD"
if [ "$?" -eq 0 ] ; then
cp "${_CUR_CMD_PATH}" "${_BOOTSTRAP_PATH}/dropbear"

if [ -f "/opt/local/etc/dropbear/dropbear_rsa_host_key" ] ; then
cp /opt/local/etc/dropbear/dropbear_rsa_host_key "${_BOOTSTRAP_PATH}"
else
ln -s "${_BOOTSTRAP_PATH}/dropbear" "${_BOOTSTRAP_PATH}/dropbearkey"
"${_BOOTSTRAP_PATH}/dropbearkey" -t rsa -f "${_BOOTSTRAP_PATH}/dropbear_rsa_host_key" 2>&- >&-
fi

"${_BOOTSTRAP_PATH}/dropbear" \
-B -P "${_BOOTSTRAP_PATH}/dropbear.pid" -p 20022 -K 300 \
-r "${_BOOTSTRAP_PATH}/dropbear_rsa_host_key"
else
printf "!!! %s : %s\n" "$_CUR_SCRIPT" "busybox does not exist" 1>&2
printf '!!! %s : %s\n' "${_CUR_CMD_PATH##*/}" " does not exist" 1>&2
fi

unset _BUSYBOX
unset _CUR_CMD_PATH

_BOOTSTRAP=$( which /opt/local/bin/bootstrap )
_CUR_CMD_PATH=$( which /opt/local/bin/bootstrap )

if [ "$?" -eq 0 ] ; then
"$_BOOTSTRAP" 2>&1 | tee /tmp/bootstrap.log
"$_CUR_CMD_PATH" 2>&1 | tee "${_BOOTSTRAP_PATH}/bootstrap.log"
else
printf '!!! %s : %s\n' "${_CUR_CMD_PATH##*/}" " does not exist" 1>&2
fi

unset _BOOTSTRAP
unset _CUR_CMD_PATH

rm -f "$_FIRSTBOOT_FILE"
fi

unset _FIRSTBOOT_FILE
unset _FIRSTBOOT_FILE _BOOTSTRAP_PATH


###
unset _CUR_SCRIPT
###

44 changes: 41 additions & 3 deletions opt/local/lib/sys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,49 @@ disable_and_stop_daemon () {
check_not_empty_arguments "$FUN_NAME" "$DAEMON" || \
exit $EXIT_FAILURE

which "$DAEMON" >/dev/null && {
proctl initpath "$DAEMON" >/dev/null && {
printf ">> Disabling %s\n" "$DAEMON"
pidof "$DAEMON" >/dev/null && proctl stop "$DAEMON"
pidof "$DAEMON" >/dev/null && killall -9 "$DAEMON"
proctl enabled "$DAEMON" && proctl disable "$DAEMON"

printf ">> Stopping %s\n" "$DAEMON"
local PROGNAME=$( proctl progname "$DAEMON" )

if [ "$PROGNAME" == "" ] ; then
proctl stop "$DAEMON"
else
pidof "$PROGNAME" >/dev/null && proctl stop "$DAEMON"
fi
}

return $SUCCESS
}


disable_stop_and_kill_daemon () {
local FUN_NAME='disable_stop_and_kill_daemon'
local FUN_ARG_NUM='1'

check_num_arguments_equal_to "$FUN_NAME" "$FUN_ARG_NUM" "$#" || \
exit $EXIT_FAILURE

local DAEMON="$1"

check_not_empty_arguments "$FUN_NAME" "$DAEMON" || \
exit $EXIT_FAILURE

proctl initpath "$DAEMON" >/dev/null && {
printf ">> Disabling %s\n" "$DAEMON"
proctl enabled "$DAEMON" && proctl disable "$DAEMON"

printf ">> Stopping %s\n" "$DAEMON"
local PROGNAME=$( proctl progname "$DAEMON" )

if [ "$PROGNAME" == "" ] ; then
proctl stop "$DAEMON"
else
pidof "$PROGNAME" >/dev/null && proctl stop "$DAEMON"
pidof "$PROGNAME" >/dev/null && killall -9 "$PROGNAME"
fi
}

return $SUCCESS
Expand Down

0 comments on commit fecb406

Please sign in to comment.