Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.05 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. Start() {
  4.  
  5. if "$Online" && [ "$USER" != "plg" ]; then
  6. SendStats
  7. fi
  8.  
  9. if "$MinimalMode"; then
  10. if [ "$BackupAt" == "All" ] || [ "$BackupAt" == "Start" ]; then
  11. ./script/Utilities.sh Backup Start
  12. fi
  13.  
  14. java -server -Xms512M -Xmx$RAM -jar $jar $mode $arguments
  15. echo
  16.  
  17. if [ "$BackupAt" == "All" ] || [ "$BackupAt" == "Stop" ]; then
  18. ./script/Utilities.sh Backup Stop
  19. fi
  20.  
  21. rm -rf ./script/temp
  22.  
  23. else
  24. if [ ! -f ./script/temp/dummies/_Closed ]; then
  25. if "$Schedule"; then
  26. touch ./script/temp/dummies/_Schedule
  27. if [ ! -f server.log.lck ]; then
  28. mv -f ./server.log ./script/temp/server.log
  29. fi
  30.  
  31. if "$RAMDisk"; then
  32. if "$Linux"; then
  33. SudoAuthorization "to mount the RAMDisk"
  34. fi
  35. touch ./script/temp/dummies/_RAMDisk
  36. ./script/Utilities.sh RAMDisk Mount
  37. fi
  38.  
  39. screen -dmS Minecraft-Schedule -c ./script/temp/screen/Schedule.conf
  40.  
  41. elif [ ! -f server.log.lck ]; then
  42. mv -f ./server.log ./script/temp/server.log
  43.  
  44. if ! "$RAMDisk"; then
  45. screen -dmS "$ServerScreen" -c ./script/temp/screen/Server.conf
  46.  
  47. else
  48. if "$Linux"; then
  49. SudoAuthorization "to mount the RAMDisk"
  50. fi
  51. touch ./script/temp/dummies/_RAMDisk
  52. ./script/Utilities.sh RAMDisk Mount
  53.  
  54. screen -dmS "$ServerScreen" -c ./script/temp/screen/Server.conf
  55. fi
  56. fi
  57. else
  58. rm -rf ./script/temp/dummies/_Closed
  59. fi
  60.  
  61. clear
  62. screen -S GTB-Script -c ./script/temp/screen/Main.conf
  63.  
  64. if [ -f ./script/temp/dummies/_Closed ]; then
  65. echo -e "${Blue}Resume the script be relaunching it${None}"
  66. exit
  67. fi
  68.  
  69. if "$RAMDisk"; then
  70. if "$Linux"; then
  71. SudoAuthorization "to unmount the RAMDisk"
  72. fi
  73. ./script/Utilities.sh RAMDisk Eject
  74. fi
  75.  
  76. fi
  77. }
  78.  
  79. Daemon() {
  80. if [ "$1" == "--start" ]; then
  81. if [ ! -f server.log.lck ] && [ -z "$(screen -ls | grep "$ServerScreen")" ]; then
  82. screen -dmS "$ServerScreen" -c ./script/temp/screen/Server.conf
  83. echo "The server was started"
  84. else
  85. echo "The server is already running"
  86. fi
  87.  
  88. elif [ "$1" == "--stop" ]; then
  89. if [ -f server.log.lck ] && [ ! -z "$(screen -ls | grep "$ServerScreen")" ]; then
  90. screen -S "$ServerScreen" -p 1 -X eval "stuff 'stop'\015"
  91. rm -rf ./script/temp
  92. echo "The server was stopped"
  93. else
  94. echo "The server is not running"
  95. fi
  96.  
  97. fi
  98.  
  99. exit
  100. }
  101.  
  102. ExportVars() {
  103. echo "AfterRestart='$AfterRestart'" > ./script/temp/vars.conf
  104. echo "arguments='$arguments'" >> ./script/temp/vars.conf
  105. echo "BackupAt='$BackupAt'" >> ./script/temp/vars.conf
  106. echo "BackupInterval='$BackupInterval'" >> ./script/temp/vars.conf
  107. echo "BackupLimit='$BackupLimit'" >> ./script/temp/vars.conf
  108. echo "BackupList='$BackupList'" >> ./script/temp/vars.conf
  109. echo "BackupPlugins='$BackupPlugins'" >> ./script/temp/vars.conf
  110. echo "Backups='$Backups'" >> ./script/temp/vars.conf
  111. echo "BackupTime='$BackupTime'" >> ./script/temp/vars.conf
  112. echo "BeforeRestart='$BeforeRestart'" >> ./script/temp/vars.conf
  113. echo "Columns='$Columns'" >> ./script/temp/vars.conf
  114. echo "CommandPrefix='$CommandPrefix'" >> ./script/temp/vars.conf
  115. echo "CompressBackups='$CompressBackups'" >> ./script/temp/vars.conf
  116. echo "Debian='$Debian'" >> ./script/temp/vars.conf
  117. echo "jar='$jar'" >> ./script/temp/vars.conf
  118. echo "Jar='$Jar'" >> ./script/temp/vars.conf
  119. echo "LauncherUpToDate='$LauncherUpToDate'" >> ./script/temp/vars.conf
  120. echo "Link='$Link'" >> ./script/temp/vars.conf
  121. echo "Linux='$Linux'" >> ./script/temp/vars.conf
  122. echo "MenuLines='$MenuLines'" >> ./script/temp/vars.conf
  123. echo "mode='$mode'" >> ./script/temp/vars.conf
  124. echo "Online='$Online'" >> ./script/temp/vars.conf
  125. echo "OnlyScheduled='$OnlyScheduled'" >> ./script/temp/vars.conf
  126. echo "RAM='$RAM'" >> ./script/temp/vars.conf
  127. echo "RAMDisk='$RAMDisk'" >> ./script/temp/vars.conf
  128. echo "RAMDiskList='$RAMDiskList'" >> ./script/temp/vars.conf
  129. echo "RestartInterval='$RestartInterval'" >> ./script/temp/vars.conf
  130. echo "Schedule='$Schedule'" >> ./script/temp/vars.conf
  131. echo "ServerScreen='$ServerScreen'" >> ./script/temp/vars.conf
  132. echo "ServerUpToDate='$ServerUpToDate'" >> ./script/temp/vars.conf
  133. echo "ServerVersion='$ServerVersion'" >> ./script/temp/vars.conf
  134. echo "MinimalMode='$MinimalMode'" >> ./script/temp/vars.conf
  135. echo "StartTime='$StartTime'" >> ./script/temp/vars.conf
  136. echo "StopTime='$StopTime'" >> ./script/temp/vars.conf
  137. echo "Tip='$Tip'" >> ./script/temp/vars.conf
  138. echo "ThisVersion='$ThisVersion'" >> ./script/temp/vars.conf
  139. echo "Ubuntu='$Ubuntu'" >> ./script/temp/vars.conf
  140. echo "ViewLines='$ViewLines'" >> ./script/temp/vars.conf
  141. echo "World='$World'" >> ./script/temp/vars.conf
  142. echo "WorldName='$WorldName'" >> ./script/temp/vars.conf
  143.  
  144. if [ "$BackupInterval" != "00:00" ]; then
  145. echo "BackupTime='$(./script/Utlilites.sh In $BackupInterval)'" >> ./script/temp/vars.conf
  146. else
  147. echo "BackupTime='never'" >> ./script/temp/vars.conf
  148. fi
  149. }
  150.  
  151. ServerVersion() {
  152. if [ -f "$jar" ]; then
  153. if [ "$jar" == "CraftBukkit.jar" ]; then
  154. ServerVersion=$(java -jar "$jar" -v | cut -d '-' -f 3,4)
  155. elif [ "$jar" == "SpiGot.jar" ]; then
  156. ServerVersion=$(java -jar "$jar" -v | cut -d '-' -f 4,5)
  157. else
  158. if "$Online"; then
  159. ServerVersion=$(curl -s http://mcupdate.tumblr.com | grep 'Permanent link for this post' | \
  160. sed -n 1p | cut -d '/' -f 6 | cut -d '"' -f 1 | cut -d "-" -f 2-10 | sed 's/-/./g')
  161. else
  162. ServerVersion="offline"
  163. fi
  164. fi
  165. fi
  166. }
  167.  
  168. ReadConfig() {
  169. ServerScreen="GTB-Server"
  170. source LaunchServer.properties
  171. CheckConfig
  172.  
  173. if [ "$1" == "--start" ] || [ "$1" == "--stop" ] || [ "$1" == "--help" ]; then
  174. Daemon=true
  175. else
  176. Daemon=false
  177. fi
  178.  
  179. if ! "$MinimalMode" && ! "$Daemon"; then
  180. echo -e "${Blue}Loading...${None}"
  181. tput civis
  182. fi
  183.  
  184. jar="$Jar.jar"
  185.  
  186. if ! "$Backups"; then
  187. BackupAt='None'
  188. BackupInterval='00:00'
  189. BackupTime='never'
  190. fi
  191.  
  192. WorldName="$(grep level-name server.properties | cut -d '=' -f 2)"
  193. if [ -z "$WorldName" ]; then
  194. WorldName=world
  195. fi
  196. World="./$WorldName"
  197.  
  198. Online=true
  199. mode="-o true"
  200. if [ -z "$SSH_CLIENT" ]; then
  201. ping -t 1 -c 1 google.com > /dev/null 2>&1
  202. if [ "$?" -ne 0 ]; then
  203. ping -c 1 awardspace.com > /dev/null 2>&1
  204. if [ "$?" -ne 0 ]; then
  205. Online=false
  206. mode="-o false"
  207. fi
  208. fi
  209. fi
  210.  
  211. ChangedMode=false
  212. if [ -z "$(grep 'online-mode=true' server.properties)" ]; then
  213. if [ "$mode" != "-o false" ]; then
  214. ChangedMode=false
  215. fi
  216. else
  217. mode="-o false"
  218. fi
  219.  
  220. export LANG=C
  221. export LC_ALL=en_US.UTF-8
  222. export LC_CTYPE=en_US.UTF-8
  223. if [ ! -f .Tips.list ] && "$Online"; then
  224. curl -sL http://cblauncher.netne.net/Update/Tips.list -o .Tips.list
  225. fi
  226. Tip=$(sed -n $(perl -e "print int(rand($(wc -l < .Tips.list))) + 1")p < .Tips.list)
  227.  
  228. if [ ! -z "$(echo $* | grep '-help')" ]; then
  229. echo "$Jar help:"
  230. java -jar $jar --help; exit
  231. fi
  232.  
  233. if [ "$jar" == "CraftBukkit.jar" ]; then
  234. if [ "$Builds" == "recommended" ]; then
  235. Link=http://dl.bukkit.org/downloads/craftbukkit/get/latest-rb/craftbukkit.jar
  236. elif [ "$Builds" == "beta" ]; then
  237. Link=http://dl.bukkit.org/downloads/craftbukkit/get/latest-dev/craftbukkit-bet.jar
  238. elif [ "$Builds" == "developer" ]; then
  239. Link=http://dl.bukkit.org/downloads/craftbukkit/get/latest-dev/craftbukkit-dev.jar
  240. fi
  241.  
  242. elif [ "$jar" == "Minecraft_Server.jar" ]; then
  243. arguments="--nogui $arguments"
  244. Link="https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar"
  245.  
  246. elif [ "$jar" == "SpiGot.jar" ]; then
  247. Part1="http://ci.ecocitycraft.com/job/Spigot"
  248. Part2="artifact/Spigot/target/"
  249. if [ "$Builds" == "recommended" ]; then
  250. Link="$Part1/lastStableBuild/$Part2$(curl -s $Part1/lastStableBuild/$Part2 | grep ".jar" | cut -d '=' -f 16 | cut -d '"' -f 2)" #'
  251. elif [ "$Builds" == "beta" ] || [ "$Builds" == "developer" ]; then
  252. Link="$Part1/lastSuccessfulBuild/$Part2$(curl -s $Part1/lastSuccessfulBuild/$Part2 | grep ".jar" | cut -d '=' -f 16 | cut -d '"' -f 2)" #'
  253. fi
  254. fi
  255. }
  256.  
  257. ConfigError() {
  258. echo -e "${Red}$1 setting: '${Purple}$2${Red}', please edit $it${None}"
  259. Open "LaunchServer.properties" "-a" "TextEdit"
  260. Exit
  261. }
  262.  
  263. CheckConfig() {
  264. if [ -z "$DevSupport" ]; then
  265. ConfigError "Empty" "DevSupport"
  266. else
  267. if [ "$DevSupport" != "true" ] && [ "$DevSupport" != "false" ]; then
  268. ConfigError "Invalid" "DevSupport"
  269. fi
  270. fi
  271.  
  272. if [ -z "$Jar" ]; then
  273. ConfigError "Empty" "Jar"
  274. else
  275. if [ "$Jar" != "CraftBukkit" ] && [ "$Jar" != "Minecraft_Server" ] && [ "$Jar" != "SpiGot" ]; then
  276. ConfigError "Invalid" "Jar"
  277. fi
  278. fi
  279.  
  280. if [ -z "$Builds" ]; then
  281. ConfigError "Empty" "Builds"
  282. else
  283. if [ "$Builds" != "recommended" ] && [ "$Builds" != "beta" ] && [ "$Builds" != "developer" ]; then
  284. ConfigError "Invalid" "Builds"
  285. fi
  286. fi
  287.  
  288. if [ -z "$RAM" ]; then
  289. ConfigError "Empty" "RAM"
  290. else
  291. if [ "$(echo "$RAM" | sed 's/^[0-9]*//')" == "$RAM" ]; then
  292. ConfigError "Invalid" "RAM"
  293. elif [ -z "$(echo $RAM | grep G)" ] && [ -z "$(echo $RAM | grep M)" ]; then
  294. ConfigError "Invalid" "RAM"
  295. fi
  296. fi
  297.  
  298. if [ -z "$RAMDisk" ]; then
  299. ConfigError "Empty" "RAMDisk"
  300. else
  301. if [ "$RAMDisk" != "true" ] && [ "$RAMDisk" != "false" ]; then
  302. ConfigError "Invalid" "RAMDisk"
  303. fi
  304. fi
  305.  
  306. if [ -z "$RAMDiskList" ] && [ "$RAMDisk" == "true" ]; then
  307. ConfigError "Empty" "RAMDiskList"
  308. else
  309. if [ ! -z "$(echo "$RAMDiskList" | grep 'script')" ] || [ ! -z "$(echo "$RAMDiskList" | grep 'Backups')" ]; then
  310. ConfigError "Invalid" "RAMDiskList"
  311. fi
  312. fi
  313.  
  314. if [ -z "$MinimalMode" ]; then
  315. ConfigError "Empty" "MinimalMode"
  316. else
  317. if [ "$MinimalMode" != "true" ] && [ "$MinimalMode" != "false" ]; then
  318. ConfigError "Invalid" "MinimalMode"
  319. fi
  320. fi
  321.  
  322. if [ ! -z "$(echo "$CommandPrefix" | grep ' ')" ]; then
  323. ConfigError "Invalid" "CommandPrefix"
  324. fi
  325.  
  326. if [ -z "$Protips" ]; then
  327. ConfigError "Empty" "Protips"
  328. else
  329. if [ "$Protips" != "true" ] && [ "$Protips" != "false" ]; then
  330. ConfigError "Invalid" "Protips"
  331. fi
  332. fi
  333.  
  334. if [ -z "$Backups" ]; then
  335. ConfigError "Empty" "Backups"
  336. else
  337. if [ "$Backups" != "true" ] && [ "$Backups" != "false" ]; then
  338. ConfigError "Invalid" "Backups"
  339. fi
  340. fi
  341.  
  342. if [ -z "$BackupAt" ]; then
  343. ConfigError "Empty" "BackupAt"
  344. else
  345. if [ "$BackupAt" != "Start" ] && [ "$BackupAt" != "Stop" ] && [ "$BackupAt" != "Restart" ] && [ "$BackupAt" != "All" ]; then
  346. ConfigError "Invalid" "BackupAt"
  347. fi
  348. fi
  349.  
  350. if [ -z "$OnlyScheduled" ]; then
  351. ConfigError "Empty" "OnlyScheduled"
  352. else
  353. if [ "$OnlyScheduled" != "true" ] && [ "$OnlyScheduled" != "false" ]; then
  354. ConfigError "Invalid" "OnlyScheduled"
  355. fi
  356. fi
  357.  
  358. if [ -z "$BackupInterval" ]; then
  359. ConfigError "Empty" "BackupInterval"
  360. else
  361. if [ -z "$(echo "$BackupInterval" | grep "^[:0-9]*$")" > .IntervalTest ] || [ "${#BackupInterval}" -ne 5 ]; then
  362. ConfigError "Invalid" "BackupInterval"
  363. fi
  364. fi
  365.  
  366. if [ -z "$BackupLimit" ]; then
  367. ConfigError "Empty" "BackupLimit"
  368. else
  369. if [ "$(echo "$BackupLimit" | sed 's/^[-+0-9][0-9]*//' | wc -c)" -ne 1 ]; then
  370. ConfigError "Invalid" "BackupLimit"
  371. fi
  372. fi
  373.  
  374. if [ -z "$BackupList" ]; then
  375. ConfigError "Empty" "BackupList"
  376. fi
  377.  
  378. if [ -z "$BackupPlugins" ]; then
  379. ConfigError "Empty" "BackupPlugins"
  380. else
  381. if [ "$BackupPlugins" != "true" ] && [ "$BackupPlugins" != "false" ]; then
  382. ConfigError "Invalid" "BackupPlugins"
  383. fi
  384. fi
  385.  
  386. if [ -z "$CompressBackups" ]; then
  387. ConfigError "Empty" "CompressBackups"
  388. else
  389. if [ "$CompressBackups" != "true" ] && [ "$CompressBackups" != "false" ]; then
  390. ConfigError "Invalid" "CompressBackups"
  391. fi
  392. fi
  393.  
  394. if [ -z "$Schedule" ]; then
  395. ConfigError "Empty" "Schedule"
  396. else
  397. if [ "$Schedule" != "true" ] && [ "$Schedule" != "false" ]; then
  398. ConfigError "Invalid" "Schedule"
  399. fi
  400. fi
  401.  
  402. if [ -z "$StartTime" ]; then
  403. ConfigError "Empty" "StartTime"
  404. else
  405. if [ -z "$(echo "$StartTime" | grep "^[:0-9]*$")" > .IntervalTest ] || [ "${#StartTime}" -ne 5 ]; then
  406. if [ "$StartTime" != "now" ]; then
  407. ConfigError "Invalid" "StartTime"
  408. fi
  409. fi
  410. fi
  411.  
  412. if [ -z "$StopTime" ]; then
  413. ConfigError "Empty" "StopTime"
  414. else
  415. if [ -z "$(echo "$StopTime" | grep "^[:0-9]*$")" > .IntervalTest ] || [ "${#StopTime}" -ne 5 ]; then
  416. if [ "$StopTime" != "never" ]; then
  417. ConfigError "Invalid" "StopTime"
  418. fi
  419. fi
  420. fi
  421.  
  422. if [ -z "$RestartInterval" ]; then
  423. ConfigError "Empty" "RestartInterval"
  424. else
  425. if [ -z "$(echo "$RestartInterval" | grep "^[:0-9]*$")" > .IntervalTest ] || [ "${#RestartInterval}" -ne 5 ]; then
  426. ConfigError "Invalid" "RestartInterval"
  427. fi
  428. fi
  429.  
  430. rm -f .IntervalTest
  431. }
  432.  
  433. Configure() {
  434. echo -e "${Blue}No configuration was found, creating a configuration file and exiting${None}"
  435.  
  436. echo -e '# Support the developer by viewing an adf.ly link (http://adf.ly/CNCVe) every time you use the script 5 times' > LaunchServer.properties
  437. echo -e '# The ad will open in your browser, and will not stop the script' >> LaunchServer.properties
  438. echo -e '# If you feel nice, turn this on :)' >> LaunchServer.properties
  439. echo -e 'DevSupport="false"\n' >> LaunchServer.properties
  440.  
  441. echo -e '# # # # # # # # # #\n# #\n# Server #\n# #\n# # # # # # # # # #\n' >> LaunchServer.properties
  442. echo -e '# Jar file to use' >> LaunchServer.properties
  443. echo -e '# Options: "CraftBukkit"; "Minecraft_Server"; "SpiGot"' >> LaunchServer.properties
  444. echo -e 'Jar="CraftBukkit"\n' >> LaunchServer.properties
  445.  
  446. echo -e '# What type of build to use (ignored if Jar="Minecraft_Server")' >> LaunchServer.properties
  447. echo -e '# Options: recommended; beta; developer' >> LaunchServer.properties
  448. echo -e 'Builds="recommended"\n' >> LaunchServer.properties
  449.  
  450. echo -e '# How much RAM the server should be able to use' >> LaunchServer.properties
  451. echo -e '# Options: any number (more than 2GBs on a small server is pointless)' >> LaunchServer.properties
  452. echo -e '# Examples: - 1G (=1GB)' >> LaunchServer.properties
  453. echo -e '# - 512M (=1/2GB)' >> LaunchServer.properties
  454. echo -e 'RAM="1G"\n' >> LaunchServer.properties
  455.  
  456. echo -e '# # # # # # # # # #\n# #\n# Misc #\n# #\n# # # # # # # # # #\n' >> LaunchServer.properties
  457.  
  458. echo -e '# No fancy layout or features, just the updates and the server' >> LaunchServer.properties
  459. echo -e 'MinimalMode="false"\n' >> LaunchServer.properties
  460.  
  461. echo -e '# Prefix for script commands, opposed to server commands' >> LaunchServer.properties
  462. echo -e "# Options: Can be anything (including nothing), but can't contain spaces" >> LaunchServer.properties
  463. echo -e 'CommandPrefix=""\n' >> LaunchServer.properties
  464.  
  465. echo -e '# Protips on server start' >> LaunchServer.properties
  466. echo -e 'Protips="true"\n' >> LaunchServer.properties
  467.  
  468. echo -e '# Use a RAM Disk makes loading and saving faster' >> LaunchServer.properties
  469. echo -e '# Not recommened as you might loose or corrupt your worlds if something goes wrong will the server is running' >> LaunchServer.properties
  470. echo -e 'RAMDisk="false"\n' >> LaunchServer.properties
  471.  
  472. echo -e '# Worlds to move to the RAMDisk' >> LaunchServer.properties
  473. echo -e 'RAMDiskList="world\nworld_nether\nworld_the_end"\n\n' >> LaunchServer.properties
  474.  
  475. echo -e '# # # # # # # # # #\n# #\n# Backups #\n# #\n# # # # # # # # # #\n' >> LaunchServer.properties
  476.  
  477. echo -e '# Backup worlds' >> LaunchServer.properties
  478. echo -e 'Backups="true"\n' >> LaunchServer.properties
  479.  
  480. echo -e '# When to backup' >> LaunchServer.properties
  481. echo -e '# Options: Start (script); Stop (script); Restart (server); All' >> LaunchServer.properties
  482. echo -e 'BackupAt="Start"\n' >> LaunchServer.properties
  483.  
  484. echo -e '# Only backup when the server is (re)started/stopped by the schedule' >> LaunchServer.properties
  485. echo -e '# (ignored if Schedule="false")' >> LaunchServer.properties
  486. echo -e 'OnlyScheduled="true"\n' >> LaunchServer.properties
  487.  
  488. echo -e '# Only keep X backups (oldest will be deleted)' >> LaunchServer.properties
  489. echo -e 'BackupLimit="5"\n' >> LaunchServer.properties
  490.  
  491. echo -e '# Worlds to backup' >> LaunchServer.properties
  492. echo -e 'BackupList="world\nworld_nether\nworld_the_end"\n' >> LaunchServer.properties
  493.  
  494. echo -e '# Backup plugins'"'"' configurations, but not the plugins themselves (.jar)' >> LaunchServer.properties
  495. echo -e 'BackupPlugins="false"\n' >> LaunchServer.properties
  496.  
  497. echo -e '# Compress backups to save space (uses "'$(which tar)'")' >> LaunchServer.properties
  498. echo -e 'CompressBackups="true"\n\n' >> LaunchServer.properties
  499.  
  500. echo -e '# # # # # # # # # #\n# #\n# Schedule #\n# #\n# # # # # # # # # #\n' >> LaunchServer.properties
  501.  
  502. echo -e '# Use the schedule option (Forces MinimalMode="false")' >> LaunchServer.properties
  503. echo -e 'Schedule="false"\n' >> LaunchServer.properties
  504.  
  505. echo -e '# When the server should automatically start/stop (ignored if Schedule="false")' >> LaunchServer.properties
  506. echo -e '# Options: HH:MM; $(In HH:MM); now (only for StartTime); never (only for StopTime)' >> LaunchServer.properties
  507. echo -e '# Examples: - StartTime="18:30" (=Start at 6:30 PM)' >> LaunchServer.properties
  508. echo -e '# - StartTime="$(In 00:05)" (=Start 5 minutes after the script is opened)' >> LaunchServer.properties
  509. echo -e 'StartTime="now"' >> LaunchServer.properties
  510. echo -e 'StopTime="never"\n' >> LaunchServer.properties
  511.  
  512. echo -e '# Interval between world backups (ignored if Schedule="false")' >> LaunchServer.properties
  513. echo -e '# Examples: - 00:00 (=never)' >> LaunchServer.properties
  514. echo -e '# - 00:10 (=every 10 minutes)' >> LaunchServer.properties
  515. echo -e '# - 01:30 (=every 1h30)' >> LaunchServer.properties
  516. echo -e 'BackupInterval="00:00"\n' >> LaunchServer.properties
  517.  
  518. echo -e '# Interval between server restarts (ignored if Schedule="false")' >> LaunchServer.properties
  519. echo -e '# Examples: - 00:00 (=never)' >> LaunchServer.properties
  520. echo -e '# - 00:10 (=every 10 minutes)' >> LaunchServer.properties
  521. echo -e '# - 01:30 (=every 1h30)' >> LaunchServer.properties
  522. echo -e 'RestartInterval="00:00"\n' >> LaunchServer.properties
  523.  
  524. echo -e '# Commands to run before/after restarting the server' >> LaunchServer.properties
  525. echo -e '# One command per line:' >> LaunchServer.properties
  526. echo -e '# Before/AfterRestart="say First Command' >> LaunchServer.properties
  527. echo -e '# say Second Command"' >> LaunchServer.properties
  528. echo -e 'BeforeRestart="say Schedulede restart. See you in a sec!"' >> LaunchServer.properties
  529. echo -e 'AfterRestart=""' >> LaunchServer.properties
  530.  
  531. Open "LaunchServer.properties" "-a" "TextEdit"
  532. }
  533.  
  534. In() {
  535. if [ -z "$2" ]; then
  536. Start=$(date +'%R')
  537. End="$1"
  538. else
  539. Start="$1"
  540. End="$2"
  541. fi
  542. Part1=
  543. Part2=
  544.  
  545. N1=$(echo "$Start" | cut -d ':' -f 1 | sed 's/^0*//'); if [ -z "$N1" ]; then N1="0"; fi
  546. N2=$(echo "$Start" | cut -d ':' -f 2 | sed 's/^0*//'); if [ -z "$N2" ]; then N2="0"; fi
  547. A1=$(echo "$End" | cut -d ':' -f 1 | sed 's/^0*//'); if [ -z "$A1" ]; then A1="0"; fi
  548. A2=$(echo "$End" | cut -d ':' -f 2 | sed 's/^0*//'); if [ -z "$A2" ]; then A2="0"; fi
  549.  
  550. Part2=$(( $N2 + $A2 ))
  551.  
  552. if [ "$A1" == "00" ]; then
  553. Part1=$N1
  554. fi
  555.  
  556. if [ "$Part2" -gt 60 ]; then
  557. Part1=$(( (Part2 / 60) + $A1 + $N1 ))
  558. Part2=$(( Part2 % 60 ))
  559.  
  560. elif [ "$Part2" -eq 60 ]; then
  561. Part2=00
  562. Part1=$(( 1 + $A1 + $N1 ))
  563. else
  564. Part1=$(( $A1 + $N1 ))
  565. fi
  566. Part1=$((Part1 % 24))
  567.  
  568. Part1=$(echo -n "$Part1" | sed 's/^-*//')
  569. Part2=$(echo -n "$Part2" | sed 's/^-*//')
  570. if [ $(echo -n "$Part1" | wc -m) -eq 1 ]; then Part1="0$Part1"; fi; if [ -z "$Part1" ]; then Part1="00"; fi
  571. if [ $(echo -n "$Part2" | wc -m) -eq 1 ]; then Part2="0$Part2"; fi; if [ -z "$Part2" ]; then Part2="00"; fi
  572.  
  573. echo "$Part1:$Part2"
  574. }
  575.  
  576. Do() {
  577. if [ $"1" == "Undo" ]; then
  578. if [ -f "$Jar"_Old.jar ]; then
  579. mv -f "$jar" "$Jar"_New.jar > /dev/null 2>&1
  580. mv -f "$Jar"_Old.jar "$jar" > /dev/null 2>&1
  581. clear
  582. echo -e "${Green}The update was successfully undone${None}"
  583. fi
  584. elif [ "$1" == "Redo" ]; then
  585. if [ -f "$Jar"_New.jar ]; then
  586. mv -f "$jar" "$Jar"_Old.jar > /dev/null 2>&1
  587. mv -f "$Jar"_New.jar "$jar" > /dev/null 2>&1
  588. clear
  589. echo -e "${Green}The update was successfully redone${None}"
  590. fi
  591. fi
  592. }
  593.  
  594. DontDo() {
  595. if [ "$1" == "Undo" ]; then
  596. echo -e "\n${Blue}Update was not undone${None}"
  597. echo -e "${Green}Can I delete ${Jar}_Old.jar (needed to undo the update)? (${Purple}Yes${Green}/${Purple}No${Green})${None}"
  598. tput cnorm
  599. read -p ": " Delete
  600. if ! "$MinimalMode"; then
  601. tput civis
  602. fi
  603. shopt -s nocasematch
  604. case "$Delete" in
  605. y | yes) rm -f "$Jar"_Old.jar;;
  606. n | no ) echo -e "\n${Blue}${Jar}_Old.jar was left, you will be asked agin if you want to undo the update${None}";;
  607. esac
  608. elif [ "$1" == "Redo" ]; then
  609. echo -e "\n${Blue}Update was not redone${None}"
  610. echo -e "${Green}Can I delete ${Jar}_New.jar (needed to redo the update)? (${Purple}Yes${Green}/${Purple}No${Green})${None}"
  611. tput cnorm
  612. read -p ": " Delete
  613. if ! "$MinimalMode"; then
  614. tput civis
  615. fi
  616. shopt -s nocasematch
  617. case "$Delete" in
  618. y | yes) rm -f "$Jar"_New.jar;;
  619. n | no ) clear; echo -e "\n${Blue}${Jar}_New.jar was left, you will be asked agin if you want to redo the update${None}";;
  620. esac
  621. fi
  622. }
  623.  
  624. ChangeLog() {
  625. ChangeLog=Displayed
  626. curl -sL http://cblauncher.netne.net/Update/Changelog.list -o ./script/temp/Changelog.list
  627.  
  628. if [ "$1" == "Continue" ]; then
  629. clear
  630. fi
  631. echo -e "${Blue}Changelog for version ${Purple}$LatestVersion${Blue} :${None}"
  632. while read Change; do
  633. if [ -n "$Change" ]; then
  634. echo -e "${Blue}\t- $Change${None}"
  635. fi
  636. done < ./script/temp/Changelog.list
  637. if [ "$1" == "Wait" ]; then
  638. echo -e "\n${Blue}Press enter when done reading.${None}"
  639. tput cnorm
  640. read -p ": " NULL
  641. if ! "$MinimalMode"; then
  642. tput civis
  643. fi
  644. fi
  645.  
  646. rm -f ./script/temp/Changelog.list
  647. }
  648.  
  649. CheckForLauncherUpdates() {
  650. curl -sL http://cblauncher.netne.net/Update/General.list -o ./script/temp/General.list
  651. source ./script/temp/General.list
  652.  
  653. if [ "$ThisVersion" != "$LatestVersion" ] && "$Critical" && ! "$Silent"; then
  654. echo -e "${Green}A Critical update was found. Proceeding to update${None}"
  655. UpdateLauncher
  656. elif [ "$LatestVersion" != "0.4" ] && "$Critical" && "$Silent"; then
  657. UpdateLauncher Silent
  658. fi
  659.  
  660. if [ "$ThisVersion" != "$LatestVersion" ] && ! "$Critical"; then
  661. echo -e "${Green}An update for the server launcher is available${None}"
  662. for (( i = 0; i < 1; j = 0)); do
  663. echo -e "${Green}Would you like to update now? (${Purple}Yes${Green}/${Purple}No${Green}/[${Purple}C${Green}]hangelog${Green})${None}"
  664. tput cnorm
  665. read -p ": " Update
  666. if ! "$MinimalMode"; then
  667. tput civis
  668. fi
  669. shopt -s nocasematch
  670. case "$Update" in
  671. y | yes ) UpdateLauncher; i=2;;
  672. n | no ) i=3;;
  673. c | changelog ) ChangeLog Continue; i=0;;
  674. esac
  675. done
  676. clear
  677. if [ $i -eq 3 ]; then
  678. echo -e "${Green}Continuing without updating the launcher${None}"
  679. fi
  680. else
  681. if "$MinimalMode"; then
  682. echo -e "${Green}Your Server Launcher is up to date! (version ${Purple}$ThisVersion${Green})${None}"
  683. else
  684. LauncherUpToDate=true
  685. fi
  686. fi
  687. rm -f ./script/temp/General.list
  688. }
  689.  
  690. UpdateLauncher() {
  691. if [ "$1" != "Silent" ]; then
  692. curl -L http://cblauncher.netne.net/Update/LaunchServer.command -o ./script/temp/NewLauncher.command --progress-bar
  693. else
  694. curl -sL http://cblauncher.netne.net/Update/LaunchServer.command -o ./script/temp/NewLauncher.command
  695. fi
  696. chmod +x ./script/temp/NewLauncher.command
  697. curl -sL http://cblauncher.netne.net/Update/Tips.list -o .Tips.list
  698. if [ "$1" != "Silent" ]; then
  699. clear
  700. echo -e "${Green}The launcher was successfully updated${None}"
  701. if [ -z "$ChangeLog" ]; then
  702. ChangeLog Wait
  703. fi
  704. fi
  705. if "$Reconfigure"; then
  706. curl -sL http://cblauncher.netne.net/Update/NewOptions.command -o ./script/temp/NewOptions.command
  707. chmod +x ./script/temp/NewOptions.command
  708. ./script/temp/NewOptions.command
  709. rm -f ./script/temp/NewOptions.command
  710. Open "LaunchServer.properties" "-a" "TextEdit"
  711. fi
  712. rm -rf ./script/*.*
  713. rm "$0"
  714. mv -f ./script/temp/NewLauncher.command ./LaunchServer.command
  715. if ! "$Reconfigure"; then
  716. ./LaunchServer.command
  717. fi
  718. exit
  719. }
  720.  
  721. CheckForServerUpdates() {
  722. if "$Linux"; then
  723. Local=$(stat -c%s ./"$jar")
  724. else
  725. Local=$(stat -f "%z" ./"$jar")
  726. fi
  727.  
  728. Remote=$(curl --connect-timeout 3 --max-time 3 -sLI "$Link" | awk '/Content-Length/ {sub("\r",""); print $2}')
  729. Remote=$(echo "$Remote" | sed -n $(echo "$Remote" | wc -l)p)
  730.  
  731. if [ -z "$Remote" ]; then
  732. ServerUpToDate=offline
  733. return 0
  734. fi
  735.  
  736. if [ "$Local" -ne "$Remote" ]; then
  737. if "$MinimalMode"; then
  738. echo -e '\n'
  739. else
  740. ServerUpToDate=false
  741. fi
  742. echo -e "${Green}An update for $Jar is available${None}"
  743. echo -e "${Green}Do you want to update now? (${Purple}Yes${Green}/${Purple}No${Green})${None}"
  744. tput cnorm
  745. read -p ": " Update
  746. if ! "$MinimalMode"; then
  747. tput civis
  748. fi
  749. shopt -s nocasematch
  750. case "$Update" in
  751. y | yes) UpdateServer;;
  752. n | no ) clear;;
  753. esac
  754.  
  755. ServerVersion
  756.  
  757. elif [ "$Local" -eq "$Remote" ]; then
  758. if "$MinimalMode"; then
  759. if [ "$Jar" == "Minecraft_Server" ]; then
  760. echo -e "${Green}$jar is up to date! (version ${Purple}$ServerVersion${Green})${None}"
  761. else
  762. echo -e "${Green}$Jar is up to date! (latest ${Purple}$Builds${Green} build: ${Purple}${ServerVersion}${Green})${None}"
  763. fi
  764. else
  765. ServerUpToDate=true
  766. fi
  767. fi
  768. }
  769.  
  770. UpdateServer() {
  771. clear
  772. echo -e "${Blue}Updating server...${None}"
  773. echo -e "${Blue}Backed up $jar to ${Jar}_Old.jar in case something goes wrong.${None}\n"
  774. mv -f "$jar" "$Jar"_Old.jar
  775. echo -e "${Blue}Downloading $jar:${None}"
  776. curl -L "$Link" -o "$jar" --progress-bar
  777. clear
  778. echo -e "${Green}Your server was updated.${None}"
  779. echo -e "${Red}WARNING: An update may break plugins! Please ensure all plugins installed are up to date.\n${None}"
  780.  
  781. if ! "$MinimalMode"; then
  782. ServerUpToDate=true
  783. fi
  784. }
  785.  
  786. PrepareFiles() {
  787. mkdir -p ./script/temp/dummies
  788. mkdir -p ./script/temp/screen
  789. # chflags hidden ./script
  790.  
  791. if [ "$1" == "Server" ]; then
  792. touch banned-players.txt banned-ips.txt ops.txt server.log server.properties white-list.txt
  793.  
  794. if [ -f server.log.lck ] && [ -z "$(screen -ls | grep "$ServerScreen")" ]; then
  795. echo "A server is already running, and it wasn't started with this script, please stop it and try again"
  796. Exit
  797. fi
  798.  
  799. if [ -f bukkit.yml ]; then
  800. while read; do
  801. if [ "$REPLY" == ' enabled: true' ]; then
  802. printf ' enabled: false\n'
  803. else
  804. echo "$REPLY"
  805. fi
  806. done < bukkit.yml > ./script/temp/bukkit.yml
  807. mv -f ./script/temp/bukkit.yml bukkit.yml
  808. else
  809. printf 'auto-updater:\n enabled: false\n' >> bukkit.yml
  810. fi
  811.  
  812.  
  813. elif [ "$1" == "Jar" ]; then
  814. if [ -f "$Jar"_New.jar ]; then
  815. echo -e "${Green}Would you like to redo the update? (${Purple}Yes${Green}/${Purple}No${Green})${None}"
  816. tput cnorm
  817. read -p ": " Redo
  818. if ! "$MinimalMode"; then
  819. tput civis
  820. fi
  821. shopt -s nocasematch
  822. case "$Redo" in
  823. y | yes) Do Redo;;
  824. n | no ) DontDo Redo;;
  825. esac
  826. elif [ -f "$Jar"_Old.jar ]; then
  827. clear
  828. echo -e "${Green}Would you like to undo the update? (${Purple}Yes${Green}/${Purple}No${Green})${None}"
  829. tput cnorm
  830. read -p ": " Undo
  831. if ! "$MinimalMode"; then
  832. tput civis
  833. fi
  834. shopt -s nocasematch
  835. case "$Undo" in
  836. y | yes) Do Undo;;
  837. n | no ) DontDo Undo;;
  838. esac
  839. fi
  840.  
  841. if ! "$Online"; then
  842. if [ -f "$jar" ]; then
  843. if "$MinimalMode"; then
  844. echo -e "${Red}Could not check for updates, the server will start in offline mode${None}"
  845. fi
  846. mode="-o false"
  847.  
  848. elif [ ! -f "$jar" ] && [ ! -f "$Jar"_Old.jar ] && [ ! -f "$Jar"_New.jar ]; then
  849. echo -e "${Red}Could not check for updates, and $jar was not found${None}"
  850. echo -e "${Red}The server will not start, please connect to the internet to download $jar${None}"
  851. Exit
  852.  
  853. elif [ ! -f "$jar" ] && [ -f "$Jar"_Old.jar ] && [ ! -f "$Jar"_New.jar ]; then
  854. echo -e "${Red}Could not check for updates, and $jar was not found${None}"
  855. echo -e "${Green}I found ${Jar}_Old.jar, should I use it instead? (${Purple}Yes${Green}/${Purple}No${Green})${None}"
  856. tput cnorm
  857. read -p ": " Use
  858. if ! "$MinimalMode"; then
  859. tput civis
  860. fi
  861. shopt -s nocasematch
  862. case "$Use" in
  863. y | yes) jar="$Jar"_Old.jar; mode="-o false"; return 0;;
  864. n | no ) echo -e "${Red}The server will not start, please connect to the internet to download $jar${None}"; Exit;;
  865. esac
  866.  
  867. elif [ ! -f "$jar" ] && [ ! -f "$Jar"_Old.jar ] && [ -f "$Jar"_New.jar ]; then
  868. echo -e "${Red}Could not check for updates, and $jar was not found${None}"
  869. echo -e "${Green}I found ${Jar}_New.jar, should I use it instead? (${Purple}Yes${Green}/${Purple}No${Green})${None}"
  870. tput cnorm
  871. read -p ": " Use
  872. if ! "$MinimalMode"; then
  873. tput civis
  874. fi
  875. shopt -s nocasematch
  876. case "$Use" in
  877. y | yes) jar="$Jar"_New.jar; mode="-o false"; return 0;;
  878. n | no ) echo -e "${Red}The server will not start, please connect to the internet to download $jar${None}"; Exit;;
  879. esac
  880. fi
  881. fi
  882.  
  883. if [ ! -f "$jar" ] && "$Online"; then
  884. echo -e "${Red}$jar was not found, it will be redownloaded:${None}"
  885. curl -L "$Link" -o "$jar" --progress-bar
  886. clear
  887. fi
  888.  
  889. ServerVersion
  890.  
  891.  
  892. elif [ "$1" == "Screen" ]; then
  893. Columns=$(tput cols)
  894. Lines=$(tput lines)
  895. if [ "$Lines" -lt 31 ]; then
  896. MenuLines=$(( Lines * 1 / 4 ))
  897. elif [ "$Lines" -gt 30 ]; then
  898. MenuLines=$(( Lines * 1 / 3 ))
  899. fi
  900. ViewLines=$(( Lines - MenuLines ))
  901.  
  902. echo -e 'startup_message off' > ./script/temp/screen/Main.conf
  903. echo -e 'screen -t Script-Menu 2 ./script/Main.sh' >> ./script/temp/screen/Main.conf
  904. echo -e 'screen -t Server-View 1 ./script/View.sh\n' >> ./script/temp/screen/Main.conf
  905.  
  906. echo -e 'split\n' >> ./script/temp/screen/Main.conf
  907.  
  908. echo -e "resize $ViewLines" >> ./script/temp/screen/Main.conf
  909. echo -e 'focus down\n' >> ./script/temp/screen/Main.conf
  910.  
  911. echo -e "resize $MenuLines" >> ./script/temp/screen/Main.conf
  912. echo -e 'select Script-Menu' >> ./script/temp/screen/Main.conf
  913.  
  914.  
  915. echo -e 'startup_message off' > ./script/temp/screen/Schedule.conf
  916. echo -e 'screen 1 ./script/Schedule.sh' >> ./script/temp/screen/Schedule.conf
  917.  
  918.  
  919. echo -e 'startup_message off' > ./script/temp/screen/Server.conf
  920. echo -e 'screen 1 ./script/Server.sh' >> ./script/temp/screen/Server.conf
  921.  
  922.  
  923. elif [ "$1" == "Script" ]; then
  924.  
  925. if "$Protips"; then
  926. echo "PROTIP: $Tip" > ./script/temp/Notifications
  927. fi
  928.  
  929. if [ ! -f LauncherAliases.properties ]; then
  930. echo -e '# Put your aliases here for the launcher to use' >> LauncherAliases.properties
  931. echo -e '# These are not accesible when MinimalMode="true"' >> LauncherAliases.properties
  932. echo -e '# The aliases will be checked live, so you can update this file while the server is running' >> LauncherAliases.properties
  933. echo -e 'Example="say This is an example alias\nsay You can have multiple lines!"' >> LauncherAliases.properties
  934. fi
  935.  
  936. if ! "$MinimalMode"; then
  937. Missing=0
  938.  
  939. touch ./script/temp/dummies/_ScriptIsOn
  940. touch ./script/temp/dummies/_Run
  941.  
  942. if [ ! -f "./script/Main.sh" ]; then
  943. ((Missing++))
  944. MissingFiles="$MissingFiles$(echo -e 'Main.sh\t')"
  945. else
  946. chmod +x ./script/Main.sh
  947. fi
  948.  
  949. if [ ! -f "./script/MCQuery.py" ]; then
  950. ((Missing++))
  951. MissingFiles="$MissingFiles$(echo -e 'MCQuery.py\t')"
  952. fi
  953.  
  954. if [ ! -f "./script/Schedule.sh" ]; then
  955. ((Missing++))
  956. MissingFiles="$MissingFiles$(echo -e 'Schedule.sh\t')"
  957. else
  958. chmod +x ./script/Schedule.sh
  959. fi
  960.  
  961. if [ ! -f "./script/Server.sh" ]; then
  962. ((Missing++))
  963. MissingFiles="$MissingFiles$(echo -e 'Server.sh\t')"
  964. else
  965. chmod +x ./script/Server.sh
  966. fi
  967.  
  968. if [ ! -f "./script/Utilities.sh" ]; then
  969. ((Missing++))
  970. MissingFiles="$MissingFiles$(echo -e 'Utilities.sh\t')"
  971. else
  972. chmod +x ./script/Utilities.sh
  973. fi
  974.  
  975. if [ ! -f "./script/View.sh" ]; then
  976. ((Missing++))
  977. MissingFiles="$MissingFiles$(echo -e 'View.sh\t')"
  978. else
  979. chmod +x ./script/View.sh
  980. fi
  981.  
  982. if [ "$Missing" -ne 0 ]; then
  983. echo -e "${Red}Some script files are missing${None}"
  984.  
  985. if "$Online"; then
  986. echo -e "${Blue}Downloading missing files:${None}"
  987. for ((i=1; i<=Missing; i++)); do
  988. File="$(echo "$MissingFiles" | cut -f $i)"
  989. curl -L http://cblauncher.netne.net/Update/script/"$File" -o ./script/"$File" --progress-bar
  990. chmod +x ./script/"$File"
  991. done
  992. ./LaunchServer.command; exit
  993. else
  994. echo -e "${Red}Could not download them: you are not connected to the internet${None}"
  995. Exit
  996. fi
  997. fi
  998. fi
  999. fi
  1000. }
  1001.  
  1002. Dependencies() {
  1003. if [ -z "$(which curl)" ]; then
  1004. echo -e "${Blue}Installing ${Purple}curl${Blue}:${None}"
  1005. SudoAuthorization "to install curl"
  1006. sudo apt-get install curl
  1007. if [ $? -ne 0 ]; then
  1008. echo -e "${Red}There was an error while installing ${Purple}curl${None}"
  1009. Exit 1
  1010. fi
  1011. clear
  1012. fi
  1013. if [ -z "$(which java)" ]; then
  1014. echo -e "${Red}Java is required to run the Minecraft Server{None}"
  1015. echo -e "You can install it manually here: ${Blue}http://java.com/en/download/linux_manual.jsp${None}"
  1016. echo -e "Or install it from the command line:"
  1017. echo -e "sudo add-apt-repository ppa:webupd8team/java"
  1018. echo -e "sudo apt-get update"
  1019. echo -e "sudo apt-get install oracle-java7-installer"
  1020. Exit 1
  1021. fi
  1022. if [ -z "$(which python)" ]; then
  1023. echo -e "${Blue}Installing ${Purple}python${Blue}:${None}"
  1024. SudoAuthorization "to install python"
  1025. sudo apt-get install python
  1026. if [ $? -ne 0 ]; then
  1027. echo -e "${Red}There was an error while installing ${Purple}python${None}"
  1028. Exit 1
  1029. fi
  1030. clear
  1031. fi
  1032. if [ -z "$(which screen)" ]; then
  1033. echo -e "${Blue}Installing ${Purple}screen${Blue}:${None}"
  1034. SudoAuthorization "to install screen"
  1035. sudo apt-get install screen
  1036. if [ $? -ne 0 ]; then
  1037. echo -e "${Red}There was an error while installing ${Purple}screen${None}"
  1038. Exit 1
  1039. fi
  1040. clear
  1041. fi
  1042. }
  1043.  
  1044. SudoAuthorization() {
  1045. echo -e "${Blue}Please type your password, it is required $1${None}"
  1046. tput cnorm
  1047. sudo printf ""
  1048. if [ "$?" -eq 0 ]; then
  1049. echo -e "${Blue}Thank you${None}"
  1050. else
  1051. echo -e "${Red}Error, aborting!${None}"
  1052. Exit
  1053. fi
  1054. }
  1055.  
  1056. SendStats() {
  1057. Date=$(date)
  1058. if [ "$ThisVersion" == "$LatestVersion" ]; then ThisVersion="$ThisVersion (Latest)"; fi
  1059. if [ ! -f ~/.com.Pierre-Louis.CBlauncher ]; then
  1060. touch ~/.com.Pierre-Louis.CBlauncher
  1061. curl -d "Date=$Date&Action=Install&Version=$ThisVersion&submit=submit" -L http://cblauncher.netne.net/record_stats.php > /dev/null 2>&1
  1062. fi
  1063. curl -d "Date=$Date&Action=Launch&Version=$ThisVersion&submit=submit" -L http://cblauncher.netne.net/record_stats.php > /dev/null 2>&1
  1064. }
  1065.  
  1066. Open() {
  1067. if [ -f "$1" ] || [ ! -z "$(echo $* | grep 'http://')" ]; then
  1068. if [ ! -z "$SSH_CLIENT" ]; then
  1069. if [ -f "$1" ]; then
  1070. if [ -f "$1" ]; then
  1071. echo -e "Press enter to open '$1' with nano"
  1072. echo -e "To cancel, press 'Ctrl + C'"
  1073. tput cnorm
  1074. read -p ": " NULL
  1075. if ! "$MinimalMode"; then
  1076. tput civis
  1077. fi
  1078. nano "$1"
  1079. else
  1080. Exit
  1081. fi
  1082. fi
  1083. elif "$Linux"; then
  1084. xdg-open "$1"
  1085. else
  1086. open "$2" "$3" "$1"
  1087. fi
  1088. fi
  1089. }
  1090.  
  1091. Exit() {
  1092. if [ "$1" == "EndOfScript" ] && "$ChangedMode" && [ "$mode" == "-o false" ]; then
  1093. while read; do
  1094. if [ "$REPLY" == "online-mode=true" ]; then
  1095. echo "online-mode=false"
  1096. else
  1097. echo "$REPLY"
  1098. fi
  1099. done < server.properties > .server.properties
  1100. mv -f .server.properties server.properties
  1101. elif [ "$1" != "EndOfScript" ] && [ ! -z "$1" ]; then
  1102. ExitCode="$1"
  1103. fi
  1104.  
  1105. tput cnorm
  1106. rm -rf ./script/temp
  1107. exit $ExitCode
  1108. }
  1109.  
  1110. Main() {
  1111. clear
  1112. cd "$(dirname "$0")"
  1113.  
  1114. if [ -f ./script/temp/dummies/_Closed ] && [ "$1" != "--stop" ]; then
  1115. echo -e "${Blue}Resuming...${None}"
  1116. touch ./script/temp/dummies/_ScriptIsOn
  1117. source ./script/temp/vars.conf
  1118. Start
  1119.  
  1120. else
  1121. Linux=false
  1122. Debian=false
  1123. Ubuntu=false
  1124.  
  1125. if [ ! -z "$(uname -a | grep Linux)" ]; then
  1126. Linux=true
  1127. if [ ! -z "$(uname -a | grep Debian)" ] || [ "$(lsb_release -i -s)" == "Debian" ]; then
  1128. Debian=true
  1129. elif [ ! -z "$(uname -a | grep Ubuntu)" ] || [ "$(lsb_release -i -s)" == "Ubuntu" ]; then
  1130. Ubuntu=true
  1131. fi
  1132. Dependencies
  1133. fi
  1134.  
  1135. if [ "$1" == "--start" ] || [ "$1" == "--stop" ]; then
  1136. ReadConfig $*
  1137. PrepareFiles Server
  1138. PrepareFiles Screen
  1139. PrepareFiles Script
  1140. ExportVars
  1141. Daemon $*
  1142.  
  1143. else
  1144. PrepareFiles Server
  1145.  
  1146. if [ -f LaunchServer.properties ]; then
  1147. ReadConfig $*
  1148. else
  1149. Configure
  1150. Exit
  1151. fi
  1152.  
  1153. PrepareFiles Screen
  1154. PrepareFiles Script
  1155. PrepareFiles Jar
  1156.  
  1157. if "$Online"; then
  1158. CheckForLauncherUpdates
  1159. CheckForServerUpdates
  1160.  
  1161. if "$DevSupport"; then
  1162. if [ -f .AdCount ]; then
  1163. source .AdCount
  1164. else
  1165. LaunchNumber=5
  1166. fi
  1167.  
  1168. if [ "$LaunchNumber" -ne 5 ]; then
  1169. echo -e "LaunchNumber=$((LaunchNumber + 1))\nAdViewed=$AdViewed" > .AdCount
  1170. else
  1171. echo -e "LaunchNumber=1\nAdViewed=$((AdViewed + 1))" >> .AdCount
  1172. Open http://adf.ly/CNCVe
  1173. fi
  1174. fi
  1175.  
  1176. else
  1177. LauncherUpToDate="offline"
  1178. ServerUpToDate="offline"
  1179. fi
  1180. fi
  1181.  
  1182. ExportVars
  1183.  
  1184. tput cnorm
  1185. Start
  1186. Exit EndOfScript
  1187. fi
  1188. }
  1189.  
  1190. # # # # # # # # # # #
  1191. # #
  1192. # End Of Functions #
  1193. # #
  1194. # # # # # # # # # # #
  1195. ThisVersion="1.0.6"
  1196.  
  1197. None='\033[0m'
  1198. Black='\033[0;30m'
  1199. Blue='\033[0;34m'
  1200. Cyan='\033[0;36m'
  1201. Green='\033[0;32m'
  1202. Purple='\033[0;35m'
  1203. Red='\033[0;31m'
  1204. Yellow='\033[0;33m'
  1205.  
  1206. Main $*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement