post-install.sh 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. #! /bin/bash
  2. # COLORS {{{
  3. Bold=$(tput bold)
  4. Underline=$(tput sgr 0 1)
  5. Reset=$(tput sgr0)
  6. # Regular Colors
  7. Red=$(tput setaf 1)
  8. Green=$(tput setaf 2)
  9. Yellow=$(tput setaf 3)
  10. Blue=$(tput setaf 4)
  11. Purple=$(tput setaf 5)
  12. Cyan=$(tput setaf 6)
  13. White=$(tput setaf 7)
  14. # Bold
  15. BRed=${Bold}$(tput setaf 1)
  16. BGreen=${Bold}$(tput setaf 2)
  17. BYellow=${Bold}$(tput setaf 3)
  18. BBlue=${Bold}$(tput setaf 4)
  19. BPurple=${Bold}$(tput setaf 5)
  20. BCyan=${Bold}$(tput setaf 6)
  21. BWhite=${Bold}$(tput setaf 7)
  22. print_line() {
  23. printf "%$(tput cols)s\n"|tr ' ' '-'
  24. }
  25. print_title() {
  26. #clear
  27. print_line
  28. echo -e "# ${BPurple}$1${Reset}"
  29. print_line
  30. echo ""
  31. }
  32. print_question(){
  33. T_COLS=`tput cols`
  34. echo -n "${BBlue}$1${Reset}"
  35. }
  36. print_msg(){
  37. T_COLS=`tput cols`
  38. echo -e "${BGreen}$1${Reset}"
  39. sleep 2
  40. }
  41. print_info() {
  42. #Console width number
  43. T_COLS=`tput cols`
  44. echo -e "${Bold}$1${Reset}\n" | fold -sw $(( $T_COLS - 18 )) | sed 's/^/\t /'
  45. }
  46. print_warning() {
  47. T_COLS=`tput cols`
  48. echo -e "${BYellow}$1${Reset}\n" | fold -sw $(( $T_COLS - 1 ))
  49. sleep 4
  50. }
  51. print_title 'Arch Linux Postinstall'
  52. _cwd="$(pwd)"
  53. alpi_user(){
  54. print_title "User"
  55. print_question "Create new user? [Y|n]"
  56. read yn
  57. yn=${yn:-y}
  58. if [ "$yn" == "y" ]; then
  59. print_question "Enter user name:"
  60. read username
  61. useradd -m -g users -G wheel,sys -s /bin/bash ${username}
  62. chfn ${username}
  63. passwd ${username}
  64. print_msg "user $username created"
  65. echo "$username ALL=(ALL) ALL" >> /etc/sudoers
  66. print_msg "$username added to sudoers"
  67. print_msg "switching now to $username"
  68. su ${username}
  69. fi
  70. }
  71. alpi_avahi(){
  72. print_msg "install avahi"
  73. sudo pacman -S --needed --noconfirm avahi nss-mdns
  74. print_msg "configure avahi"
  75. sudo systemctl enable avahi-daemon
  76. sudo systemctl start avahi-deamon
  77. sed -i.back 's/hosts: files dns myhostname/hosts: files mdns_minimal [NOTFOUND=return] dns myhostname/' /etc/nsswitch.conf
  78. }
  79. alpi_basics(){
  80. print_title "basic packages install"
  81. print_question "install basic pkgs? [Y|n]"
  82. read yn
  83. yn=${yn:-y}
  84. if [ "$yn" == "y" ]; then
  85. sudo pacman -S --needed --noconfirm vim rsync acpi parted imagemagick lynx wget alsa-utils tmux git openssh knockd bluez-utils htop
  86. print_msg 'securing ssh'
  87. sed -i.back 's/^#PermitEmptyPasswords.*/PermitEmptyPasswords no/' /etc/ssh/sshd_config
  88. sed -i.back 's/^#PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
  89. sudo systemctl enable sshd
  90. sudo systemctl start sshd
  91. alpi_avahi
  92. print_msg "basic packages installed"
  93. fi
  94. }
  95. alpi_cosmetics(){
  96. print_title "apply pacman, bash, vim and git config (needs basic pkgs install)"
  97. alpi_basics
  98. # vim
  99. print_msg 'vim configuration'
  100. sudo pacman -S --needed --noconfirm vim-{spell-fr,spell-en,nerdtree,supertab,systemd}
  101. cp $_cwp/assets/vim /home/$USER/.vim
  102. cp $_cwd/assets/vimrc /home/$USER/.vimrc
  103. sudo cp $_cwd/assets/vim /root/.vim
  104. sudo cp $_cwd/assets/vimrc /root/.vimrc
  105. print_msg 'Git Completion'
  106. sudo pacman -S --needed --noconfirm bash-completion
  107. sudo mkdir /etc/bash_completion.d
  108. sudo wget -O /etc/bash_completion.d/git-completion.bash https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
  109. # bash & prompt
  110. print_msg 'Bash and Prompt (liquidprompt)'
  111. git clone https://github.com/nojhan/liquidprompt.git -o github /home/$USER/.liquidprompt
  112. cp $_cwd/assets/bash_profile /home/$USER/.bash_profile
  113. cp $_cwd/assets/bashrc /home/$USER/.bashrc
  114. mkdir /home/$USER/.config
  115. cp $_cwd/assets/config/liquipromptrc /home/$USER/.config/
  116. # sudo pacman -S --needed --noconfirm bash-completion
  117. source /home/$USER/.bashrc
  118. touch /home/$USER/.inputrc
  119. echo 'set show-all-if-ambiguous on' >> /home/$USER/.inputrc
  120. echo 'set completion-ignore-case on' >> /home/$USER/.inputrc
  121. print_msg 'ILoveCandy (pacman)'
  122. sudo sed -i.back 's/.*\[options\].*/&\nILoveCandy/' /etc/pacman.conf
  123. sudo sed -i.back 's/^#Color$/Color/' /etc/pacman.conf
  124. print_msg 'Config and Cosmetics done'
  125. }
  126. # GPG
  127. alpi_gnupg(){
  128. print_title 'Setup a gpg encripting'
  129. print_msg 'see https://wiki.archlinux.org/index.php/GnuPG'
  130. print_question "create your gpg encrypting key? [Y|n] "
  131. read yn
  132. yn=${yn:-y}
  133. if [ "$yn" == "y" ]; then
  134. gpg --full-gen-key
  135. fi
  136. print_msg 'Gnupg done!'
  137. }
  138. alpi_secure(){
  139. print_title 'Basic securing system'
  140. print_msg 'remove root autologin'
  141. sudo sed -i.back 's/--autologin root //' /etc/systemd/system/getty@tty1.service.d/autologin.conf
  142. print_msg 'remove root login'
  143. sudo sed -i.back 's/#auth\srequired\spam_wheel.so\suse_uid/auth required spam_wheel.so use_uid/' /etc/pam.d/su
  144. sudo sed -i.back 's/#auth\srequired\spam_wheel.so\suse_uid/auth required spam_wheel.so use_uid/' /etc/pam.d/su-l
  145. print_msg 'restrict log access to root'
  146. sudo touch /etc/sysctl.d/50-dmesg-restrict.conf
  147. sudo sh -c "echo 'kernel.dmesg_restrict = 1' >> /etc/sysctl.d/50-dmesg-restrict.conf"
  148. sudo touch /etc/sysctl.d/50-kptr-restrict.con
  149. sudo sh -c "echo 'kernel.kptr_restrict = 1' >> /etc/sysctl.d/50-kptr-restrict.conf"
  150. print_msg 'basics secure done'
  151. }
  152. # Display Manager
  153. alpi_xserver(){
  154. print_title "install Graphical Display Part 1 : Xorg server"
  155. print_msg "you will have to reboot at the end of part 1"
  156. print_question "install xorg server? [Y|n] "
  157. read yn
  158. yn=${yn:-y}
  159. if [ "$yn" == "y" ]; then
  160. # touch pad
  161. sudo pacman -S --needed --noconfirm xf86-input-libinput
  162. # integred gpu
  163. sudo pacman -S --needed --noconfirm xf86-input-libinput xf86-video-intel
  164. # discret gpu
  165. sudo pacman -S --needed --noconfirm bbswitch bumblebee primus
  166. sudo pacman -S --needed --noconfirm nvidia nvidia-utils
  167. # xorg server
  168. sudo pacman -S --needed --noconfirm xorg-xinit xorg-server-devel
  169. sudo pacman -S --needed --noconfirm mesa mesa-demos
  170. sudo gpasswd -a $USER bumblebee
  171. sudo systemctl enable bumblebeed
  172. print_warning "xorg install complete, after reboot, please run part 2 : Desktop manager Plasma5"
  173. print_warnig "press enter to reboot"
  174. read x
  175. sudo reboot
  176. fi
  177. }
  178. alpi_plasma5(){
  179. print_title "install Graphical Display Part 2 : Desktop Manager Plasma 5"
  180. print_question "install Kde Plasma 5? [Y|n] "
  181. read yn
  182. yn=${yn:-y}
  183. if [ "$yn" == "y" ]; then
  184. sudo pacman -S --needed --noconfirm --force plasma-meta
  185. sudo pacman -S --needed --noconfirm ttf-{dejavu,liberation,droid,ubuntu-font-family}
  186. # network & Bluetooth
  187. sudo pacman -S --needed --noconfirm networkmanager-openvpn pulseaudio-alsa pulseaudio-dlna rfkill systemd-kcm bluedevil
  188. sudo systemctl enable NetworkManager
  189. sudo systemctl start NetworkManager
  190. sudo systemctl enable bluetooth
  191. sudo systemctl start bluetooth
  192. touch /home/$USER/.xinitrc
  193. echo 'exec startkde' > /home/$USER/.xinitrc
  194. print_msg "Plasma 5 install complete!"
  195. print_msg 'run "startx" to start x server with kde plasma 5'
  196. fi
  197. }
  198. # Yaourt
  199. alpi_yaourt(){
  200. print_title "AUR helper : Yaourt"
  201. print_question "install Yaourt [Y|n] "
  202. read yaourt
  203. yaourt=${yaourt:-y}
  204. if [ "$yaourt" == "y" ]; then
  205. sudo pacman -S --needed base-devel
  206. mkdir -p /home/$USER/Developer/Linux/build-repos
  207. wget -O /home/$USER/Developer/Linux/build-repos/package-query.tar.gz https://aur.archlinux.org/cgit/aur.git/snapshot/package-query.tar.gz
  208. wget -O /home/$USER/Developer/Linux/build-repos/yaourt.tar.gz https://aur.archlinux.org/cgit/aur.git/snapshot/yaourt.tar.gz
  209. cd /home/$USER/Developer/Linux/build-repos
  210. tar -xvf package-query.tar.gz
  211. tar -xvf yaourt.tar.gz
  212. cd package-query
  213. makepkg -sri
  214. cd ../yaourt
  215. makepkg -sri
  216. echo 'ask for editing config file before build'
  217. echo "EDITFILES=1" >> ~/.yaourtrc
  218. print_msg "Yaourt install complete!"
  219. fi
  220. }
  221. alpi_cups(){
  222. print_title 'CUPS (for printing)'
  223. print_question "install cups [Y|n] "
  224. read yn
  225. yn=${yn:-y}
  226. if [ "$yn" == "y" ]; then
  227. sudo pacman -S --needed --noconfirm cups cups-filters libcups ghostscript gsfonts
  228. sudo pacman -S --needed --noconfirm gutenprint splix cups-pdf
  229. sudo pacman -S --needed --noconfirm print-manager
  230. alpi_avahi
  231. sudo systemctl enable org.cups.cupsd
  232. sudo systemctl start org.cups.cupsd
  233. sudo systemctl enable cups-browsed
  234. sudo systemctl start cups-browsed
  235. print_msg "CUPS install complete!"
  236. print_warning "add your user to the sys group if you want to be able to add printers"
  237. fi
  238. }
  239. # kernel LTS
  240. alpi_kernellts(){
  241. print_title "Long Term Support Kernel"
  242. print_question "install kernel-lts)? [Y|n]"
  243. read yn
  244. yn=${yn:-y}
  245. if [ "$yn" == "y" ]; then
  246. sudo pacman -S linux-lts linux-lts-headers nvidia-lts bbswitch-lts
  247. #sudo grub-mkconfig -o /boot/grub/grub.cfg
  248. print_msg "kernel LTS install complete!"
  249. fi
  250. }
  251. alpi_mysql(){
  252. print_msg "installe mysql"
  253. sudo pacman -S --needed --noconfirm mariadb
  254. print_msg "configure mysql"
  255. sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
  256. mysql_secure_installation
  257. sudo sed -i.back 's/^log-bin=mysql-bin$/#&/' /etc/mysql/my.cnf
  258. sudo sed -i.back 's/^max_allowed_packet.*$/max_allowed_packet = 16M/' /etc/mysql/my.cnf
  259. }
  260. # Packages
  261. alpi_defaultpkgs(){
  262. print_title "Day to day software"
  263. print_question "install day to day packages? [Y|n]"
  264. read yn
  265. yn=${yn:-y}
  266. if [ "$yn" == "y" ]; then
  267. print_msg "file explorer : Dolphin"
  268. sudo pacman -S --needed --noconfirm dolphin dolphin-plugins
  269. print_msg 'Pim softwares : mail, calendar, contact, etc'
  270. sudo pacman -S --needed --noconfirm kmail korganizer kaddressbook kdeconnect kleopatra pidgin
  271. sudo pacman -S --needed --noconfirm spamassassin razor
  272. sudo sa-update
  273. print_question "Install regular mysql support for akonadi? [Y|n] "
  274. read ako
  275. ako=${ako:-y}
  276. if [ "$ako" == "y" ]; then
  277. print_question "Should we install and configure mysql (if not already done)? [y|N] "
  278. read sql
  279. sql=${sql:-n}
  280. if [ "$sql" == "y" ]; then
  281. alpi_mysql
  282. fi
  283. # https://forum.kde.org/viewtopic.php?t=84478#p140762
  284. print_question "please type your root mysql password :"
  285. read -s -p Password: pswd
  286. mysql -u root -p$pswd -e "create database akonadi;"
  287. mysql -u root -p$pswd -e "create user 'akonadi'@'localhost' identified by 'akonadi';"
  288. mysql -u root -p$pswd -e "grant all privileges on akonadi.* to 'akonadi'@'localhost';"
  289. mysql -u root -p$pswd -e "flush privileges;"
  290. mkdir -p /home/$USER/.config/akonadi
  291. mv /home/$USER/.config/akonadi/akonadiserverrc /home/$USER/.config/akonadi/akonadiserverrc.back
  292. cp $_cwd/assets/akonadiserverrc /home/$USER/.config/akonadi/
  293. print_msg "Akonadi configured to use system wide sql server!"
  294. fi
  295. print_msg "web browser, terminal emulator, disk tool, password tool"
  296. sudo pacman -S --needed --noconfirm chromium terminator gparted keepass
  297. print_msg 'install office softwares'
  298. sudo pacman -S --needed --noconfirm gwenview kimageformats kdegraphics-okular kipi-plugins libreoffice-fresh hunspell-{fr,en}
  299. print_msg 'install media softwares'
  300. sudo pacman -S --needed --noconfirm digikam darktable vlc lua-socket ktorrent banshee
  301. print_msg 'install graphic softwares'
  302. sudo pacman -S --needed --noconfirm inkscape gimp scribus fontforge blender
  303. print_msg 'web dev softwares'
  304. sudo pacman -S --needed --noconfirm firefox filezilla gulp
  305. print_msg 'install cloud softwares'
  306. sudo pacman -S --needed --noconfirm owncloud-client syncthing syncthing-gtk syncthing-inotify
  307. print_msg 'increase inotify watch limit'
  308. sleep 3
  309. sudo cp $_cwd/assets/90-inotify.conf /etc/sysctl.d/
  310. if [ -f /usr/bin/yaourt ];
  311. then
  312. yaourt -S downgrade
  313. yaourt -S atom-editor
  314. else
  315. print_warning "some packages can't be installed because you don't have yaourt installed"
  316. fi
  317. fi
  318. }
  319. # LAMP
  320. alpi_lamp(){
  321. # https://wiki.archlinux.org/index.php/Apache_HTTP_Server
  322. print_title "Web Server (apache, php, mysql)"
  323. print_question "Install apache php mysql? [Y|n] "
  324. read yn
  325. yn=${yn:-y}
  326. if [ "$yn" == "y" ]; then
  327. sudo pacman -S --needed --noconfirm apache php php-apache phpmyadmin php-mcrypt php-gd
  328. print_question "Should we install and configure mysql (if not already done)? [y|N] "
  329. read sql
  330. sql=${sql:-n}
  331. if [ "$sql" == "y" ]; then
  332. alpi_mysql
  333. fi
  334. print_msg "configure apache"
  335. sudo sed -i.back 's/^LoadModule mpm_event_module modules\/mod_mpm_event\.so$/#&/' /etc/httpd/conf/httpd.conf
  336. 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
  337. sudo sed -i.back 's/^#LoadModule rewrite_module modules\/mod_rewrite\.so$/LoadModule rewrite_module modules\/mod_rewrite.so/' /etc/httpd/conf/httpd.conf
  338. print-msg "configure vhosts folder"
  339. sudo mkdir /etc/httpd/conf/vhosts
  340. sudo sed -i.back 's/^#Include conf\/extra\/httpd-vhosts\.conf$/&\nInclude conf\/vhosts\/*.conf/' /etc/httpd/conf/httpd.conf
  341. print_msg "configure apache for php"
  342. sudo sed -i.back 's/^LoadModule dir_module modules\/mod_dir\.so$/&\nLoadModule php5_module modules\/libphp5.so/' /etc/httpd/conf/httpd.conf
  343. sudo sh -c "echo 'Include conf/extra/php5_module.conf' >> /etc/httpd/conf/httpd.conf"
  344. print_msg "configure php"
  345. sudo sed -i.back 's/^memory_limit.*$/memory_limit = 512M/' /etc/php/php.ini
  346. sudo sed -i.back 's/^error_reporting.*$/error_reporting = E_ALL \& ~E_NOTICE/' /etc/php/php.ini
  347. sudo sed -i.back 's/;extension=gd\.so/extension=gd.so/' /etc/php/php.ini
  348. print_question "Should we configure custom basedir folder for php? [Y|n] "
  349. read bd
  350. sql=${bd:-y}
  351. if [ "$bd" == "y" ]; then
  352. print_question "Please enter the basedir path"
  353. read basedir
  354. sudo sed -i.back "s/^open_basedir = .*$/&:${basedir}/" /etc/php/php.ini
  355. fi
  356. print_msg "configure php for mysql"
  357. sudo sed -i.back 's/;extension=pdo_mysql\.so/extension=pdo_mysql.so/' /etc/php/php.ini
  358. print_msg "configure phpmyadmin"
  359. sudo sed -i.back 's/;extension=mysqli\.so/extension=mysqli.so/' /etc/php/php.ini
  360. sudo sed -i.back 's/;extension=mcrypt\.so/extension=mcrypt.so/' /etc/php/php.ini
  361. sudo sed -i.back 's/;extension=bz2\.so/extension=bz2.so/' /etc/php/php.ini
  362. sudo sed -i.back 's/;extension=zip\.so/extension=zip.so/' /etc/php/php.ini
  363. sudo sed -i.back 's/^open_basedir = .*$/&:\/etc\/webapps\//' /etc/php/php.ini
  364. # TODO : instal drush
  365. fi
  366. }
  367. # END
  368. alpi_end(){
  369. print_question "Reboot now? [Y|n] "
  370. read yn
  371. yn=${yn:-y}
  372. if [ "$yn" != "y" ]; then
  373. print_warning "depending on what you've done you may need to reboot"
  374. exit
  375. fi
  376. print_msg "Rebooting in 5sec"
  377. sleep 3
  378. reboot
  379. }
  380. alpi_menu(){
  381. while true
  382. do
  383. print_question "choose an action (preferably in proposed order)"
  384. echo
  385. 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");
  386. select action in "${action_list[@]}"; do
  387. case "$REPLY" in
  388. 1)
  389. alpi_user
  390. ;;
  391. 2)
  392. alpi_basics
  393. ;;
  394. 3)
  395. alpi_cosmetics
  396. ;;
  397. 4)
  398. alpi_gnupg
  399. ;;
  400. 5)
  401. alpi_secure
  402. ;;
  403. 6)
  404. alpi_xserver
  405. ;;
  406. 7)
  407. alpi_plasma5
  408. ;;
  409. 8)
  410. alpi_yaourt
  411. ;;
  412. 9)
  413. alpi_cups
  414. ;;
  415. 10)
  416. alpi_kernellts
  417. ;;
  418. 11)
  419. alpi_defaultpkgs
  420. ;;
  421. 12)
  422. alpi_lamp
  423. ;;
  424. 13)
  425. alpi_end
  426. ;;
  427. *)
  428. print_warning "dommage, essaye encore"
  429. ;;
  430. esac
  431. [[ -n $OPT ]] && break
  432. done
  433. done
  434. }
  435. alpi_menu