#!/bin/bash # Use find to locate all files with extensions .zip, .tar, or .tgz in /home files=$(find . -maxdepth 1 -name "*.zip" -o -name "*.tar*" -o -name "*.tgz" -type f) file1=$(find . -name "start.sh" -type f) username=$(whoami) mkdir -p lib/mongo mkdir -p log/mongodb PATTERN='$USER' # Create the mongod.service file cat << EOF > /home/$USER/mongod.service [Unit] Description=MongoDB Database Server Documentation=https://docs.mongodb.org/manual After=network-online.target Wants=network-online.target [Service] User=$USER Group=$USER Environment="OPTIONS=-f /home/$USER/mongod.conf" EnvironmentFile=-/etc/sysconfig/mongod ExecStart=/usr/local/bin/mongod \$OPTIONS ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb ExecStartPre=/usr/bin/chown $USER:$USER /var/run/mongodb ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb PermissionsStartOnly=true PIDFile=/var/run/mongodb/mongod.pid Type=fork # file size LimitFSIZE=infinity # cpu time LimitCPU=infinity # virtual memory size LimitAS=infinity # open files LimitNOFILE=64000 # processes/threads LimitNPROC=64000 # locked memory LimitMEMLOCK=infinity # total threads (user+kernel) TasksMax=infinity TasksAccounting=false # Recommended limits for mongod as specified in # https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings [Install] WantedBy=multi-user.target EOF # Create the mongod.conf file cat << EOF > /home/$USER/mongod.conf # mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # where to write logging data. systemLog: destination: file logAppend: true path: /home/$USER/log/mongodb/mongod.log # Where and how to store data. storage: dbPath: /home/$USER/lib/mongo journal: enabled: true # engine: # wiredTiger: # how the process runs processManagement: fork: true # fork and run in background pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile timeZoneInfo: /usr/share/zoneinfo # network interfaces net: port: 27017 bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting. #security: #operationProfiling: #replication: #sharding: ## Enterprise-Only Options #auditLog: #snmp: EOF # Display the list of matching files in a table if [ -n "$files" ]; then echo "The following files were found:" printf '%-5s %-30s\n' "#" "Filename" echo "----------------------------------------" count=1 for file in $files; do printf '%-5s %-30s\n' "$count" "$file" (( count++ )) done else echo "No matching files were found." exit 1 fi # Prompt the user to choose a file to extract, or extract all files by default read -p "Enter the number of the file to extract (e.g. 1), or press Enter to extract all files: " file_num if [ -n "$file_num" ]; then if [ "$file_num" -ge 1 ] && [ "$file_num" -le "$count" ]; then # Extract the chosen file based on its extension chosen_file=$(echo "$files" | sed -n "${file_num}p") case "$chosen_file" in *.zip) mkdir ~/amb unzip "$chosen_file" -d amb path_found=$(find . -name 'elx-stub.jar' -print -quit) path_audit=$(dirname $path_found) echo "$path_audit" path_real=$(echo "$path_audit" | sed 's|^./||') echo "$path_real" sed -i "s|$PATTERN|$username|g" $file1 sed -i 's/external-host = ".*"/external-host = "localhost"/g; s/internal-host = ".*"/internal-host = "localhost"/g; s/mongodb = ".*"/mongodb = "localhost"/g' /home/$username/$path_real/etc/application.conf chmod +x /home/$username/$path_real/bin/run-server ;; *.tar*) mkdir ~/java17 tar xvf "$chosen_file" -C java17 ;; *.tgz) mkdir ~/mongo tar xvfz "$chosen_file" -C mongo ;; *) echo "Unknown file type" exit 1 ;; esac else echo "Invalid file number" exit 1 fi else # Extract all files based on their extension for file in $files; do case "$file" in *.zip) mkdir ~/amb unzip "$file" -d amb path_found=$(find . -name 'elx-stub.jar' -print -quit) path_audit=$(dirname $path_found) echo "$path_audit" path_real=$(echo "$path_audit" | sed 's|^./||') echo "$path_real" sed -i "s|$PATTERN|$username|g" $file1 sed -i 's/external-host = ".*"/external-host = "localhost"/g; s/internal-host = ".*"/internal-host = "localhost"/g; s/mongodb = ".*"/mongodb = "localhost"/g' /home/$username/$path_real/etc/application.conf chmod +x /home/$username/$path_real/bin/run-server ;; *.tar*) mkdir ~/java17 tar xvf "$file" -C java17 ;; *.tgz) mkdir ~/mongo tar xvfz "$file" -C mongo ;; esac done fi # Create the elx-ambience.service file cat << EOF > /home/$USER/elx-ambience.service #!/bin/sh [Unit] Description=Run mongod when machine reboot After=network.target [Service] #Type=simple User=$USER WorkingDirectory=/home/$USER/$path_real/bin ExecStart=/bin/bash /home/$USER/$path_real/bin/run-server Restart=on-failure [Install] WantedBy=multi-user.target EOF