Advertisement
metalx1000

BASH Configure File Example

Oct 29th, 2022
1,961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.58 KB | Source Code | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2022  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. ######################################################################
  19.  
  20. config_dir="$HOME/.config/examples"
  21. config_file="$config_dir/login.conf"
  22.  
  23. mkdir -p "$config_dir" || exit 1
  24.  
  25. function create_config(){
  26.   read -p "User Name: " user
  27.   read -s -p "Password: " password
  28.   echo
  29.   read -p "Server Address: " server
  30.   read -p "Port: " port
  31.   read -p "Message: " msg
  32.  
  33.   echo "
  34.  user='$user'
  35.  password='$password'
  36.  server='$server'
  37.  port='$port'
  38.  msg='$msg'
  39.  " > "$config_file"
  40. }
  41.  
  42. [[ -f "$config_file" ]] ||  create_config
  43. source "$config_file"
  44.  
  45. [[ $user ]] || create_config
  46. [[ $password ]] || create_config
  47. [[ $server ]] || create_config
  48. [[ $port ]] || create_config
  49. [[ $msg ]] || create_config
  50.  
  51. wget -qO- --user "$user" --password "$password" "http://$server:$port/?msg=$msg" || echo fail
  52.  
Tags: Config BASH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement