Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh -e
- ## DOSLDR - Damn, Open Source Literally Defines Rubbish
- ## gbsn
- ## public domain
- # --- #
- version="0.8"
- root="${HOME}/dosldr"
- config="${HOME}/dosbox.conf"
- device="/dev/sr0"
- editor="dte"
- password="80abf72386c3e5f475f3ab0ffc232c130300218c050912aa025c4a5ffdc934e4"
- mainmenu="\
- Choose an option:
- [s]elect a game
- [a]dmin menu
- [v]iew credits
- [q]uit"
- adminmenu="\
- Choose an option:
- [i]nstall a game
- [r]emove a game
- [g]ame config
- [d]osbox config
- [s]hutdown machine
- [q]uit to main menu"
- selectmenu="\
- Press Q to go back. Type a number and press ENTER to select.
- Press L for last page. Press R for next page.
- "
- removemenu="\
- WARNING: You are in the REMOVAL MENU
- If you are not supposed to be here, press Q
- ${selectmenu}"
- ident=' ___ ___ __ __ ___ ___ ___ __ __ ___ _ _ _ _
- | _ \/ __| \/ | | \ / _ \/ __| | \/ | __| \| | | | |
- | / (__| |\/| | | |) | (_) \__ \ | |\/| | _|| .` | |_| |
- |_|_\\\\___|_| |_| |___/ \___/|___/ |_| |_|___|_|\_|\___/'
- adminident=' ___ ___ __ __ ___ ___ ___ __ __ ___ _ _ _ _
- | _ \/ __| \/ | | \ / _ \/ __| | \/ | __| \| | | | |
- | / (__| |\/| | | |) | (_) \__ \ | |\/| | _|| .` | |_| |
- |_|_\\\\___|_| |_| |___/ \___/|___/ |_| |_|___|_|\_|\___/
- (admin mode)'
- # --- #
- die()
- {
- reset
- echo "$@" 1>&2
- exit 1
- }
- reexec()
- {
- clear
- exec "$0"
- }
- readb()
- {
- stty -icanon -echo
- input="$(dd count=1 bs=1 2> /dev/null)"
- stty icanon echo
- }
- info()
- {
- clear
- echo "${ident}"
- echo ""
- echo "$@"
- }
- error()
- {
- info "error: $@"
- echo ""
- echo "press a key to continue..."
- readb
- }
- errorr()
- {
- error "$@"
- reexec
- }
- prompt()
- {
- info "$@"
- echo ""
- printf ">>> "
- read input
- }
- menu()
- {
- info "$@"
- echo ""
- printf ">>> "
- readb
- }
- games()
- {
- for game in "${root}"/*
- do
- printf "${game##*/}\n"
- done | sort
- }
- gamesmenu()
- {
- page=0
- max=$(($(tput lines) - $(echo "$1" | wc -l) - $(echo "${ident}" | wc -l) - 4))
- while true
- do
- info "$1"
- i=0
- n1=$((page * max + 1))
- n2=$(((page + 1) * max))
- set +e
- games | sed -n "${n1},${n2}p" | while read game
- do
- echo " ${i} - ${game}"
- i=$((i+1))
- [ ${i} -ge ${max} ] && break
- done
- set -e
- echo ""
- printf ">>> "
- while true
- do
- readb
- case "${input}" in
- 0|1|2|3|4|5|6|7|8|9)
- n="${input}"
- printf "\r>>> ${n}"
- while true
- do
- readb
- hex="$(echo "${input}" | xxd -p | cut -b1,2)"
- [ "${hex}" = "7f" -o "${hex}" = "08" ] && n=${n%?} &&
- if [ -z "${n}" ]
- then
- continue 3
- else
- printf "\r>>> ${n} \r>>> ${n}"
- continue
- fi
- [ "${hex}" = "0a" ] && break
- [ 48 -le "$((0x${hex}))" -a "$((0x${hex}))" -le 57 ] && n="${n}${input}" && printf "\r>>> ${n}"
- done
- break
- ;;
- l|L)
- [ "${page}" -gt 0 ] && page=$((page - 1)) && continue 2
- ;;
- r|R)
- [ "$(games | wc -l)" -ge $(((page + 1) * max)) ] && page=$((page + 1)) && continue 2
- ;;
- q|Q) break 2 ;;
- esac
- done
- if ! [ "${n}" -ge 0 ]
- then
- error "invalid game id"
- continue
- fi
- game=$(games | sed -n $((page * max + n + 1))p)
- [ -z "${game}" ] && error "invalid game id" && continue
- break
- done
- }
- # --- #
- mkdir -p "${root}"
- menu "${mainmenu}"
- case "${input}" in
- s)
- gamesmenu "${selectmenu}"
- if [ ! -z "${game}" ]
- then
- [ -e "${config}" ] || errorr "global config not found"
- [ -e "${root}/${game}/conf" ] || errorr "config for ${game} not found"
- [ -e "${root}/${game}/iso" ] || errorr "image for ${game} not found"
- [ -d "${root}/${game}/drive" ] || errorr "drive for ${game} not found"
- clear
- dosbox -conf "${config}" -conf "${root}/${game}/conf"
- fi
- reexec
- ;;
- a)
- stty -echo
- prompt "enter admin password (blank to abort): "
- stty echo
- [ "${input}" ] || reexec
- [ "$(echo "${input}" | sha256sum | cut -d' ' -f1)" != "${password}" ] && errorr "invalid password"
- ident="${adminident}"
- while true
- do
- menu "${adminmenu}"
- case "${input}" in
- i)
- info "Installing"
- while true
- do
- prompt "Enter game name (blank to abort)"
- name="${input}"
- [ -z "${name}" ] && reexec
- [ -e "${root}/${input}" ] && error "${input} already installed" && continue
- break
- done
- echo ""
- echo "Insert disk and press enter (q to abort)"
- readb
- [ "${input}" = q -o "${input}" = Q ] && reexec
- info "Installing ${name}"
- echo ""
- echo "Creating game files..."
- mkdir "${root}/${name}"
- cd "${root}/${name}"
- mkdir "drive"
- cat > "conf" << EOF
- [autoexec]
- @ECHO OFF
- MOUNT C "${root}/${game}/drive"
- IMGMOUNT D "${root}/${game}/cue" -t iso
- CLS
- :: add game load here
- EXIT
- EOF
- echo "Creating disk image..."
- sudo cdrdao read-cd --read-raw --driver generic-mmc:0x20000 --device "${device}" --datafile bin toc
- sudo toc2cue toc cue
- sudo rm toc
- sudo chown $(id -u):$(id -g) bin cue
- cd -
- echo ""
- echo "Enter DOSBOX? [Y/n] "
- readb
- [ "${input}" != "n" -a "${input}" != "N" ] && dosbox -conf "${config}" -c "MOUNT C \"${root}/${game}/drive\"" -c "IMGMOUNT D \"${root}/${game}/cue\" -t iso"
- echo "Edit config? (HIGHLY recommended) [Y/n] "
- readb
- [ "${input}" != "n" -a "${input}" != "N" ] && ${editor} "${root}/${name}/conf"
- echo ""
- echo "Installation complete"
- echo "Press a key"
- readb
- reexec
- ;;
- r)
- gamesmenu "${removemenu}"
- if [ ! -z "${game}" ]
- then
- prompt "Are you SURE you want to remove ${game}? [reenter password to confirm]"
- [ ! "$(echo ${input} | sha256sum | cut -d' ' -f1)" = "${password}" ] && error "invalid password, aborting" && continue
- rm -r "${root}/${game}"
- fi
- ;;
- g)
- gamesmenu "${selectmenu}"
- if [ ! -z "${game}" ]
- then
- ${editor} "${root}/${game}/conf"
- fi
- ;;
- d)
- ${editor} "${config}"
- ;;
- s)
- sudo init 0
- ;;
- q)
- reexec
- ;;
- esac
- done
- ;;
- v)
- clear
- echo "\
- === DOSLDR/${version} ===
- George Programming
- RCM Other stuff
- The Internet Advice
- DOSBOX Team Creating DOSBOX
- Launchbox Needing a replacement
- Visit the Retro Computer Museum online -- https://retrocomputermuseum.co.uk/
- View my other things -- https://tty0.xyz/
- "
- readb
- reexec
- ;;
- q)
- echo
- exit 0
- ;;
- *) reexec ;;
- esac
- # --- #
- #############
- # CHANGELOG #
- #############
- #
- # 0.8 (2019-04-21)
- # install: fix ripping
- # games: prevent typing invalid characters after entering a number
- # games: use ${hex} consistently
- # admin: add option to shutdown machine
- #
- # 0.7 (2019-04-18)
- # admin: create administration menu
- # admin: add option to edit config files
- # remove: create removal menu in admin menu
- # install: move to admin menu
- # install: fix typo
- # dosbox: new global config file
- # main: add quit option to main menu
- # ui: show different ident in admin menu
- #
- # 0.6 (2019-04-17)
- # select: move game menu to seperate function
- # games: proper backspace handling
- # games: clean break/continue statements
- # games: calculate ${max} properly
- # install: slightly better UI
- # credits: less calls to echo
- # credits: credit the internet
- # credits: shameless self promotion
- #
- # 0.5 (2019-04-16)
- # dosldr: reorganise ${root}
- # dosbox: use userconf instead of global config
- # games: remove need for catalog file
- # ui: new functions for erroring
- #
- # 0.4 (2019-04-15)
- # ui: new ui system
- # install: rip to bin+cue instead of iso
- # install: better default config
- # dosbox: add global config file
- # credits: more detailed credits
- #
- # 0.3 (2019-04-14)
- # install: create installation menu
- # select: add backspace handling
- # credits: create credits
- #
- # 0.2 (2019-04-13)
- # select: fix pages
- # select: configurable games per page
- # select: remove unreachable branch
- #
- # 0.1 (2019-04-12)
- # create dosldr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement