Procházet zdrojové kódy

Script started at user and root login

Laurent HUBERT před 6 roky
rodič
revize
aa1b1f13b0

+ 10 - 1
deploy

@@ -19,7 +19,16 @@ cp scripts/* $FIRST_BOOT_SCRIPTS_DIR
 touch $FIRST_BOOT_BASE_DIR/.mustrun
 
 # Deploys
-systemctl enable first-boot-init.service
+#See to make automatic root at first login https://serverfault.com/questions/760391/make-no-password-required-on-local-linux-tty-login
+cp /root/.profile /root/.profile.firstboot
+grep -F "$FIRST_BOOT_BASE_DIR" /root/.profile > /dev/null || echo $FIRST_BOOT_BASE_DIR/first-boot-script >> /root/.profile
+
+the_user=$(id -u 1000 -n)
+cp /home/$the_user/.profile /home/$the_user/.profile.firstboot
+grep -F "$FIRST_BOOT_BASE_DIR" /home/$the_user/.profile > /dev/null || echo sudo $FIRST_BOOT_BASE_DIR/first-boot-script >> /home/$the_user/.profile
+
+#https://stackoverflow.com/questions/14152026/how-can-i-automatically-login-on-a-tty-and-execute-a-script
+#https://unix.stackexchange.com/questions/401759/automatically-login-on-debian-9-2-1-command-line
 
 echo "You can now run rm -r on this directory"
 echo "e.g. :"

+ 1 - 1
first-boot-init.service

@@ -4,7 +4,7 @@ ConditionPathExists=/etc/first-boot/.mustrun
 
 [Service]
 Type=oneshot
-ExecStart=/etc/first-boot/scripts/first-boot-script
+ExecStart=/etc/first-boot/first-boot-script
 
 [Install]
 WantedBy=multi-user.target

+ 5 - 0
first-boot-script

@@ -6,6 +6,11 @@
 FIRST_BOOT_BASE_DIR=/etc/first-boot
 FIRST_BOOT_SCRIPTS_DIR=$FIRST_BOOT_BASE_DIR/scripts
 
+if [ ! -r /etc/first-boot/.mustrun ]
+then
+  exit 0
+fi
+
 if [[ $EUID -ne 0 ]]; then
 	 echo "This script cannot work if not super-user. Please run as root" 1>&2
 	 exit 1

+ 7 - 1
scripts/01-renew-ssh-keys

@@ -10,7 +10,13 @@ cat <<EOF
 ##################################
 EOF
 status=0
-ls /etc/ssh/ssh_host_*key* > /dev/null 2>&1 && dpkg-reconfigure openssh-server || status=1
+renew_ssh_keys(){
+  rm /etc/ssh/ssh_host_*key*
+  dpkg-reconfigure openssh-server
+  status=$?
+}
+
+ls /etc/ssh/ssh_host_*key* > /dev/null 2>&1 && renew_ssh_keys || status=1
 if [ 0 -ne "$status" ]
 then
   # Exit with non zero status

+ 0 - 0
scripts/02-password


+ 0 - 0
scripts/03-user-password


+ 0 - 0
scripts/04-create-default-user


+ 0 - 0
scripts/50-hostname