From fecb406fd277c2f4a8dea558c712ef842b12ef39 Mon Sep 17 00:00:00 2001 From: Giorgio Marinelli Date: Wed, 10 May 2017 18:56:11 +0200 Subject: [PATCH] 20150909 --- opt/local/bin/bootstrap | 43 ++++++-------------- opt/local/bin/check-openwrt-mirror | 24 +++++------ opt/local/bin/proctl | 41 ++++++++++++++++--- opt/local/etc/opkg.conf | 1 - opt/local/etc/opkg/distfeeds.conf | 1 + opt/local/etc/opkg/opkg-brrr-https.conf | 6 +++ opt/local/etc/opkg/opkg-garr-http.conf | 4 -- opt/local/etc/opkg/opkg-openwrt-http.conf | 4 -- opt/local/etc/opkg/opkg-openwrt-https.conf | 4 -- opt/local/etc/opkg/opkg-reversiva-http.conf | 10 ----- opt/local/etc/rc.bootstrap | 39 +++++++++++++----- opt/local/lib/sys.sh | 44 +++++++++++++++++++-- 12 files changed, 136 insertions(+), 85 deletions(-) delete mode 120000 opt/local/etc/opkg.conf create mode 120000 opt/local/etc/opkg/distfeeds.conf create mode 100644 opt/local/etc/opkg/opkg-brrr-https.conf delete mode 100644 opt/local/etc/opkg/opkg-reversiva-http.conf diff --git a/opt/local/bin/bootstrap b/opt/local/bin/bootstrap index 494d0a8..dfa401f 100755 --- a/opt/local/bin/bootstrap +++ b/opt/local/bin/bootstrap @@ -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 @@ -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 @@ -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 @@ -95,6 +74,7 @@ proctl start sshd ## dnsmasq pkg_installed dnsmasq && pkg_remove dnsmasq + pkg_install dnsmasq-full disable_and_stop_daemon dnsmasq @@ -151,4 +131,5 @@ pkg_remove \ dns_temp_disable proctl reload network +proctl reload firewall diff --git a/opt/local/bin/check-openwrt-mirror b/opt/local/bin/check-openwrt-mirror index 36c45f7..e93fa23 100755 --- a/opt/local/bin/check-openwrt-mirror +++ b/opt/local/bin/check-openwrt-mirror @@ -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 @@ -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" diff --git a/opt/local/bin/proctl b/opt/local/bin/proctl index 6d3d908..32ece25 100755 --- a/opt/local/bin/proctl +++ b/opt/local/bin/proctl @@ -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 \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" + diff --git a/opt/local/etc/opkg.conf b/opt/local/etc/opkg.conf deleted file mode 120000 index d9d7675..0000000 --- a/opt/local/etc/opkg.conf +++ /dev/null @@ -1 +0,0 @@ -opkg/opkg-garr-http.conf \ No newline at end of file diff --git a/opt/local/etc/opkg/distfeeds.conf b/opt/local/etc/opkg/distfeeds.conf new file mode 120000 index 0000000..76875f2 --- /dev/null +++ b/opt/local/etc/opkg/distfeeds.conf @@ -0,0 +1 @@ +opkg-garr-http.conf \ No newline at end of file diff --git a/opt/local/etc/opkg/opkg-brrr-https.conf b/opt/local/etc/opkg/opkg-brrr-https.conf new file mode 100644 index 0000000..f5652ae --- /dev/null +++ b/opt/local/etc/opkg/opkg-brrr-https.conf @@ -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 diff --git a/opt/local/etc/opkg/opkg-garr-http.conf b/opt/local/etc/opkg/opkg-garr-http.conf index 4d39ddc..7fa8e88 100644 --- a/opt/local/etc/opkg/opkg-garr-http.conf +++ b/opt/local/etc/opkg/opkg-garr-http.conf @@ -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 diff --git a/opt/local/etc/opkg/opkg-openwrt-http.conf b/opt/local/etc/opkg/opkg-openwrt-http.conf index da0dfc6..25947c0 100644 --- a/opt/local/etc/opkg/opkg-openwrt-http.conf +++ b/opt/local/etc/opkg/opkg-openwrt-http.conf @@ -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 diff --git a/opt/local/etc/opkg/opkg-openwrt-https.conf b/opt/local/etc/opkg/opkg-openwrt-https.conf index d55bcf7..b1b65ea 100644 --- a/opt/local/etc/opkg/opkg-openwrt-https.conf +++ b/opt/local/etc/opkg/opkg-openwrt-https.conf @@ -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 diff --git a/opt/local/etc/opkg/opkg-reversiva-http.conf b/opt/local/etc/opkg/opkg-reversiva-http.conf deleted file mode 100644 index f022623..0000000 --- a/opt/local/etc/opkg/opkg-reversiva-http.conf +++ /dev/null @@ -1,10 +0,0 @@ -dest root / -dest ram /tmp -lists_dir ext /var/opkg-lists -option overlay_root /overlay -src/gz chaos_calmer_base http://reversiva.net:10080/openwrt/snapshots/trunk/ar71xx/generic/packages/base -src/gz chaos_calmer_luci http://reversiva.net:10080/openwrt/snapshots/trunk/ar71xx/generic/packages/luci -src/gz chaos_calmer_management http://reversiva.net:10080/openwrt/snapshots/trunk/ar71xx/generic/packages/management -src/gz chaos_calmer_packages http://reversiva.net:10080/openwrt/snapshots/trunk/ar71xx/generic/packages/packages -src/gz chaos_calmer_routing http://reversiva.net:10080/openwrt/snapshots/trunk/ar71xx/generic/packages/routing -src/gz chaos_calmer_telephony http://reversiva.net:10080/openwrt/snapshots/trunk/ar71xx/generic/packages/telephony diff --git a/opt/local/etc/rc.bootstrap b/opt/local/etc/rc.bootstrap index 9c507b4..3f297c0 100644 --- a/opt/local/etc/rc.bootstrap +++ b/opt/local/etc/rc.bootstrap @@ -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 +### diff --git a/opt/local/lib/sys.sh b/opt/local/lib/sys.sh index 81e0857..542065e 100644 --- a/opt/local/lib/sys.sh +++ b/opt/local/lib/sys.sh @@ -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