Ver código fonte

Arch installation script

Viktor Grahn 2 anos atrás
pai
commit
5a07bf6d9a
1 arquivos alterados com 19 adições e 3 exclusões
  1. 19 3
      archInstall.sh

+ 19 - 3
archInstall.sh

@@ -41,7 +41,11 @@ function preChrootStep {
   read -p "System drive: " DISK
   read -p "Hostname: " HOSTNAME
   read -p "Username: " USERNAME
-  PASSWORD=$(openssl passwd -6)
+  PASSWORD=$(openssl passwd -6) || exit $?
+  printf "Generate ssh key\n"
+  ssh-keygen -f /tmp/id_ed25519 -t ed25519 -C "${USERNAME}@${HOSTNAME}" -q || exit $?
+  SSH_PUB=$(cat /tmp/id_ed25519.pub)
+  SSH_PRIV=$(cat /tmp/id_ed25519)
 
   LOGFILE="archInstall.$(date +%Y%m%d-%H%M%S).log"
 
@@ -117,7 +121,7 @@ function preChrootStep {
   btrfs filesystem mkswapfile --size 8G /mnt/swap/swapfile >> $LOGFILE 2>&1 || exit $?
   swapon /mnt/swap/swapfile
 
-  PACSTRAPPKGS="base linux linux-firmware btrfs-progs grub efibootmgr networkmanager sudo sed git ansible"
+  PACSTRAPPKGS="base base-devel linux linux-firmware btrfs-progs grub efibootmgr networkmanager sudo sed git ansible"
 
   printf "Checking CPU manufacturer\n" | tee -a $LOGFILE
   CPU=$(lscpu | grep "^Vendor ID:" | awk '{ print $3 }')
@@ -164,6 +168,12 @@ function chrootStep {
   useradd -m $USERNAME -G wheel >&2 || exit $?
   echo "${USERNAME}:${PASSWORD}" | chpasswd -e >&2 || exit $?
 
+  printf "Add user ssh key" | tee -a $LOGFILE
+  (umask 066; mkdir /home/${USERNAME}/.ssh)
+  (umask 066; echo "${SSH_PRIV}" > /home/${USERNAME}/.ssh/id_ed25519)
+  (umask 022; echo "${SSH_PUB}" > /home/${USERNAME}/.ssh/id_ed25519.pub)
+  chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}/.ssh
+
   printf "Setting temporary root password\n"
   echo "root:root" | chpasswd >&2 || exit $?
 
@@ -200,7 +210,13 @@ printf "Adding install script to mount directory\n" | tee -a $LOGFILE
 cp $0 /mnt/
 
 printf "Chrooting arch\n" | tee -a $LOGFILE
-DISK="${DISK}" HOSTNAME="${HOSTNAME}" USERNAME="${USERNAME}" PASSWORD="${PASSWORD}" arch-chroot /mnt /$(basename $0) chroot 2>> $LOGFILE | tee -a $LOGFILE
+DISK="${DISK}" \
+  HOSTNAME="${HOSTNAME}" \
+  USERNAME="${USERNAME}" \
+  PASSWORD="${PASSWORD}" \
+  SSH_PUB="${SSH_PUB}" \
+  SSH_PRIV="${SSH_PRIV}" \
+  arch-chroot /mnt /$(basename $0) chroot 2>> $LOGFILE | tee -a $LOGFILE
 if (( ${PIPESTATUS[0]} > 0 )); then
   exit ${PIPESTATUS[0]}
 fi