Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.11 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. NC='\033[0m'
  4. GREEN='\033[0;32m'
  5. RED='\033[0;31m'
  6. YELLOW='\033[0;33m'
  7.  
  8. # Function to create default configuration depending on path
  9. create_default_config()
  10. {
  11.     echo "${YELLOW}Could not find an existing configuration file. Creating one for you.${NC}"
  12.     echo "${YELLOW}Make sure to adjust important settings like your RCon password!${NC}"
  13.  
  14.     sleep 2
  15.  
  16.     echo "Copying default init.txt."
  17.     cp /defaults/init.txt $1
  18. }
  19.  
  20. echo "Initializing v${CONTAINER_VERSION} for HaloCE SAPP v10.1"
  21.  
  22. # Search for haloceded.exe in game directory
  23. if [ ! -e /game/haloceded.exe ]; then
  24.     echo "${RED}Could not find haloceded.exe. Did you mount the game directory to /game?${NC}"
  25.     sleep 2
  26.     exit 1
  27. fi
  28.  
  29. # Search for SAPP in game directory
  30. if [ ! -e /game/sapp.dll ]; then
  31.     echo "${YELLOW}Could not find SAPP. Downloading it for you.${NC}"
  32.     sleep 2
  33.     # Download SAPP v10.1 for Halo CE to game directory
  34.     wget https://opencarnage.net/misc/sapp_ce.zip -P /game && \
  35.     unzip sapp_ce.zip && \
  36.     mv sapp_ce/*.dll . && \
  37.     # Cleanup
  38.     rm -rf sapp_ce/ sapp_ce.zip && \
  39.     echo "${GREEN}SAPP download complete.${NC}"
  40. fi
  41.  
  42. # Create user if container should run as user
  43. if [ -z "${RUN_AS_USER}" ]; then
  44.     echo "Running as root"
  45.     user=root
  46.  
  47.     if [ $PUID -ne 0 ] || [ $PGID -ne 0 ]; then
  48.         echo "${RED}Tried to set PUID OR PGID without setting RUN_AS_USER.${NC}"
  49.         echo "${RED}Please set RUN_AS_USER or remove PUID & PGID from your environment variables.${NC}"
  50.  
  51.         sleep 2
  52.         exit 40
  53.     fi
  54. else
  55.     echo "Running as haloce"
  56.     user=haloce
  57.  
  58.     if [ $PUID -lt 1000 ] || [ $PUID -gt 60000 ]; then
  59.         echo "${RED}PUID is invalid${NC}"
  60.  
  61.         sleep 2
  62.         exit 20
  63.     fi
  64.  
  65.     if [ $PGID -lt 1000 ] || [ $PGID -gt 60000 ]; then
  66.         echo "${RED}PGID is invalid${NC}"
  67.  
  68.         sleep 2
  69.         exit 30
  70.     fi
  71.  
  72.     if ! id -u haloce > /dev/null 2>&1; then
  73.         echo "Creating user"
  74.         useradd -u $PUID -m -d /tmp/home haloce
  75.     fi
  76. fi
  77.  
  78. # Search for init.txt in /game directory
  79. if [ ! -e "init.txt" ]; then
  80.     create_default_config "/game"
  81. fi
  82.  
  83. if [ -z "${SKIP_CHOWN}" ]; then
  84.     echo "Taking ownership of folders"
  85.     chown -R $PUID:$PGID /game /config /wine
  86.  
  87.     echo "Changing folder permissions"
  88.     find /game /config -type d -exec chmod 775 {} \;
  89.  
  90.     echo "Changing file permissions"
  91.     find /game /config -type f -exec chmod 664 {} \;
  92. fi
  93.  
  94. # Xvfb needs cleaning because it doesn't exit cleanly
  95. echo "Cleaning up"
  96. rm /tmp/.X1-lock
  97.  
  98. echo "Starting virtual frame buffer"
  99. Xvfb :1 -screen 0 320x240x24 &
  100.  
  101. echo "${GREEN}Starting dedicated server${NC}"
  102.  
  103. # DLL overrides for Wine are required to prevent issues with master server announcement
  104. export WINEDLLOVERRIDES="winhttp,rasapi32=n"
  105.  
  106. if [ ! -z "${WINE_DEBUG}" ]; then
  107.     echo "Setting wine to verbose output"
  108.     export WINEDEBUG=warn+all
  109. fi
  110.  
  111. # Start the server
  112. su -c "wine haloceded.exe" $user
  113.  
  114. if [ -z "${WAIT_ON_EXIT}" ]; then
  115.     echo "${RED}Server terminated, exiting${NC}"
  116. else
  117.     echo "${RED}Server terminated, waiting${NC}"
  118.     sleep infinity
  119. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement