Changeset 19 for scripts/usr/local/lib/7dtd/commands
- Timestamp:
- May 23, 2014, 6:39:58 PM (10 years ago)
- Location:
- scripts/usr/local/lib/7dtd/commands
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
scripts/usr/local/lib/7dtd/commands/instances.sh
r17 r19 3 3 4 4 5 sdtd CommandInstances() {5 sdtdSubcommandInstancesList() { 6 6 printf "%-*s | %-*s | %-*s | %-*s\n" 20 "Instance name" 8 "Running" 7 "Players" 5 "Port" 7 7 printf -v line "%*s-+-%*s-+-%*s-+-%*s\n" 20 " " 8 " " 7 " " 5 " " … … 22 22 printf "%-*s | %*s | %2s/%2d | %5d\n" 20 "$I" 8 "$run" $cur $max $port 23 23 done 24 exit 0 24 } 25 26 sdtdSubcommandInstancesCreate() { 27 while : ; do 28 readInstanceName 29 [ $(isValidInstance "$INSTANCE") -eq 0 ] && break 30 echo "Instance name already in use." 31 INSTANCE= 32 done 33 echo 34 35 local IPATH=$(getInstancePath "$INSTANCE") 36 mkdir -p "$IPATH" 2>/dev/null 37 38 if [ $(configTemplateExists) -eq 1 ]; then 39 local USETEMPLATE 40 while : ; do 41 read -p "Use the config template? [Yn] " USETEMPLATE 42 USETEMPLATE=${USETEMPLATE:-Y} 43 case $USETEMPLATE in 44 y|Y) 45 cp $SDTD_BASE/templates/config.xml $IPATH/config.xml 46 loadCurrentConfigValues "$INSTANCE" 47 break 48 ;; 49 n|N) 50 break 51 ;; 52 esac 53 done 54 fi 55 configEditAll 56 echo 57 configSetAutoParameters "$INSTANCE" 58 echo 59 echo "Saving" 60 61 if [ ! -f $IPATH/config.xml ]; then 62 echo "<ServerSettings/>" > $IPATH/config.xml 63 fi 64 saveCurrentConfigValues "$INSTANCE" 65 if [ -f "$SDTD_BASE/templates/admins.xml" ]; then 66 cp "$SDTD_BASE/templates/admins.xml" "$IPATH/" 67 fi 68 chown -R $SDTD_USER.$SDTD_GROUP $IPATH 69 echo "Done" 70 } 71 72 sdtdSubcommandInstancesEdit() { 73 if [ $(isValidInstance "$1") -eq 0 ]; then 74 echo "No instance given or not a valid instance!" 75 return 76 fi 77 78 if [ $(isRunning "$1") -eq 0 ]; then 79 INSTANCE=$1 80 loadCurrentConfigValues "$1" 81 configEditAll 82 echo 83 configSetAutoParameters "$INSTANCE" 84 echo 85 echo "Saving" 86 saveCurrentConfigValues "$1" 87 echo "Done" 88 else 89 echo "Instance $1 is currently running. Please stop it first." 90 fi 91 } 92 93 sdtdSubcommandInstancesDelete() { 94 if [ $(isValidInstance "$1") -eq 0 ]; then 95 echo "No instance given or not a valid instance!" 96 return 97 fi 98 99 if [ $(isRunning "$1") -eq 0 ]; then 100 local SECCODE=$(dd if=/dev/urandom bs=1 count=100 2>/dev/null \ 101 | tr -cd '[:alnum:]' | head -c5) 102 local SECCODEIN 103 echo 104 echo "WARNING: Do you really want to delete the following instance?" 105 echo " $1" 106 echo "This will delete all of its configuration and save data." 107 echo "If you REALLY want to continue enter the following security code:" 108 echo " $SECCODE" 109 echo 110 read -p "Security code: " -e SECCODEIN 111 if [ "$SECCODE" = "$SECCODEIN" ]; then 112 rm -R "$(getInstancePath "$1")" 113 echo "Done" 114 else 115 echo "Security code did not match, aborting." 116 fi 117 else 118 echo "Instance $1 is currently running. Please stop it first." 119 fi 120 } 121 122 sdtdCommandInstances() { 123 SUBCMD=$1 124 shift 125 case $SUBCMD in 126 list) 127 sdtdSubcommandInstancesList "$@" 128 ;; 129 create) 130 sdtdSubcommandInstancesCreate "$@" 131 ;; 132 edit) 133 sdtdSubcommandInstancesEdit "$@" 134 ;; 135 delete) 136 sdtdSubcommandInstancesDelete "$@" 137 ;; 138 *) 139 sdtdCommandInstancesHelp 140 ;; 141 esac 25 142 } 26 143 27 144 sdtdCommandInstancesHelp() { 28 echo "Usage: $(basename $0) instances" 29 echo 30 echo "List all defined instances and their status." 145 line() { 146 printf " %-*s %s\n" 19 "$1" "$2" 147 } 148 149 echo "Usage: $(basename $0) instances <subcommand>" 150 echo "Subcommands are:" 151 line "list" "List all defined instances and their status." 152 line "create" "Create a new instance" 153 line "edit <instance>" "Edit an existing instance" 154 line "delete <instance>" "Delete an existing instance" 31 155 } 32 156 … … 34 158 echo "List all defined instances" 35 159 } 160 161 sdtdCommandInstancesExpects() { 162 case $1 in 163 2) 164 echo "list create edit delete" 165 ;; 166 3) 167 case $2 in 168 edit|delete) 169 echo "$(getInstanceList)" 170 ;; 171 esac 172 ;; 173 esac 174 } 175 -
scripts/usr/local/lib/7dtd/commands/status.sh
r17 r19 53 53 54 54 echo 55 exit 056 55 } 57 56 -
scripts/usr/local/lib/7dtd/commands/updateengine.sh
r17 r19 7 7 for I in $(getInstanceList); do 8 8 if [ $(isRunning $I) -eq 1 ]; then 9 echo "At least one instance is still running ."9 echo "At least one instance is still running (\"$I\")." 10 10 echo "Before updating the engine please stop all instances!" 11 11 return
Note:
See TracChangeset
for help on using the changeset viewer.