Ran Qiangjun

Blog/Bloglet about Drupal, Ops, and mORe

Script to Init a New Server

Submitted by jungle on Tue, 12/03/2019 - 00:57

wget -O - http://ranqiangjun.com/sites/default/files/file/2019-12/init.sh | bash -s - jungle

  1. #!/bin/bash
  2. if [ "$#" -eq 0 ]; then
  3. echo Missing username.
  4. exit
  5. fi
  6.  
  7. if [ "$#" -ne 1 ]; then
  8.  
  9. echo Too much args.
  10. exit
  11.  
  12. fi
  13.  
  14. username=$1
  15.  
  16. adduser --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password ${username}
  17. usermod -aG sudo ${username}
  18. # echo "${username}:password" | chpasswd
  19. mkdir -p /home/${username}/.ssh
  20. echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC4W9ib34VKwnK6kGoIcONtplH6PR1ZqvhD31LdRyI6Alf8SiWoqiPBypNxL6k4FO6MBtKoTA0Vnv6E9DfjS8WqRg4qRhglWkshxJPmp+39htYXuj3XRpfRTgiupjpAev3TOI8qrYRnnmD1ojd9NjT/N8DOJmpfAlmG2HwA0v3myDAMWd01BNVB1ZRbZIJ0jrr/uN+6tMLxs4pRgblIlAabRF9nnopYczVsQNPJEiGefRDBpiE5pILZnoLQZF4Yq8JSUm335Fnez9M5AC3hp/VUPkXS+G1PBlgXaVMo6uHZzV2Db98DA1IBE2x1Cx4yhS1IxvzHgsHdBdet0TVSZGOz jungle@ranqiangjun.com' >> /home/${username}/.ssh/authorized_keys
  21. chown ${username}:${username} /home/${username}/.ssh/authorized_keys
  22. chown ${username}:${username} /home/${username}/.ssh
  23. chmod 600 /home/${username}/.ssh/authorized_keys
  24. chmod 700 /home/${username}/.ssh
  25. echo "${username} ALL=NOPASSWD: ALL" >> /etc/sudoers
  26.  
  27.  
  28. # Install docker.
  29. apt-get update
  30. apt-get install -y \
  31. apt-transport-https \
  32. ca-certificates \
  33. curl \
  34. software-properties-common
  35. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
  36. apt-key fingerprint 0EBFCD88
  37. add-apt-repository \
  38. "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
  39. $(lsb_release -cs) \
  40. stable"
  41. apt-get update
  42. # apt-cache madison docker-ce
  43. # apt-get install docker-ce=17.09.0~ce-0~ubuntu
  44. apt-get install -y docker-ce
  45.  
  46. docker run --rm hello-world
  47. groupadd docker
  48. usermod -aG docker ${username}
  49. docker run --rm hello-world
  50. docker rmi hello-world
  51. systemctl enable docker
  52. apt-get install python3-pip -y
  53. pip3 install docker-compose
  54. docker --version
  55. docker-compose --version
  56.  
  57.  
  58. # git configuration.
  59. git config --global user.email "jungle@ranqiangjun.com"
  60. git config --global user.name "Jungle Ran"
©2020 ranqiangjun.com. All rights reserved.