Browse Source

added manu and created function, ran some tests

Bachir Soussi Chiadmi 8 years ago
parent
commit
986b7cc480
1 changed files with 247 additions and 111 deletions
  1. 247 111
      post-install.sh

+ 247 - 111
post-install.sh

@@ -1,47 +1,127 @@
 #! /bin/bash
 
-echo 'Arch Linux Postinstall'
+# COLORS {{{
+Bold=$(tput bold)
+Underline=$(tput sgr 0 1)
+Reset=$(tput sgr0)
+# Regular Colors
+Red=$(tput setaf 1)
+Green=$(tput setaf 2)
+Yellow=$(tput setaf 3)
+Blue=$(tput setaf 4)
+Purple=$(tput setaf 5)
+Cyan=$(tput setaf 6)
+White=$(tput setaf 7)
+# Bold
+BRed=${Bold}$(tput setaf 1)
+BGreen=${Bold}$(tput setaf 2)
+BYellow=${Bold}$(tput setaf 3)
+BBlue=${Bold}$(tput setaf 4)
+BPurple=${Bold}$(tput setaf 5)
+BCyan=${Bold}$(tput setaf 6)
+BWhite=${Bold}$(tput setaf 7)
+
+print_line() {
+  printf "%$(tput cols)s\n"|tr ' ' '-'
+}
+print_title() {
+  #clear
+  print_line
+  echo -e "# ${BPurple}$1${Reset}"
+  print_line
+  echo ""
+}
+print_question(){
+  T_COLS=`tput cols`
+  echo -n "${BBlue}$1${Reset}"
+}
+
+print_msg(){
+  T_COLS=`tput cols`
+  echo -e "${BGreen}$1${Reset}"
+  sleep 2
+}
+
+print_info() {
+  #Console width number
+  T_COLS=`tput cols`
+  echo -e "${Bold}$1${Reset}\n" | fold -sw $(( $T_COLS - 18 )) | sed 's/^/\t    /'
+}
+print_warning() {
+  T_COLS=`tput cols`
+  echo -e "${BYellow}$1${Reset}\n" | fold -sw $(( $T_COLS - 1 ))
+  sleep 4
+}
+
+
+print_title 'Arch Linux Postinstall'
 
 _cwd="$(pwd)"
 
 alpi_user(){
-  echo -n "Create your user? [Y|n]"
+  print_title "Apache Mysql Php"
+  print_question "Create new user? [Y|n]"
   read yn
   yn=${yn:-y}
   if [ "$yn" == "y" ]; then
-    echo -n "Enter user name:"
+    print_question "Enter user name:"
     read username
-    useradd -m -g users -G wheel -s /bin/bash ${username}
+    useradd -m -g users -G wheel,sys -s /bin/bash ${username}
     chfn ${username}
     passwd ${username}
-    echo "user $username created"
+    print_msg "user $username created"
     echo "$username	ALL=(ALL) ALL" >> /etc/sudoers
-    echo "$username added to sudoers"
+    print_msg "$username added to sudoers"
+    print_msg "switching now to $username"
     su ${username}
   fi
 }
 
-# misc
+alpi_avahi(){
+  print_msg "install avahi"
+  sudo pacman -S --needed --noconfirm avahi nss-mdns
+  print_msg "configure avahi"
+  sudo systemctl enable avahi-daemon
+  sudo systemctl start avahi-deamon
+  sed -i.back 's/hosts: files dns myhostname/hosts: files mdns_minimal [NOTFOUND=return] dns myhostname/' /etc/nsswitch.conf
+}
+
 alpi_basics(){
-  sudo pacman -S --needed --noconfirm vim rsync acpi parted imagemagick lynx alsa-utils tmux git
+  print_title "basic packages install"
+  print_question "install basic pkgs? [Y|n]"
+  read yn
+  yn=${yn:-y}
+  if [ "$yn" == "y" ]; then
+    sudo pacman -S --needed --noconfirm vim rsync acpi parted imagemagick lynx wget alsa-utils tmux git openssh knockd avahi nss-mdns
+    print_msg 'securing ssh'
+    sed -i.back 's/^#PermitEmptyPasswords.*/PermitEmptyPasswords no/'
+    sed -i.back 's/^#PermitRootLogin.*/PermitRootLogin no/'
+    sudo systemctl enable sshd
+    sudo systemctl start sshd
+    alpi_avahi
+    print_msg "basic packages installed"
+  fi
 }
 
+
 alpi_cosmetics(){
+  print_title "apply pacman, bash, vim and git config (needs basic pkgs install)"
+  alpi_basics
   # vim
-  echo 'vim configuration'
+  print_msg 'vim configuration'
   sudo pacman -S --needed --noconfirm vim-{spell-fr,spell-en,nerdtree,supertab,systemd}
   cp $_cwp/assets/vim /home/$USER/.vim
   cp $_cwd/assets/vimrc /home/$USER/.vimrc
   sudo cp $_cwd/assets/vim /root/.vim
   sudo cp $_cwd/assets/vimrc /root/.vimrc
 
-  echo 'Git Completion'
-  sudo pacman -S --needed --noconfirm bash-completion wget
+  print_msg 'Git Completion'
+  sudo pacman -S --needed --noconfirm bash-completion
   sudo mkdir /etc/bash_completion.d
   sudo wget -O /etc/bash_completion.d/git-completion.bash https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
 
   # bash & prompt
-  echo 'Bash and Prompt'
+  print_msg 'Bash and Prompt (liquidprompt)'
   git clone https://github.com/hojhan/liquidprompt.git -o github /home/$USER/.liquidprompt
   cp $_cwd/assets/bash_profile /home/$USER/.bash_profile
   cp $_cwd/assets/bashrc /home/$USER/.bashrc
@@ -54,41 +134,51 @@ alpi_cosmetics(){
   echo 'set show-all-if-ambiguous on' >> /home/$USER/.inputrc
   echo 'set completion-ignore-case on' >> /home/$USER/.inputrc
 
-  echo 'ILoveCandy'
+  print_msg 'ILoveCandy (pacman)'
   sudo sed -i.back 's/.*\[options\].*/&\nILoveCandy/' /etc/pacman.conf
   sudo sed -i.back 's/^#Color$/Color/' /etc/pacman.conf
+
+  print_msg 'Config and Cosmetics done'
 }
 
 # GPG
 alpi_gnupg(){
-  echo 'Setup a gpg encripting'
-  echo 'see https://wiki.archlinux.org/index.php/GnuPG'
-  echo -n "create your gpg encrypting key? [Y|n] "
+  print_title 'Setup a gpg encripting'
+  print_msg 'see https://wiki.archlinux.org/index.php/GnuPG'
+  print_question "create your gpg encrypting key? [Y|n] "
   read yn
   yn=${yn:-y}
   if [ "$yn" == "y" ]; then
     gpg --full-gen-key
   fi
+  print_msg 'Gnupg done!'
 }
 
 alpi_secure(){
-  # remove root autologin
+  print_title 'Basic securing system'
+
+  print_msg 'remove root autologin'
   sudo sed -i.back 's/--autologin root //' /etc/systemd/system/getty@tty1.service.d/autologin.conf
-  # remove root login
+
+  print_msg 'remove root login'
   sudo sed -i.back 's/#auth\srequired\spam_wheel.so\suse_uid/auth	required	spam_wheel.so use_uid/' /etc/pam.d/su
   sudo sed -i.back 's/#auth\srequired\spam_wheel.so\suse_uid/auth	required	spam_wheel.so use_uid/' /etc/pam.d/su-l
 
-  # security
+  print_msg 'restrict log access to root'
   sudo touch /etc/sysctl.d/50-dmesg-restrict.conf
   sudo sh -c "echo 'kernel.dmesg_restrict = 1' >> /etc/sysctl.d/50-dmesg-restrict.conf"
   sudo touch /etc/sysctl.d/50-kptr-restrict.con
   sudo sh -c "echo 'kernel.kptr_restrict = 1' >> /etc/sysctl.d/50-kptr-restrict.conf"
+
+  print_msg 'basics secure done'
 }
 
 
 # Display Manager
 alpi_xserver(){
-  echo -n "install Graphical Display Part 1 : Xorg server (you will have to reboot at the end of part 1)? [Y|n] "
+  print_title "install Graphical Display Part 1 : Xorg server"
+  print_msg "you will have to reboot at the end of part 1"
+  print_question "install xorg server? [Y|n] "
   read yn
   yn=${yn:-y}
   if [ "$yn" == "y" ]; then
@@ -104,31 +194,38 @@ alpi_xserver(){
     sudo pacman -S --needed --noconfirm mesa mesa-demos
     sudo gpasswd -a $USER bumblebee
     sudo systemctl enable bumblebeed
+    print_warning "xorg install complete, after reboot, please run part 2 : Desktop manager Plasma5"
+    print_warnig "press enter to reboot"
+    read x
     sudo reboot
   fi
 }
 
 alpi_plasma5(){
-  echo -n "install Graphical Display Part 2 : Kde Plasma 5? [Y|n] "
+  print_title "install Graphical Display Part 2 : Desktop Manager Plasma 5"
+  print_question "install Kde Plasma 5? [Y|n] "
   read yn
   yn=${yn:-y}
   if [ "$yn" == "y" ]; then
     sudo pacman -S --needed --noconfirm --force plasma-meta
     sudo pacman -S --needed --noconfirm ttf-{dejavu,liberation,droid,ubuntu-font-family}
     # network & Bluetooth
-    sudo pacman -S --needed --noconfirm networkmanager-openvpn pulseaudio-alsa rfkill
+    sudo pacman -S --needed --noconfirm networkmanager-openvpn pulseaudio-alsa rfkill systemd-kcm bluedevil
     sudo systemctl enable NetworkManager
     sudo systemctl start NetworkManager
     sudo systemctl enable bluetooth
     sudo systemctl start bluetooth
     touch /home/$USER/.xinitrc
     echo 'exec startkde' > /home/$USER/.xinitrc
+    print_msg "Plasma 5 install complete!"
+    print_msg 'run "startx" to start x server with kde plasma 5'
   fi
 }
 
 # Yaourt
 alpi_yaourt(){
-  echo -n "install Yaourt [Y|n] "
+  print_title "AUR helper : Yaourt"
+  print_question "install Yaourt [Y|n] "
   read yaourt
   yaourt=${yaourt:-y}
   if [ "$yaourt" == "y" ]; then
@@ -145,24 +242,46 @@ alpi_yaourt(){
     makepkg -sri
     echo 'ask for editing config file before build'
     echo "EDITFILES=1" >> ~/.yaourtrc
+    print_msg "Yaourt install complete!"
   fi
 }
 
+alpi_cups(){
+  print_title 'CUPS (for printing)'
+  print_question "install cups [Y|n] "
+  read yn
+  yn=${yn:-y}
+  if [ "$yn" == "y" ]; then
+    sudo pacman -S --needed --noconfirm cups cups-filters libcups ghostscript gsfonts
+    sudo pacman -S --needed --noconfirm gutenprint splix cups-pdf
+    sudo pacman -S --needed --noconfirm print-manager
+    alpi_avahi
+    sudo systemctl enable org.cups.cupsd
+    sudo systemctl start org.cups.cupsd
+    sudo systemctl enable cups-browsed
+    sudo systemctl start cups-browsed
+    print_msg "CUPS install complete!"
+    print_warning "add your user to the sys group if you want to be able to add printers"
+  fi
+}
 
 # kernel LTS
 alpi_kernellts(){
-  echo -n "Switch linux kernel to long term support version (more stable)? [Y|n] "
+  print_title "Long Term Support Kernel"
+  print_question "install kernel-lts)? [Y|n]"
   read yn
   yn=${yn:-y}
   if [ "$yn" == "y" ]; then
     sudo pacman -S linux-lts linux-lts-headers nvidia-lts
     sudo grub-mkconfig -o /boot/grub/grub.cfg
+    print_msg "kernel LTS install complete!"
   fi
 }
 
 alpi_mysql(){
+    print_msg "installe mysql"
     sudo pacman -S --needed --noconfirm mariadb
-    # configure mysql
+    print_msg "configure mysql"
     sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
     mysql_secure_installation
     sudo sed -i.back 's/^log-bin=mysql-bin$/#&/' /etc/mysql/my.cnf
@@ -171,24 +290,23 @@ alpi_mysql(){
 
 # Packages
 alpi_defaultpkgs(){
-  # TODO : install and configure mariadb before that
-  echo "install basic packages? [Y|n]"
+  print_title "Day to day software"
+  print_question "install day to day packages? [Y|n]"
   read yn
   yn=${yn:-y}
   if [ "$yn" == "y" ]; then
-    sudo pacman -S --needed --noconfirm systemd-kcm bluedevil
+    print_msg "file explorer : Dolphin"
     sudo pacman -S --needed --noconfirm dolphin dolphin-plugins
-    echo 'install pim softwares'
-    sudo pacman -S --needed --noconfirm kmail korganizer kaddressbook kdeconnect pidgin
+    print_msg 'Pim softwares : mail, calendar, contact, etc'
+    sudo pacman -S --needed --noconfirm kmail korganizer kaddressbook kdeconnect kleopatra pidgin
     sudo pacman -S --needed --noconfirm spamassassin razor
     sudo sa-update
 
-    echo -n "Install regular mysql support for akonadi? [Y|n] "
+    print_question "Install regular mysql support for akonadi? [Y|n] "
     read ako
     ako=${ako:-y}
     if [ "$ako" == "y" ]; then
-
-      echo -n "Should we install and configure mysql (if not already done)? [y|N] "
+      print_question "Should we install and configure mysql (if not already done)? [y|N] "
       read sql
       sql=${sql:-n}
       if [ "$sql" == "y" ]; then
@@ -196,35 +314,41 @@ alpi_defaultpkgs(){
       fi
 
       # https://forum.kde.org/viewtopic.php?t=84478#p140762
-      echo "please type your root mysql pass-word :"
+      print_question "please type your root mysql password :"
       read -s -p Password: pswd
       mysql -u root -p$pswd -e "create database akonadi;"
       mysql -u root -p$pswd -e "create user 'akonadi'@'localhost' identified by 'akonadi';"
       mysql -u root -p$pswd -e "grant all privileges on akonadi.* to 'akonadi'@'localhost';"
       mysql -u root -p$pswd -e "flush privileges;"
-      # TODO : BUG create first the .config/akonadi folder
+      mkdir -p /home/$USER/.config/akonadi
       mv /home/$USER/.config/akonadi/akonadiserverrc /home/$USER/.config/akonadi/akonadiserverrc.back
       cp $_cwd/assets/akonadiserverrc /home/$USER/.config/akonadi/
+      print_msg "Akonadi configured to use system wide sql server!"
     fi
 
+    print_msg "web browser, terminal emulator, disk tool, password tool"
     sudo pacman -S --needed --noconfirm chromium terminator gparted keepass
-    echo 'install office softwares'
+
+    print_msg 'install office softwares'
     sudo pacman -S --needed --noconfirm gwenview kimageformats kdegraphics-okular kipi-plugins libreoffice-fresh hunspell-{fr,en}
-    echo 'install media softwares'
+    print_msg 'install media softwares'
     sudo pacman -S --needed --noconfirm digikam darktable vlc lua-socket ktorrent banshee
-    echo 'install graphic softwares'
+
+    print_msg 'install graphic softwares'
     sudo pacman -S --needed --noconfirm inkscape gimp scribus fontforge blender
-    #echo 'install some more fonts'
-    #sudo pacman -S ttf-{,}
-    echo 'install cloud softwares'
+
+    print_msg 'install cloud softwares'
     sudo pacman -S --needed --noconfirm owncloud-client syncthing syncthing-gtk syncthing-inotify
-    echo 'increase inotify watch limit'
+    print_msg 'increase inotify watch limit'
     sleep 3
     sudo cp $_cwd/assets/90-inotify.conf /etc/sysctl.d/
 
-    if [ "$yaourt" == "y" ]; then
-      yaourt -S downgrade
-      yaourt -S atom-editor
+    if [ -f /usr/bin/yaourt ];
+      then
+        yaourt -S downgrade
+        yaourt -S atom-editor
+      else
+        print_warning "some packages can't be installed because you don't have yaourt installed"
     fi
   fi
 }
@@ -232,110 +356,122 @@ alpi_defaultpkgs(){
 # LAMP
 alpi_lamp(){
   # https://wiki.archlinux.org/index.php/Apache_HTTP_Server
-  echo -n "Install apache php mysql? [Y|n] "
+  print_title "Web Server (apache, php, mysql)"
+  print_question "Install apache php mysql? [Y|n] "
   read yn
   yn=${yn:-y}
   if [ "$yn" == "y" ]; then
-    # install packages
     sudo pacman -S --needed --noconfirm apache php php-apache phpmyadmin php-mcrypt
-    echo -n "Should we install and configure mysql (if not already done)? [y|N] "
+    print_question "Should we install and configure mysql (if not already done)? [y|N] "
     read sql
     sql=${sql:-n}
     if [ "$sql" == "y" ]; then
       alpi_mysql
     fi
-    # configure apache
+    print_msg "configure apache"
     sudo sed -i.back 's/^LoadModule mpm_event_module modules\/mod_mpm_event\.so$/#&/' /etc/httpd/conf/httpd.conf
     sudo sed -i.back 's/^#LoadModule mpm_prefork_module modules\/mod_mpm_prefork\.so$/LoadModule mpm_prefork_module modules\/mod_mpm_prefork.so/' /etc/httpd/conf/httpd.conf
     sudo sed -i.back 's/^#LoadModule rewrite_module modules\/mod_rewrite\.so$/LoadModule rewrite_module modules\/mod_rewrite.so/' /etc/httpd/conf/httpd.conf
-    # configure vhosts folder
+    print-msg "configure vhosts folder"
     sudo mkdir /etc/httpd/conf/vhosts
     sudo sed -i.back 's/^#Include conf\/extra\/httpd-vhosts\.conf$/&\nInclude conf\/vhosts\/*.conf/' /etc/httpd/conf/httpd.conf
-    # configure apache for php
+    print_msg "configure apache for php"
     sudo sed -i.back 's/^LoadModule dir_module modules\/mod_dir\.so$/&\nLoadModule php5_module modules\/libphp5.so/' /etc/httpd/conf/httpd.conf
     sudo sh -c "echo 'Include conf/extra/php5_module.conf' >> /etc/httpd/conf/httpd.conf"
-    # configure php
+    print_msg "configure php"
     sudo sed -i.back 's/^memory_limit.*$/memory_limit = 512M/' /etc/php/php.ini
     sudo sed -i.back 's/^error_reporting.*$/error_reporting = E_ALL \& ~E_NOTICE/' /etc/php/php.ini
     sudo sed -i.back 's/;extension=gd\.so/extension=gd.so/' /etc/php/php.ini
-    # configure php for mysql
+    print_question "Should we configure custom basedir folder for php? [Y|n] "
+    read bd
+    sql=${bd:-y}
+    if [ "$bd" == "y" ]; then
+      print_question "Please enter the basedir path"
+      read basedir
+      sudo sed -i.back "s/^open_basedir = .*$/&:${basedir}/" /etc/php/php.ini
+    fi
+    print_msg "configure php for mysql"
     sudo sed -i.back 's/;extension=pdo_mysql\.so/extension=pdo_mysql.so/' /etc/php/php.ini
 
-    # configure phpmyadmin
+    print_msg "configure phpmyadmin"
+    sudo sed -i.back 's/;extension=mysqli\.so/extension=mysqli.so/' /etc/php/php.ini
     sudo sed -i.back 's/;extension=mcrypt\.so/extension=mcrypt.so/' /etc/php/php.ini
     sudo sed -i.back 's/;extension=bz2\.so/extension=bz2.so/' /etc/php/php.ini
     sudo sed -i.back 's/;extension=zip\.so/extension=zip.so/' /etc/php/php.ini
     sudo sed -i.back 's/^open_basedir = .*$/&:\/etc\/webapps\//' /etc/php/php.ini
 
-    echo -n "Should we configure custom basedir folder? [Y|n] "
-    read bd
-    sql=${bd:-y}
-    if [ "$bd" == "y" ]; then
-      echo -n "Please enter the basedir path"
-      read basedir
-      sudo sed -i.back "s/^open_basedir = .*$/&:${basedir}/" /etc/php/php.ini
-    fi
     # TODO : instal drush
   fi
 }
 
 # END
 alpi_end(){
-  echo -n "Reboot? [Y|n] "
+  print_question "Reboot now? [Y|n] "
   read yn
   yn=${yn:-y}
   if [ "$yn" != "y" ]; then
-    echo "depending on what you've done you may need to reboot"
+    print_warning "depending on what you've done you may need to reboot"
     exit
   fi
-
+  print_msg "Rebooting in 5sec"
+  sleep 3
   reboot
 }
 
-
-while true
-do
-  echo -e "choosse action (preferably in order)\n"
-  action_list=("create user" "install basics" "cosmetics" "create gnupgp key" "secure the system" "install Xorg Server" "install Plasma 5 (kde)" "yaourt" "switch to LTS kernel" "install default packages" "install lamp" "end");
-  select action in "${action_list[@]}"; do
-    case "$REPLY" in
-      1)
-        alpi_user
-        ;;
-      2)
-        alpi_basics
-        ;;
-      3)
-        alpi_cosmetics
-        ;;
-      4)
-        alpi_gnupg
-        ;;
-      5)
-        alpi_secure
-        ;;
-      6)
-        alpi_xserver
-        ;;
-      7)
-        alpi_plasma5
-        ;;
-      8)
-        alpi_yaourt
-        ;;
-      9)
-        alpi_kernellts
-        ;;
-      10)
-        alpi_defaultpkgs
-        ;;
-      11)
-        alpi_lamp
-        ;;
-      12)
-        alpi_end
-        ;;
-    esac
-    [[ -n $OPT ]] && break
+alpi_menu(){
+  while true
+  do
+    print_question "choose an action (preferably in proposed order)"
+    echo
+    action_list=("create user" "install basics" "cosmetics" "create gnupgp key" "secure the system" "install Xorg Server" "install Plasma 5 (kde)" "yaourt" "cups (printers)" "switch to LTS kernel" "install default packages" "install lamp" "end");
+    select action in "${action_list[@]}"; do
+      case "$REPLY" in
+        1)
+          alpi_user
+          ;;
+        2)
+          alpi_basics
+          ;;
+        3)
+          alpi_cosmetics
+          ;;
+        4)
+          alpi_gnupg
+          ;;
+        5)
+          alpi_secure
+          ;;
+        6)
+          alpi_xserver
+          ;;
+        7)
+          alpi_plasma5
+          ;;
+        8)
+          alpi_yaourt
+          ;;
+        9)
+          alpi_cups
+          ;;
+        10)
+          alpi_kernellts
+          ;;
+        11)
+          alpi_defaultpkgs
+          ;;
+        12)
+          alpi_lamp
+          ;;
+        13)
+          alpi_end
+          ;;
+        *)
+          print_warning "dommage, essaye encore"
+          ;;
+      esac
+      [[ -n $OPT ]] && break
+    done
   done
-done
+}
+
+alpi_menu