Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.14 KB | None | 0 0
  1. #!/bin/sh -e
  2.  
  3. ## DOSLDR - Damn, Open Source Literally Defines Rubbish
  4. ## gbsn
  5. ## public domain
  6.  
  7. # --- #
  8.  
  9. version="0.8"
  10.  
  11. root="${HOME}/dosldr"
  12. config="${HOME}/dosbox.conf"
  13. device="/dev/sr0"
  14. editor="dte"
  15.  
  16. password="80abf72386c3e5f475f3ab0ffc232c130300218c050912aa025c4a5ffdc934e4"
  17.  
  18. mainmenu="\
  19. Choose an option:
  20. [s]elect a game
  21. [a]dmin menu
  22. [v]iew credits
  23. [q]uit"
  24.  
  25. adminmenu="\
  26. Choose an option:
  27. [i]nstall a game
  28. [r]emove a game
  29. [g]ame config
  30. [d]osbox config
  31. [s]hutdown machine
  32. [q]uit to main menu"
  33.  
  34. selectmenu="\
  35. Press Q to go back. Type a number and press ENTER to select.
  36. Press L for last page. Press R for next page.
  37. "
  38.  
  39. removemenu="\
  40. WARNING: You are in the REMOVAL MENU
  41. If you are not supposed to be here, press Q
  42.  
  43. ${selectmenu}"
  44.  
  45. ident=' ___ ___ __ __ ___ ___ ___ __ __ ___ _ _ _ _
  46. | _ \/ __| \/ | | \ / _ \/ __| | \/ | __| \| | | | |
  47. | / (__| |\/| | | |) | (_) \__ \ | |\/| | _|| .` | |_| |
  48. |_|_\\\\___|_| |_| |___/ \___/|___/ |_| |_|___|_|\_|\___/'
  49.  
  50. adminident=' ___ ___ __ __ ___ ___ ___ __ __ ___ _ _ _ _
  51. | _ \/ __| \/ | | \ / _ \/ __| | \/ | __| \| | | | |
  52. | / (__| |\/| | | |) | (_) \__ \ | |\/| | _|| .` | |_| |
  53. |_|_\\\\___|_| |_| |___/ \___/|___/ |_| |_|___|_|\_|\___/
  54.  
  55. (admin mode)'
  56.  
  57. # --- #
  58.  
  59. die()
  60. {
  61. reset
  62. echo "$@" 1>&2
  63. exit 1
  64. }
  65.  
  66. reexec()
  67. {
  68. clear
  69. exec "$0"
  70. }
  71.  
  72. readb()
  73. {
  74. stty -icanon -echo
  75. input="$(dd count=1 bs=1 2> /dev/null)"
  76. stty icanon echo
  77. }
  78.  
  79. info()
  80. {
  81. clear
  82. echo "${ident}"
  83. echo ""
  84. echo "$@"
  85. }
  86.  
  87. error()
  88. {
  89. info "error: $@"
  90. echo ""
  91. echo "press a key to continue..."
  92. readb
  93. }
  94.  
  95. errorr()
  96. {
  97. error "$@"
  98. reexec
  99. }
  100.  
  101. prompt()
  102. {
  103. info "$@"
  104. echo ""
  105. printf ">>> "
  106. read input
  107. }
  108.  
  109. menu()
  110. {
  111. info "$@"
  112. echo ""
  113. printf ">>> "
  114. readb
  115. }
  116.  
  117. games()
  118. {
  119. for game in "${root}"/*
  120. do
  121. printf "${game##*/}\n"
  122. done | sort
  123. }
  124.  
  125. gamesmenu()
  126. {
  127. page=0
  128. max=$(($(tput lines) - $(echo "$1" | wc -l) - $(echo "${ident}" | wc -l) - 4))
  129. while true
  130. do
  131. info "$1"
  132.  
  133. i=0
  134. n1=$((page * max + 1))
  135. n2=$(((page + 1) * max))
  136.  
  137. set +e
  138. games | sed -n "${n1},${n2}p" | while read game
  139. do
  140. echo " ${i} - ${game}"
  141. i=$((i+1))
  142. [ ${i} -ge ${max} ] && break
  143. done
  144. set -e
  145.  
  146. echo ""
  147. printf ">>> "
  148.  
  149. while true
  150. do
  151. readb
  152. case "${input}" in
  153. 0|1|2|3|4|5|6|7|8|9)
  154. n="${input}"
  155. printf "\r>>> ${n}"
  156. while true
  157. do
  158. readb
  159. hex="$(echo "${input}" | xxd -p | cut -b1,2)"
  160. [ "${hex}" = "7f" -o "${hex}" = "08" ] && n=${n%?} &&
  161. if [ -z "${n}" ]
  162. then
  163. continue 3
  164. else
  165. printf "\r>>> ${n} \r>>> ${n}"
  166. continue
  167. fi
  168. [ "${hex}" = "0a" ] && break
  169. [ 48 -le "$((0x${hex}))" -a "$((0x${hex}))" -le 57 ] && n="${n}${input}" && printf "\r>>> ${n}"
  170. done
  171. break
  172. ;;
  173. l|L)
  174. [ "${page}" -gt 0 ] && page=$((page - 1)) && continue 2
  175. ;;
  176. r|R)
  177. [ "$(games | wc -l)" -ge $(((page + 1) * max)) ] && page=$((page + 1)) && continue 2
  178. ;;
  179. q|Q) break 2 ;;
  180. esac
  181. done
  182.  
  183. if ! [ "${n}" -ge 0 ]
  184. then
  185. error "invalid game id"
  186. continue
  187. fi
  188. game=$(games | sed -n $((page * max + n + 1))p)
  189. [ -z "${game}" ] && error "invalid game id" && continue
  190. break
  191. done
  192. }
  193.  
  194. # --- #
  195.  
  196. mkdir -p "${root}"
  197.  
  198. menu "${mainmenu}"
  199. case "${input}" in
  200. s)
  201. gamesmenu "${selectmenu}"
  202. if [ ! -z "${game}" ]
  203. then
  204. [ -e "${config}" ] || errorr "global config not found"
  205. [ -e "${root}/${game}/conf" ] || errorr "config for ${game} not found"
  206. [ -e "${root}/${game}/iso" ] || errorr "image for ${game} not found"
  207. [ -d "${root}/${game}/drive" ] || errorr "drive for ${game} not found"
  208. clear
  209. dosbox -conf "${config}" -conf "${root}/${game}/conf"
  210. fi
  211. reexec
  212. ;;
  213. a)
  214. stty -echo
  215. prompt "enter admin password (blank to abort): "
  216. stty echo
  217. [ "${input}" ] || reexec
  218. [ "$(echo "${input}" | sha256sum | cut -d' ' -f1)" != "${password}" ] && errorr "invalid password"
  219.  
  220. ident="${adminident}"
  221.  
  222. while true
  223. do
  224. menu "${adminmenu}"
  225. case "${input}" in
  226. i)
  227. info "Installing"
  228. while true
  229. do
  230. prompt "Enter game name (blank to abort)"
  231. name="${input}"
  232. [ -z "${name}" ] && reexec
  233. [ -e "${root}/${input}" ] && error "${input} already installed" && continue
  234. break
  235. done
  236.  
  237. echo ""
  238. echo "Insert disk and press enter (q to abort)"
  239. readb
  240. [ "${input}" = q -o "${input}" = Q ] && reexec
  241. info "Installing ${name}"
  242.  
  243. echo ""
  244. echo "Creating game files..."
  245. mkdir "${root}/${name}"
  246. cd "${root}/${name}"
  247. mkdir "drive"
  248. cat > "conf" << EOF
  249. [autoexec]
  250. @ECHO OFF
  251. MOUNT C "${root}/${game}/drive"
  252. IMGMOUNT D "${root}/${game}/cue" -t iso
  253. CLS
  254. :: add game load here
  255. EXIT
  256. EOF
  257.  
  258. echo "Creating disk image..."
  259. sudo cdrdao read-cd --read-raw --driver generic-mmc:0x20000 --device "${device}" --datafile bin toc
  260. sudo toc2cue toc cue
  261. sudo rm toc
  262. sudo chown $(id -u):$(id -g) bin cue
  263. cd -
  264.  
  265. echo ""
  266. echo "Enter DOSBOX? [Y/n] "
  267. readb
  268. [ "${input}" != "n" -a "${input}" != "N" ] && dosbox -conf "${config}" -c "MOUNT C \"${root}/${game}/drive\"" -c "IMGMOUNT D \"${root}/${game}/cue\" -t iso"
  269.  
  270. echo "Edit config? (HIGHLY recommended) [Y/n] "
  271. readb
  272. [ "${input}" != "n" -a "${input}" != "N" ] && ${editor} "${root}/${name}/conf"
  273.  
  274. echo ""
  275. echo "Installation complete"
  276. echo "Press a key"
  277. readb
  278. reexec
  279. ;;
  280. r)
  281. gamesmenu "${removemenu}"
  282. if [ ! -z "${game}" ]
  283. then
  284. prompt "Are you SURE you want to remove ${game}? [reenter password to confirm]"
  285. [ ! "$(echo ${input} | sha256sum | cut -d' ' -f1)" = "${password}" ] && error "invalid password, aborting" && continue
  286. rm -r "${root}/${game}"
  287. fi
  288. ;;
  289. g)
  290. gamesmenu "${selectmenu}"
  291. if [ ! -z "${game}" ]
  292. then
  293. ${editor} "${root}/${game}/conf"
  294. fi
  295. ;;
  296. d)
  297. ${editor} "${config}"
  298. ;;
  299. s)
  300. sudo init 0
  301. ;;
  302. q)
  303. reexec
  304. ;;
  305. esac
  306. done
  307. ;;
  308. v)
  309. clear
  310. echo "\
  311. === DOSLDR/${version} ===
  312.  
  313. George Programming
  314. RCM Other stuff
  315. The Internet Advice
  316. DOSBOX Team Creating DOSBOX
  317. Launchbox Needing a replacement
  318.  
  319. Visit the Retro Computer Museum online -- https://retrocomputermuseum.co.uk/
  320. View my other things -- https://tty0.xyz/
  321. "
  322. readb
  323. reexec
  324. ;;
  325. q)
  326. echo
  327. exit 0
  328. ;;
  329. *) reexec ;;
  330. esac
  331.  
  332. # --- #
  333.  
  334. #############
  335. # CHANGELOG #
  336. #############
  337. #
  338. # 0.8 (2019-04-21)
  339. # install: fix ripping
  340. # games: prevent typing invalid characters after entering a number
  341. # games: use ${hex} consistently
  342. # admin: add option to shutdown machine
  343. #
  344. # 0.7 (2019-04-18)
  345. # admin: create administration menu
  346. # admin: add option to edit config files
  347. # remove: create removal menu in admin menu
  348. # install: move to admin menu
  349. # install: fix typo
  350. # dosbox: new global config file
  351. # main: add quit option to main menu
  352. # ui: show different ident in admin menu
  353. #
  354. # 0.6 (2019-04-17)
  355. # select: move game menu to seperate function
  356. # games: proper backspace handling
  357. # games: clean break/continue statements
  358. # games: calculate ${max} properly
  359. # install: slightly better UI
  360. # credits: less calls to echo
  361. # credits: credit the internet
  362. # credits: shameless self promotion
  363. #
  364. # 0.5 (2019-04-16)
  365. # dosldr: reorganise ${root}
  366. # dosbox: use userconf instead of global config
  367. # games: remove need for catalog file
  368. # ui: new functions for erroring
  369. #
  370. # 0.4 (2019-04-15)
  371. # ui: new ui system
  372. # install: rip to bin+cue instead of iso
  373. # install: better default config
  374. # dosbox: add global config file
  375. # credits: more detailed credits
  376. #
  377. # 0.3 (2019-04-14)
  378. # install: create installation menu
  379. # select: add backspace handling
  380. # credits: create credits
  381. #
  382. # 0.2 (2019-04-13)
  383. # select: fix pages
  384. # select: configurable games per page
  385. # select: remove unreachable branch
  386. #
  387. # 0.1 (2019-04-12)
  388. # create dosldr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement