Collection of scripts for interfacing with proxmox containers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
4.1 KiB

  1. #!/usr/bin/env bash
  2. ##########################
  3. # Arch Linux initilizing script
  4. ##########################
  5. # Header for this script
  6. TITLE="Arch_Setup"
  7. LOGFILE=/tmp/$TITLE.log
  8. DEPTH=1
  9. if [[ $DEPTH == 0 ]]; then
  10. TAGSTR="-->"
  11. elif [[ $DEPTH == 1 ]]; then
  12. TAGSTR="--->"
  13. elif [[ $DEPTH == 2 ]]; then
  14. TAGSTR="----->"
  15. elif [[ $DEPTH == 3 ]]; then
  16. TAGSTR="------>"
  17. fi
  18. echo "$TAGSTR ====== $TITLE (Logged to $LOGFILE) ======"
  19. # For making the script stop if something fails like make.
  20. set -e
  21. set -o pipefail
  22. # Enable and start sshd so we can ssh in here in the future.
  23. echo "$TAGSTR Enabling SSH"
  24. systemctl enable sshd >> $LOGFILE 2>&1
  25. systemctl start sshd >> $LOGFILE 2>&1
  26. # Setup keys for pacman
  27. echo "$TAGSTR Setting up keys for pacman"
  28. pacman-key --init >> $LOGFILE 2>&1
  29. pacman-key --populate archlinux >> $LOGFILE 2>&1
  30. # Setup mirrors, hardcoded for now. Could have been done with rankmirror
  31. # with USA and worldwide mirrors but eh.
  32. echo "$TAGSTR Setting up mirror list"
  33. if [[ -e /etc/pacman.d/mirrorlist ]]; then
  34. mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup # >> $LOGFILE 2>&1
  35. fi
  36. cat <<- 'EOM05594313219813' > /etc/pacman.d/mirrorlist
  37. # Server list generated by rankmirrors on 2017-11-03
  38. ##
  39. ## Arch Linux repository mirrorlist
  40. ## Generated on 2017-06-28
  41. ##
  42. ## Worldwide
  43. ## United States
  44. Server = http://mirror.nexcess.net/archlinux/$repo/os/$arch
  45. Server = http://mirror.epiphyte.network/archlinux/$repo/os/$arch
  46. Server = http://arch.mirror.constant.com/$repo/os/$arch
  47. Server = http://mirrors.evowise.com/archlinux/$repo/os/$arch
  48. Server = http://mirrors.advancedhosters.com/archlinux/$repo/os/$arch
  49. Server = http://mirror.math.princeton.edu/pub/archlinux/$repo/os/$arch
  50. EOM05594313219813
  51. # Update as needed.
  52. echo "$TAGSTR Updating all packages as needed"
  53. pacman -Syu --noconfirm --noprogressbar --needed >> $LOGFILE 2>&1
  54. # Do an update and install some packages.
  55. echo "$TAGSTR Installing base-devel, git, htop, vim, rsync, go, dotnet-sdk, wget, tmux, fish, and cowsay"
  56. pacman -S base-devel git htop vim cowsay rsync go dotnet-sdk wget fish tmux --noconfirm --noprogressbar --needed >> $LOGFILE 2>&1
  57. # Change locale to EN US UTF-8
  58. echo "$TAGSTR Changing locale to EN US UTF-8"
  59. sed -i 's/if (( EUID == 0 )); then/if (( 0 )); then/' /usr/bin/makepkg >> $LOGFILE 2>&1
  60. sed -i 's/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen >> $LOGFILE 2>&1
  61. locale-gen >> $LOGFILE 2>&1
  62. echo LANG=en_US.UTF-8 > /etc/locale.conf >> $LOGFILE 2>&1
  63. export LANG=en_US.UTF-8
  64. # Change our shell to fish
  65. echo "$TAGSTR Changing shell to fish"
  66. chsh -s /usr/bin/fish >> $LOGFILE 2>&1
  67. # Install yay. Why yay instead of pacaur? Because pacaur doesn't allow
  68. # itself to be ran as root, even though all we have is root in the container,
  69. # and I don't want to bother fiddling with users just for this. Yay on the
  70. # other hand works fine for this.
  71. if ! [ -x "$(command -v yay)" ]; then
  72. # Disable root check for makepkg since we are using root for everything.
  73. # Replace the "if (( EUID == 0 )); then" with "if (( 0 )); then" to force root
  74. # check to always fail.
  75. sed -i 's/if (( EUID == 0 )); then/if (( 0 )); then/' /usr/bin/makepkg >> $LOGFILE 2>&1
  76. echo "$TAGSTR Installing package-query and yay"
  77. mkdir ~/tmp
  78. cd ~/tmp
  79. # ----------- package query for yay -----------
  80. echo "$TAGSTR Installing package-query" >> $LOGFILE
  81. git clone https://aur.archlinux.org/package-query.git >> $LOGFILE 2>&1
  82. cd package-query
  83. makepkg -si --noconfirm >> $LOGFILE 2>&1
  84. cd ~/tmp
  85. # ----------- yay itself -----------
  86. echo "$TAGSTR Installing yay" >> $LOGFILE
  87. git clone https://aur.archlinux.org/yay.git >> $LOGFILE 2>&1
  88. cd yay
  89. makepkg -si --noconfirm >> $LOGFILE 2>&1
  90. # Wipe tmp dir
  91. cd ~
  92. rm -r -f ~/tmp
  93. fi
  94. # Get the ip addresses using some grep and awk magic.
  95. # Magic inspired by this: https://superuser.com/questions/468727/how-to-get-the-ipv6-ip-address-of-linux-machine
  96. ipv6addr=$(ip addr show dev eth0 | grep "inet6 fe80" | awk '{a=$2; split(a, b, "/"); print b[1]}')
  97. ipv4addr=$(ip addr show dev eth0 | grep "inet 10" | awk '{a=$2; split(a, b, "/"); print b[1]}')
  98. # Lastly, say we are done.
  99. echo "$TAGSTR Completed $TITLE"
  100. echo "$TAGSTR Completed $TITLE" >> $LOGFILE