Skip to content

Commit

Permalink
Don't know how these snuck by... woopz
Browse files Browse the repository at this point in the history
  • Loading branch information
kangtastic committed Jun 7, 2018
1 parent a4823c1 commit 0a5d749
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 32 deletions.
64 changes: 34 additions & 30 deletions install-attnative6
Expand Up @@ -65,25 +65,25 @@ EOF
err() { echo "${B}$1${N}" >&2; }
die() { err "EXIT WITH ERROR: $1"; [ "$2" = "y" ] && help; exit 1; }
ask() {
read -p " ${B}$2:${N} " ans
printf "%s" " ${B}$2:${N} "; read ans
[ -z "$ans" ] && ans="$3"
eval $1=\$ans
eval "$1=\$ans"
}
confirm() {
ask t "Enter 'yes' exactly to confirm [default=no]"
[ "$t" = "yes" ] && eval $1=yes || eval $1=no
[ "$t" = "yes" ] && eval "$1=yes" || eval "$1=no"
}
checkvars() {
ret=0; msg=; tmp=
for n in $(seq 1 $#); do
vname=$(eval echo \$$n); vval=$(eval echo \$$vname)
vname=$(eval echo \$"$n"); vval=$(eval echo \$"$vname")
if [ -n "$vval" ]; then
[ -n "$msg" ] && msg="$msg, "; msg="$msg$vname='$vval'"; ret=$(($ret + 1))
[ -n "$msg" ] && msg="$msg, "; msg="$msg$vname='$vval'"; ret=$((ret + 1))
else
[ -n "$tmp" ] && tmp="$tmp, "; tmp="$tmp$vname"
fi
done
[ $ret -gt 0 ] && msg="(got $msg; need $tmp)" && echo $msg; return $ret
[ $ret -gt 0 ] && msg="(got $msg; need $tmp)" && echo "$msg"; return $ret
}
# this awk one-liner should be fully portable
ascii2hex() { echo "$*" | awk 'BEGIN{for(n=0;n<256;n++)ord[sprintf("%c",n)]=n}{len=split($0,c,"");for(i=1;i<=len;i++)printf("%X",ord[c[i]])}'; }
Expand Down Expand Up @@ -265,31 +265,32 @@ ${B}SUMMARY${N}
Install helper script ${B}$INSTH${N}
Clear dibbler's lease database ${B}$CLRDB${N}
EOF
}
generate() {
from_template() {
f="$1"; of="$2"
cp $f $of &&
sed -s "s|__INSTALLERPATH__|$(readlink -f $INSTALLERPATH)|" -i.bak $of &&
sed -e "s|__DATE__|$(date -R)|" -i.bak $of &&
sed -e "s|__WAN__|$WAN|" -i.bak $of &&
sed -e "s|__LAN__|$LAN|" -i.bak $of &&
sed -e "s|__DUIDEN__|$DUIDEN|" -i.bak $of &&
sed -e "s|__CONFPATH__|$CONFPATH|" -i.bak $of &&
sed -e "s|__HLPPATH__|$HLPPATH|" -i.bak $of &&
sed -e "s|__LOGPATH__|$LOGPATH|" -i.bak $of &&
sed -e "s|__BINDWAN__|$BINDWAN|" -i.bak $of &&
rm $of.bak || return 1
cp "$f" "$of" &&
sed -s "s|__INSTALLERPATH__|$(readlink -f "$INSTALLERPATH")|" -i.bak "$of" &&
sed -e "s|__DATE__|$(date -R)|" -i.bak "$of" &&
sed -e "s|__WAN__|$WAN|" -i.bak "$of" &&
sed -e "s|__LAN__|$LAN|" -i.bak "$of" &&
sed -e "s|__DUIDEN__|$DUIDEN|" -i.bak "$of" &&
sed -e "s|__CONFPATH__|$CONFPATH|" -i.bak "$of" &&
sed -e "s|__HLPPATH__|$HLPPATH|" -i.bak "$of" &&
sed -e "s|__LOGPATH__|$LOGPATH|" -i.bak "$of" &&
sed -e "s|__BINDWAN__|$BINDWAN|" -i.bak "$of" &&
rm "$of.bak" || return 1
}
[ "$MFG" = "1" ] && MFG="00D09E" || MFG="001E46"
DUIDEN=$(ascii2hex "$MFG-$SERIAL") && DUIDEN="0x$DUIDEN"

conf=$(echo $CONFTMPL | sed 's|.template||')
hlp=$(echo $HLPTMPL | sed 's|.template||')

from_template $CONFTMPL $conf && s_conf="Success" || s_conf="Failure"
from_template $HLPTMPL $hlp && s_hlp="Success" || s_hlp="Failure"
from_template "$CONFTMPL" "$conf" && s_conf="Success" || s_conf="Failure"
from_template "$HLPTMPL" "$hlp" && s_hlp="Success" || s_hlp="Failure"

cat << EOF
Expand Down Expand Up @@ -319,12 +320,12 @@ install() {
s_kill="N/A"
fi
if [ "$INSTC" = "yes" ]; then
mkdir -p "$CONFPATH" && mv $conf "$CONFPATH" && s_instc="Success"
mkdir -p "$CONFPATH" && mv "$conf" "$CONFPATH" && s_instc="Success"
else
s_instc="N/A"
fi
if [ "$INSTH" = "yes" ] && chmod +x $hlp; then
mkdir -p "$HLPPATH" && mv $hlp "$HLPPATH" && s_insth="Success"
if [ "$INSTH" = "yes" ] && chmod +x "$hlp"; then
mkdir -p "$HLPPATH" && mv "$hlp" "$HLPPATH" && s_insth="Success"
else
s_insth="N/A"
fi
Expand Down Expand Up @@ -354,8 +355,6 @@ EOF
# Options #
OPTS=$(getopt -o hw:l:m:s:qbic --long help,wan:,lan:,mfg:,serial:,quiet,bind-wan,conf-path:,hlp-path:,log-path:,install,install-conf,install-hlp,clear-leases -n 'parse-options' -- "$@")
[ $? != 0 ] && err "Failed to parse some options; ignoring"
# debug
#echo "$OPTS"
eval set -- "$OPTS"

while true; do
Expand Down Expand Up @@ -383,11 +382,13 @@ while true; do
done

# Sanity checks #
for f in $CONFTMPL $HLPTMPL; do [ -f $f ] || die "$f not found in $PWD"; done
for f in "$CONFTMPL" "$HLPTMPL"; do
[ -f "$f" ] || die "$f not found in $PWD"
done

[ -x "$(which dibbler-client)" ] && [ "$(whoami)" = "root" ] && ALLOWINST=yes
if [ "$ALLOWINST" != "yes" ]; then
for v in INSTC INSTH CLRDB; do eval $v=disabled; done
for v in INSTC INSTH CLRDB; do eval "$v=disabled"; done
err "Not root, or dibbler-client not found; installation functions disabled."
fi

Expand All @@ -411,17 +412,20 @@ cat << EOF
${B}Please confirm that the above summary is correct, or this installer will quit.${N}
EOF
confirm trigger; [ "$trigger" = "no" ] && echo && err "User quit." && exit
confirm trigger
if [ "$trigger" = "no" ]; then
printf "\n%s\n" "${B}User quit. Bye!${N}"; exit
fi
fi

generate || die "Failed during generation step."
install || die "Failed during installation step."

cat << EOF
Finished.
${B}FINISHED${N}
(Run 'systemctl restart dibbler-client' as root to start or restart the client
on a reasonably recent Linux.)
(Run 'systemctl restart dibbler-client' as root to start or restart the client
on a reasonably recent Linux.)
EOF
4 changes: 2 additions & 2 deletions pdsplit.sh.template
Expand Up @@ -59,7 +59,7 @@ replace_lan_gua() {
log "$msg" 1
else
ip -6 addr flush dev $LAN scope global &&
ip -6 addr add $GUA64 $LAN && log "$msg" 2 || die "$msg"
ip -6 addr add $GUA64 dev $LAN && log "$msg" 2 || die "$msg"
fi
}
# If 2600:1700:xxx0:xxx0::1/128 is not bound to WAN, add it.
Expand All @@ -68,7 +68,7 @@ add_wan_gua() {
if ip -6 -br addr show dev $IFACE | grep -q $GUA128; then
log "$msg" 1
else
ip -6 addr add $GUA128 $IFACE && log "$msg" 2 || die "$msg"
ip -6 addr add $GUA128 dev $IFACE && log "$msg" 2 || die "$msg"
fi
}
fixup_default_route() {
Expand Down

0 comments on commit 0a5d749

Please sign in to comment.