Browse Source

initial commit

master
Sam Hunter 4 months ago
parent
commit
3c56793f61
  1. 126
      challenge

126
challenge

@ -0,0 +1,126 @@
#! /bin/bash
CHALLENGE="The Bare Necessities of Life 2021"
declare -i SCRIPT=0
CHALLENGEBIN="$HOME/shell2021"
declare -a ESSENTIALS=( awk bash cat chmod chown cp date ed env file find grep head ln ls mkdir mv ps rm sed sed sort stat stty tail tput tr uptime w who)
declare -a NETWORK=( ssh scp telnet w3m mail )
declare -a DEVEL=( )
declare -a RTC=( shlog )
declare -a LUXURY=( vim sftp )
create_scripts () {
echo "tput clear" > $CHALLENGEBIN/clear && chmod +x $CHALLENGEBIN/clear
((++SCRIPT))
echo "[ -n \"\$1\" ] && > \$1" > $CHALLENGEBIN/touch && chmod +x $CHALLENGEBIN/touch
((++SCRIPT))
cat <<-_gab_ > $CHALLENGEBIN/gab && chmod +x $CHALLENGEBIN/gab
#! $CHALLENGEBIN/bash
$(which python3) $(which gab) "\$@"
_gab_
((++SCRIPT))
cat <<-_who_ > $CHALLENGEBIN/who-is && chmod +x $CHALLENGEBIN/who-is
#! $CHALLENGEBIN/bash
$(which python3) $(which who-is) "\$@"
_who_
((++SCRIPT))
cat <<-_linkulator_ > $CHALLENGEBIN/linkulator && chmod +x $CHALLENGEBIN/linkulator
#! $CHALLENGEBIN/bash
$(which python3) $(which linkulator) "\$@"
_linkulator_
((++SCRIPT))
cat <<-_recent_ > $CHALLENGEBIN/recent && chmod +x $CHALLENGEBIN/recent
#! $CHALLENGEBIN/bash
PATH=/usr/bin:$CHALLENGEBIN $(which recent)
_recent_
((++SCRIPT))
cat <<-_iris_ > $CHALLENGEBIN/iris && chmod +x $CHALLENGEBIN/iris
#! $CHALLENGEBIN/bash
$(which ruby) $(which iris) "\$@"
_iris_
((++SCRIPT))
cat <<-_man_ > $CHALLENGEBIN/man && chmod +x $CHALLENGEBIN/man
#! $CHALLENGEBIN/bash
PATH=/bin:/usr/bin $(which man) "\$@"
_man_
((++SCRIPT))
cat <<-_nl_ > $CHALLENGEBIN/nl && chmod +x $CHALLENGEBIN/nl
#! $CHALLENGEBIN/bash
cat -n \$@
((++SCRIPT))
}
init () {
[ -d "$CHALLENGEBIN" ] || mkdir -p "$CHALLENGEBIN"
cd "$CHALLENGEBIN" && {
UTILS=( "${ESSENTIALS[@]}" "${NETWORK[@]}" "${DEVEL[@]}" "${RTC[@]}" "${LUXURY[@]}" )
for d in "${UTILS[@]}"; do
[ -x "$d" ] || ln -s $(which $d) "$CHALLENGEBIN"
done
create_scripts
cat <<-_profile_ > $CHALLENGEBIN/.profile
unset PROMPT_COMMAND
. <(typeset -f | awk '/\(\)/{printf("unset -f %s\n", \$1);}')
readonly PATH="$CHALLENGEBIN"
readonly PS1="$ "
readonly EDITOR=ed
export PATH PS1 EDITOR
_profile_
cat <<-_accept_ > $CHALLENGEBIN/accept
echo "Challenge started at $(date +"%Y-%m-%d %H:%M") // $LOGNAME@$HOSTNAME"
gab -c challenges\\! ; gab msg "Joined \"$CHALLENGE\" challenge."
[ -r $CHALLENGEBIN/.profile ] && $CHALLENGEBIN/bash --noprofile --init-file $CHALLENGEBIN/.profile
_accept_
chmod +x $CHALLENGEBIN/accept
cat <<-_addcmd_ > $CHALLENGEBIN/addcmd && chmod +x $CHALLENGEBIN/addcmd
#! /bin/bash
PATH="$HOME/bin:/usr/local/bin:/usr/bin:/bin"
[[ -n "\$1" && -n "\$(command -v "\$1")" ]] || exit 1
ln -s "\$(command -v "\$1")" "$CHALLENGEBIN/\$1" || exit 1
gab -c challenges\\! ; gab msg "Added \"\$1\""
_addcmd_
cat <<-_delcmd_ > $CHALLENGEBIN/delcmd && chmod +x $CHALLENGEBIN/delcmd
#! /bin/bash
rm -f "/home/samhunter/shell2021/\$1" || exit 1
gab -c challenges\\! ; gab msg "Removed \"\$1\""
_delcmd_
cat <<-_banner_
C H A L L E N G E
$CHALLENGE
Run "$CHALLENGEBIN/accept" to start your challenge with:
- ${#ESSENTIALS[@]} essentials;
- ${#NETWORK[@]} network tools;
- ${#DEVEL[@]} development tools;
- ${#RTC[@]} RTC tools;
- ${SCRIPT} scripts;
and ${#LUXURY[@]} luxury item(s).
_banner_
cd $HOME
}
}
accept() {
:
}
quit() {
:
}
init
Loading…
Cancel
Save