Browse Source

Set of scripts completed

Laurent HUBERT 6 years ago
parent
commit
457c928c75
5 changed files with 123 additions and 6 deletions
  1. 1 0
      deploy
  2. 33 0
      scripts/02-password
  3. 34 0
      scripts/03-user-password
  4. 53 0
      scripts/04-create-default-user
  5. 2 6
      scripts/50-hostname

+ 1 - 0
deploy

@@ -12,6 +12,7 @@ FIRST_BOOT_BASE_DIR=/etc/first-boot
 FIRST_BOOT_SCRIPTS_DIR=$FIRST_BOOT_BASE_DIR/scripts
 FIRST_BOOT_SCRIPTS_DIR=$FIRST_BOOT_BASE_DIR/scripts
 cp first-boot-init.service ${SYSTEMD_DIR}
 cp first-boot-init.service ${SYSTEMD_DIR}
 mkdir -p $FIRST_BOOT_SCRIPTS_DIR
 mkdir -p $FIRST_BOOT_SCRIPTS_DIR
+rm $FIRST_BOOT_SCRIPTS_DIR/*
 cp first-boot-script $FIRST_BOOT_BASE_DIR/
 cp first-boot-script $FIRST_BOOT_BASE_DIR/
 cp scripts/* $FIRST_BOOT_SCRIPTS_DIR
 cp scripts/* $FIRST_BOOT_SCRIPTS_DIR
 # Resets the flag file
 # Resets the flag file

+ 33 - 0
scripts/02-password

@@ -0,0 +1,33 @@
+#!/bin/bash
+# Licence : GPL v3
+# Author: Laurent HUBERT
+#
+# Changes the root password
+#
+cat <<EOF
+##################################
+# Changing super-user password   #
+##################################
+EOF
+status=1
+
+while [ 0 -ne "$status" ]
+do
+  passwd
+  status=$?
+  if [ 0 -ne "$status" ]
+  then
+    echo "Error changing super-user password"
+    echo "Please try again"
+  else
+    cat <<EOF
+**********************************
+* super-user password : changed  *
+**********************************
+EOF
+    exit 0
+  fi
+done
+
+echo "An error occurred changing super-user password"
+exit $status

+ 34 - 0
scripts/03-user-password

@@ -0,0 +1,34 @@
+#!/bin/bash
+# Licence : GPL v3
+# Author: Laurent HUBERT
+#
+# Changes the default user's password (id=1000)
+#
+# Default user should have id 1000:
+the_user=$(id -u 1000 -n)
+cat <<EOF
+##################################
+# Changing $the_user password #
+##################################
+EOF
+status=1
+while [ 0 -ne "$status" ]
+do
+  passwd $the_user
+  status=$?
+  if [ 0 -ne "$status" ]
+  then
+    echo "Error changing $the_user password"
+    echo "Please try again"
+  else
+    cat <<EOF
+**********************************
+* $the_user password : changed  *
+**********************************
+EOF
+    exit 0
+  fi
+done
+
+echo "An error occurred changing $the_user password"
+exit $status

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

@@ -0,0 +1,53 @@
+#!/bin/bash
+# Licence : GPL v3
+# Author: Laurent HUBERT
+#
+# Creates a new user for administrative purposes (in sudo group)
+#
+cat <<EOF
+##################################
+# Creating default user          #
+##################################
+EOF
+read -p "Please enter default user name: " the_user
+
+if [ -n "$the_user" ]
+then
+  echo Creating user $the_user
+  # Creates the user but disable the login to set the password later:
+  adduser --gecos ,,,, --disabled-login $the_user
+  status=$?
+else
+  # Exit with non zero status
+  exit 1
+fi
+
+if [ 0 -ne "$status" ]
+then
+  echo "Error creating $the_user"
+  echo "Please try again by rebooting"
+else
+  adduser $the_user sudo
+fi
+
+status=1
+while [ 0 -ne "$status" ]
+do
+  passwd $the_user
+  status=$?
+  if [ 0 -ne "$status" ]
+  then
+    echo "Error changing $the_user password"
+    echo "Please try again"
+  else
+    cat <<EOF
+************************************
+* $the_user : created successfully *
+************************************
+EOF
+    exit 0
+  fi
+done
+
+echo "An error occurred changing $the_user password"
+exit $status

+ 2 - 6
scripts/50-hostname

@@ -2,18 +2,13 @@
 # Licence : GPL v3
 # Licence : GPL v3
 # Author: Laurent HUBERT
 # Author: Laurent HUBERT
 #
 #
-# Example file for first-boot-script
-# Copy this file to a new file and add permission execution to the new file
-# Example:
-# # cp skeleton 02-myscript
-# # chmod +x 02-myscript
+# Changes the machine hostname
 #
 #
 cat <<EOF
 cat <<EOF
 ##############################
 ##############################
 # Changing hostname          #
 # Changing hostname          #
 ##############################
 ##############################
 EOF
 EOF
-# Example Section : asking user to enter a value
 read -p "Please enter new hostname: " answer
 read -p "Please enter new hostname: " answer
 
 
 if [ -n "$answer" ]
 if [ -n "$answer" ]
@@ -22,6 +17,7 @@ then
   current=$(hostname)
   current=$(hostname)
   sed -i.firstboot.backup s/$current/$answer/g /etc/hostname
   sed -i.firstboot.backup s/$current/$answer/g /etc/hostname
   sed -i.firstboot.backup s/$current/$answer/g /etc/hosts
   sed -i.firstboot.backup s/$current/$answer/g /etc/hosts
+  hostname $answer
   exit 0
   exit 0
 else
 else
   # Exit with non zero status
   # Exit with non zero status