freedombone-utils-setup 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Setup functions
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 Bob Mottram <bob@freedombone.net>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. if [ ! $PROJECT_NAME ]; then
  31. PROJECT_NAME='freedombone'
  32. fi
  33. DEFAULT_DOMAIN_NAME=
  34. DEFAULT_DOMAIN_CODE=
  35. MY_USERNAME=
  36. if [ ! $SYSTEM_TYPE ]; then
  37. SYSTEM_TYPE="full"
  38. fi
  39. # An optional configuration file which overrides some of these variables
  40. if [ ! $CONFIGURATION_FILE ]; then
  41. CONFIGURATION_FILE="$HOME/${PROJECT_NAME}.cfg"
  42. fi
  43. # Directory where source code is downloaded and compiled
  44. INSTALL_DIR=$HOME/build
  45. # device name for an attached usb drive
  46. USB_DRIVE=/dev/sda1
  47. # Location where the USB drive is mounted to
  48. USB_MOUNT=/mnt/usb
  49. # Number of days to keep backups for
  50. BACKUP_MAX_DAYS=30
  51. # file containing a list of remote locations to backup to
  52. # Format: [username@friendsdomain//home/username] [ssh_password]
  53. # With the only space character being between the server and the password
  54. FRIENDS_SERVERS_LIST=/home/$MY_USERNAME/backup.list
  55. export DEBIAN_FRONTEND=noninteractive
  56. # used to limit CPU usage
  57. CPULIMIT='/usr/bin/cpulimit -l 20 -e'
  58. # command to create a git repository
  59. CREATE_GIT_PROJECT_COMMAND='create-project'
  60. # File which keeps track of what has already been installed
  61. COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
  62. # log file where details of remote backups are stored
  63. REMOTE_BACKUPS_LOG=/var/log/remotebackups.log
  64. # message if something fails to install
  65. CHECK_MESSAGE="Check your internet connection, /etc/network/interfaces and /etc/resolv.conf, then delete $COMPLETION_FILE, run 'rm -fR /var/lib/apt/lists/* && apt-get update --fix-missing' and run this script again. If hash sum mismatches persist then try setting $DEBIAN_REPO to a different mirror and also change /etc/apt/sources.list."
  66. # Default diffie-hellman key length in bits
  67. DH_KEYLENGTH=2048
  68. function detect_usb_drive {
  69. # sets to the highest available drive letter
  70. # which is likely to be the last drive connected
  71. read_config_param USB_DRIVE
  72. partition_number='1'
  73. if [[ "$1" == "nopath" ]]; then
  74. partition_number=''
  75. fi
  76. if [ -b /dev/sdb${partition_number} ]; then
  77. USB_DRIVE=/dev/sdb${partition_number}
  78. fi
  79. if [ -b /dev/sdc${partition_number} ]; then
  80. USB_DRIVE=/dev/sdc${partition_number}
  81. fi
  82. if [ -b /dev/sdd${partition_number} ]; then
  83. USB_DRIVE=/dev/sdd${partition_number}
  84. fi
  85. if [ -b /dev/sde${partition_number} ]; then
  86. USB_DRIVE=/dev/sde${partition_number}
  87. fi
  88. if [ -b /dev/sdf${partition_number} ]; then
  89. USB_DRIVE=/dev/sdf${partition_number}
  90. fi
  91. if [ -b /dev/sdg${partition_number} ]; then
  92. USB_DRIVE=/dev/sdg${partition_number}
  93. fi
  94. if [ -b /dev/sdh${partition_number} ]; then
  95. USB_DRIVE=/dev/sdh${partition_number}
  96. fi
  97. write_config_param USB_DRIVE "$USB_DRIVE"
  98. }
  99. function separate_tmp_filesystem {
  100. tmp_filesystem_size_mb=$1
  101. if [ ! -d /tmp ]; then
  102. mkdir -p /tmp
  103. fi
  104. if ! grep -q '/tmp' /etc/fstab; then
  105. mount -t tmpfs -o size=${tmp_filesystem_size_mb}m tmpfs /tmp
  106. echo "tmpfs /tmp tmpfs nodev,nosuid,noexec,nodiratime,size=${tmp_filesystem_size_mb}M 0 0" >> /etc/fstab
  107. fi
  108. }
  109. function remove_bluetooth {
  110. rmmod -f bnep
  111. rmmod -f bluetooth
  112. if [ -f /etc/default/bluetooth ]; then
  113. if grep "BLUETOOTH_ENABLED=" /etc/default/bluetooth; then
  114. sed -i 's|BLUETOOTH_ENABLED=.*|BLUETOOTH_ENABLED=0|g' /etc/default/bluetooth
  115. else
  116. echo "BLUETOOTH_ENABLED=0" >> /etc/default/bluetooth
  117. fi
  118. fi
  119. if ! grep 'blacklist bnep' /etc/modprobe.d/bluetooth.conf; then
  120. echo 'blacklist bnep' >> /etc/modprobe.d/bluetooth.conf
  121. fi
  122. if ! grep 'blacklist btusb' /etc/modprobe.d/bluetooth.conf; then
  123. echo 'blacklist btusb' >> /etc/modprobe.d/bluetooth.conf
  124. fi
  125. if ! grep 'blacklist bluetooth' /etc/modprobe.d/bluetooth.conf; then
  126. echo 'blacklist bluetooth' >> /etc/modprobe.d/bluetooth.conf
  127. fi
  128. update-initramfs -u -k `uname -r` -v
  129. update-rc.d bluetooth remove
  130. }
  131. function running_as_root {
  132. if [[ $EUID != 0 ]] ; then
  133. echo "0"
  134. else
  135. echo "1"
  136. fi
  137. }
  138. function reset_usb_devices {
  139. for xhci in /sys/bus/pci/drivers/?hci-pci ; do
  140. if ! cd $xhci ; then
  141. return
  142. fi
  143. echo "Resetting devices from $xhci..."
  144. for i in ????:??:??.? ; do
  145. echo -n "$i" > unbind
  146. echo -n "$i" > bind
  147. done
  148. done
  149. udevadm control --reload-rules
  150. }
  151. function install_backports_kernel {
  152. # install backports kernel if possible
  153. architecture_type=$(uname -a)
  154. if [[ "$architecture_type" == *"amd64"* ]]; then
  155. apt-get -yq install linux-image-amd64 -t jessie-backports
  156. fi
  157. }
  158. function turn_off_rsys_logging {
  159. sed -i 's|mail,news.none.*|mail,news.none /dev/null|g' /etc/rsyslog.conf
  160. sed -i 's|auth,authpriv.\*.*|auth,authpriv.\* /dev/null|g' /etc/rsyslog.conf
  161. sed -i 's|mail.info.*|mail.info /dev/null|g' /etc/rsyslog.conf
  162. sed -i 's|mail.warn.*|mail.warn /dev/null|g' /etc/rsyslog.conf
  163. sed -i 's|mail.err.*|mail.err /dev/null|g' /etc/rsyslog.conf
  164. sed -i 's|daemon.\*.*|daemon.\* /dev/null|g' /etc/rsyslog.conf
  165. sed -i 's|mail.\*.*|mail.\* /dev/null|g' /etc/rsyslog.conf
  166. sed -i 's|user.\*.*|user.\* /dev/null|g' /etc/rsyslog.conf
  167. sed -i 's|news.none;mail.none.*|news.none;mail.none /dev/null|g' /etc/rsyslog.conf
  168. sed -i 's|\*.\*;auth,authpriv.none.*|\*.\*;auth,authpriv.none /dev/null|g' /etc/rsyslog.conf
  169. sed -i 's|#cron.\*|cron.\*|g' /etc/rsyslog.conf
  170. sed -i 's|cron.\*.*|cron.\* /dev/null|g' /etc/rsyslog.conf
  171. shred -zu /var/log/wtmp*
  172. shred -zu /var/log/debug*
  173. shred -zu /var/log/cron.*
  174. shred -zu /var/log/auth.*
  175. shred -zu /var/log/mail.*
  176. shred -zu /var/log/daemon.*
  177. shred -zu /var/log/user.*
  178. shred -zu /var/log/messages*
  179. }
  180. function initial_setup {
  181. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  182. return
  183. fi
  184. apt-get -yq remove --purge apache*
  185. apt-get -yq dist-upgrade
  186. apt-get -yq install ca-certificates
  187. apt-get -yq install apt-utils
  188. apt-get -yq install cryptsetup libgfshare-bin obnam sshpass wget avahi-daemon
  189. apt-get -yq install avahi-utils avahi-discover connect-proxy openssh-server
  190. apt-get -yq install sudo git dialog build-essential avahi-daemon avahi-utils
  191. apt-get -yq install avahi-discover avahi-autoipd iptables dnsutils net-tools
  192. apt-get -yq install network-manager iputils-ping libnss-mdns libnss-myhostname
  193. apt-get -yq install libnss-gw-name nano man ntp locales locales-all debconf
  194. apt-get -yq install wireless-tools wpasupplicant usbutils cryptsetup zsh
  195. apt-get -yq install pinentry-curses eatmydata iotop bc hostapd haveged
  196. apt-get -yq install cpulimit screen
  197. if [[ $ARCHITECTURE == 'qemu'* || $ARCHITECTURE == 'amd64' || $ARCHITECTURE == 'x86_64' || $ARCHITECTURE == 'i686' || $ARCHITECTURE == 'i386' ]]; then
  198. apt-get -yq install grub2
  199. fi
  200. if [ ! -d $INSTALL_DIR ]; then
  201. mkdir -p $INSTALL_DIR
  202. fi
  203. mark_completed $FUNCNAME
  204. }
  205. function admin_user_sudo {
  206. if ! grep -q "$MY_USERNAME ALL=(ALL) ALL" $rootdir/etc/sudoers; then
  207. echo "$MY_USERNAME ALL=(ALL) ALL" >> $rootdir/etc/sudoers
  208. fi
  209. }
  210. function search_for_attached_usb_drive {
  211. # If a USB drive is attached then search for email,
  212. # gpg, ssh keys and emacs configuration
  213. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  214. return
  215. fi
  216. detect_usb_drive
  217. if [ -b $USB_DRIVE ]; then
  218. if [ ! -d $USB_MOUNT ]; then
  219. echo $'Mounting USB drive'
  220. mkdir $USB_MOUNT
  221. mount $USB_DRIVE $USB_MOUNT
  222. fi
  223. if [ -d $USB_MOUNT/.gnupg ]; then
  224. echo $'Importing GPG keyring'
  225. cp -r $USB_MOUNT/.gnupg /home/$MY_USERNAME
  226. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.gnupg
  227. GPG_KEYS_IMPORTED="yes"
  228. if [ ! -f /home/$MY_USERNAME/.gnupg/secring.gpg ]; then
  229. echo $'GPG files did not copy'
  230. exit 73529
  231. fi
  232. fi
  233. if [ -f $USB_MOUNT/private_key.gpg ]; then
  234. echo $'GPG private key found on USB drive'
  235. MY_GPG_PRIVATE_KEY=$USB_MOUNT/private_key.gpg
  236. fi
  237. if [ -f $USB_MOUNT/public_key.gpg ]; then
  238. echo $'GPG public key found on USB drive'
  239. MY_GPG_PUBLIC_KEY=$USB_MOUNT/public_key.gpg
  240. fi
  241. if [ -f $USB_MOUNT/letsencrypt ]; then
  242. echo $'Copying letsencrypt keys"'
  243. cp -r $USB_MOUNT/letsencrypt /etc
  244. fi
  245. if [ -d $USB_MOUNT/.ssh ]; then
  246. echo $'Importing ssh keys'
  247. cp -r $USB_MOUNT/.ssh /home/$MY_USERNAME
  248. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
  249. # for security delete the ssh keys from the usb drive
  250. if [ ! -f /home/$MY_USERNAME/.ssh/id_rsa ]; then
  251. echo $'ssh files did not copy'
  252. exit 8
  253. fi
  254. fi
  255. if [ -f $USB_MOUNT/.emacs ]; then
  256. echo $'Importing .emacs file'
  257. cp -f $USB_MOUNT/.emacs /home/$MY_USERNAME/.emacs
  258. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs
  259. fi
  260. if [ -d $USB_MOUNT/.emacs.d ]; then
  261. echo $'Importing .emacs.d directory'
  262. cp -r $USB_MOUNT/.emacs.d /home/$MY_USERNAME
  263. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs.d
  264. fi
  265. if [ -d $USB_MOUNT/ssl ]; then
  266. echo $'Importing SSL certificates'
  267. cp -r $USB_MOUNT/ssl/* /etc/ssl
  268. chmod 640 /etc/ssl/certs/*
  269. chmod 400 /etc/ssl/private/*
  270. # change ownership of some certificates
  271. if [ -d /etc/prosody ]; then
  272. chown prosody:prosody /etc/ssl/private/xmpp.*
  273. chown prosody:prosody /etc/ssl/certs/xmpp.*
  274. fi
  275. if [ -d /etc/dovecot ]; then
  276. chown root:dovecot /etc/ssl/certs/dovecot.*
  277. chown root:dovecot /etc/ssl/private/dovecot.*
  278. fi
  279. if [ -f /etc/ssl/private/exim.key ]; then
  280. cp /etc/ssl/private/exim.key /etc/exim4
  281. cp /etc/ssl/certs/exim.crt /etc/exim4
  282. cp /etc/ssl/certs/exim.dhparam /etc/exim4
  283. chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  284. chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  285. fi
  286. fi
  287. if [ -d $USB_MOUNT/personal ]; then
  288. echo $'Importing personal directory'
  289. cp -r $USB_MOUNT/personal /home/$MY_USERNAME
  290. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/personal
  291. fi
  292. else
  293. if [ -d $USB_MOUNT ]; then
  294. umount $USB_MOUNT
  295. rm -rf $USB_MOUNT
  296. fi
  297. echo $'No USB drive attached'
  298. fi
  299. mark_completed $FUNCNAME
  300. }
  301. function mark_admin_user_account {
  302. set_completion_param "Admin user" "$MY_USERNAME"
  303. }
  304. function remove_instructions_from_motd {
  305. sed -i '/## /d' /etc/motd
  306. }
  307. function remove_default_user {
  308. # make sure you don't use the default user account
  309. if [[ $MY_USERNAME == "debian" ]]; then
  310. echo 'Do not use the default debian user account. Create a different user with: adduser [username]'
  311. exit 68
  312. fi
  313. # remove the default debian user to prevent it from becoming an attack vector
  314. if [ -d /home/debian ]; then
  315. userdel -r debian
  316. echo 'Default debian user account removed'
  317. fi
  318. }
  319. function create_completion_file {
  320. if [ ! -f $COMPLETION_FILE ]; then
  321. touch $COMPLETION_FILE
  322. fi
  323. }
  324. function disable_nfs_insecure_locks {
  325. apt-get -yq install nfs-kernel-server
  326. if grep 'insecure_locks' /etc/exports; then
  327. sed -i 's|,insecure_locks||g' /etc/exports
  328. sed -i 's|insecure_locks,||g' /etc/exports
  329. exportfs -a
  330. fi
  331. }
  332. function set_login_umask {
  333. sed -i 's|UMASK\t.*|UMASK\t\t077|g' /etc/login.defs
  334. }
  335. function disable_deferred_execution {
  336. systemctl stop atd
  337. systemctl disable atd
  338. }
  339. function set_shadow_permissions {
  340. chown root:root /etc/shadow
  341. chmod 0000 /etc/shadow
  342. chown root:root /etc/gshadow
  343. chmod 0000 /etc/gshadow
  344. }
  345. function set_max_login_tries {
  346. max_tries=$1
  347. if ! grep ' deny=' /etc/pam.d/common-auth; then
  348. sed -i "/pam_deny.so/a auth required\t\t\tpam_tally.so onerr=fail no_lock_time per_user deny=$max_tries" /etc/pam.d/common-auth
  349. else
  350. sed -i "s| deny=.*| deny=$max_tries|g" /etc/pam.d/common-auth
  351. fi
  352. if ! grep ' deny=' /etc/pam.d/common-account; then
  353. sed -i '/pam_deny.so/a account required\t\t\tpam_tally.so' /etc/pam.d/common-account
  354. else
  355. sed -i "s| deny=.*| deny=$max_tries|g" /etc/pam.d/common-account
  356. fi
  357. }
  358. function limit_user_logins {
  359. # overall max logins
  360. if ! grep '* hard maxsyslogins' /etc/security/limits.conf; then
  361. echo '* hard maxsyslogins 10' >> /etc/security/limits.conf
  362. else
  363. sed -i 's|hard maxsyslogins.*|hard maxsyslogins 10|g' /etc/security/limits.conf
  364. fi
  365. # Max logins for each user
  366. if ! grep '* hard maxlogins' /etc/security/limits.conf; then
  367. echo '* hard maxlogins 2' >> /etc/security/limits.conf
  368. else
  369. sed -i 's|hard maxlogins.*|hard maxlogins 2|g' /etc/security/limits.conf
  370. fi
  371. }
  372. function remove_serial_logins {
  373. if grep 'ttyS' /etc/securetty; then
  374. cp /etc/securetty /etc/securetty_old
  375. sed -i '/ttyS/d' /etc/securetty
  376. fi
  377. }
  378. function set_sticky_bits {
  379. world_writable=$(find / -xdev -type d -perm -002 \! -perm -1000)
  380. for w in $world_writable; do
  381. echo "Setting sticky bit on $w"
  382. chmod +t $w
  383. done
  384. }
  385. function disable_ctrl_alt_del {
  386. ln -sf /dev/null /etc/systemd/system/ctrl-alt-del.target
  387. }
  388. function lockdown_permissions {
  389. # All commands owned by root
  390. if [ -d /usr/local/share/.cache/yarn ]; then
  391. rm -rf /usr/local/share/.cache/yarn
  392. fi
  393. if [ -f /usr/lib/ssl/certs/ssl-cert-snakeoil.pem ]; then
  394. chown root:root /usr/lib/ssl/certs/ssl-cert-snake*
  395. fi
  396. if [ -d /bin ]; then
  397. chown root:root /bin/*
  398. fi
  399. if [ -d /usr/bin ]; then
  400. chown root:root /usr/bin/*
  401. fi
  402. if [ -d /usr/local/bin ]; then
  403. chown root:root /usr/local/bin/*
  404. fi
  405. if [ -d /sbin ]; then
  406. chown root:root /sbin/*
  407. fi
  408. if [ -d /usr/sbin ]; then
  409. chown root:root /usr/sbin/*
  410. fi
  411. if [ -d /usr/local/sbin ]; then
  412. chown root:root /usr/local/sbin/*
  413. fi
  414. if [ -d /usr/share/${PROJECT_NAME} ]; then
  415. chown -R root:root /usr/share/${PROJECT_NAME}
  416. chmod -R +r /usr/share/${PROJECT_NAME}
  417. fi
  418. # All libraries owned by root
  419. if [ -d /lib ]; then
  420. chown -R root:root /lib/*
  421. fi
  422. if [ -d /lib64 ]; then
  423. chown -R root:root /lib64/*
  424. fi
  425. if [ -d /usr/lib ]; then
  426. chown -R root:root /usr/lib/*
  427. fi
  428. if [ -d /usr/lib64 ]; then
  429. chown -R root:root /usr/lib64/*
  430. fi
  431. # sudo permissions
  432. chmod 4755 /usr/bin/sudo
  433. chmod 4755 /usr/lib/sudo/sudoers.so
  434. chown root:root /etc/sudoers
  435. # permissions on email commands
  436. if [ -f /usr/bin/procmail ]; then
  437. chmod 6755 /usr/bin/procmail
  438. fi
  439. if [ -f /usr/sbin/exim ]; then
  440. chmod u+s /usr/sbin/exim
  441. fi
  442. if [ -f /usr/sbin/exim4 ]; then
  443. chmod u+s /usr/sbin/exim4
  444. fi
  445. set_sticky_bits
  446. # Create some directories to correspond with users in passwords file
  447. if [ ! -d /var/spool/lpd ]; then
  448. mkdir /var/spool/lpd
  449. fi
  450. if [ ! -d /var/spool/news ]; then
  451. mkdir /var/spool/news
  452. fi
  453. if [ ! -d /var/spool/uucp ]; then
  454. mkdir /var/spool/uucp
  455. fi
  456. if [ ! -d /var/list ]; then
  457. mkdir /var/list
  458. fi
  459. if [ ! -d /var/lib/gnats ]; then
  460. mkdir /var/lib/gnats
  461. fi
  462. if [ ! -d /var/lib/saned ]; then
  463. mkdir /var/lib/saned
  464. fi
  465. if [ -d /etc/prosody ]; then
  466. chown -R prosody /etc/prosody
  467. chmod -R 700 /etc/prosody/conf.d
  468. fi
  469. if [ -d /var/lib/prosody ]; then
  470. chown -R prosody /var/lib/prosody
  471. fi
  472. }
  473. function disable_core_dumps {
  474. if ! grep '* hard core 0' /etc/security/limits.conf; then
  475. echo '* hard core 0' >> /etc/security/limits.conf
  476. else
  477. sed -i 's|hard core.*|hard core 0|g' /etc/security/limits.conf
  478. fi
  479. }
  480. function dummy_nologin_command {
  481. if [ ! -f /sbin/nologin ]; then
  482. echo '#!/bin/bash' > /sbin/nologin
  483. chmod +x /sbin/nologin
  484. fi
  485. }
  486. function disable_null_passwords {
  487. sed -i 's| nullok_secure||g' /etc/pam.d/common-auth
  488. }
  489. function setup_firewall {
  490. function_check create_completion_file
  491. create_completion_file
  492. function_check configure_firewall
  493. configure_firewall
  494. function_check configure_firewall_ping
  495. configure_firewall_ping
  496. function_check configure_firewall_for_dns
  497. configure_firewall_for_dns
  498. function_check configure_firewall_for_avahi
  499. configure_firewall_for_avahi
  500. function_check global_rate_limit
  501. global_rate_limit
  502. }
  503. function setup_utils {
  504. read_config_param "PROJECT_REPO"
  505. write_config_param "PROJECT_REPO" "$PROJECT_REPO"
  506. function_check separate_tmp_filesystem
  507. separate_tmp_filesystem 150
  508. function_check disable_null_passwords
  509. disable_null_passwords
  510. function_check disable_ctrl_alt_del
  511. disable_ctrl_alt_del
  512. function_check dummy_nologin_command
  513. dummy_nologin_command
  514. function_check disable_core_dumps
  515. disable_core_dumps
  516. function_check remove_serial_logins
  517. remove_serial_logins
  518. function_check set_max_login_tries
  519. set_max_login_tries 10
  520. function_check set_shadow_permissions
  521. set_shadow_permissions
  522. function_check remove_bluetooth
  523. remove_bluetooth
  524. function_check disable_nfs_insecure_locks
  525. disable_nfs_insecure_locks
  526. function_check set_login_umask
  527. set_login_umask
  528. function_check disable_deferred_execution
  529. disable_deferred_execution
  530. function_check turn_off_rsys_logging
  531. turn_off_rsys_logging
  532. function_check install_backports_kernel
  533. install_backports_kernel
  534. function_check create_completion_file
  535. create_completion_file
  536. function_check read_configuration
  537. read_configuration
  538. function_check check_system_type
  539. check_system_type
  540. function_check set_default_onion_domains
  541. set_default_onion_domains
  542. function_check locale_setup
  543. locale_setup
  544. function_check parse_args
  545. parse_args
  546. function_check check_domains
  547. check_domains
  548. function_check install_static_network
  549. install_static_network
  550. function_check remove_default_user
  551. remove_default_user
  552. function_check setup_firewall
  553. setup_firewall
  554. function_check create_repo_sources
  555. create_repo_sources
  556. function_check configure_dns
  557. configure_dns
  558. function_check initial_setup
  559. initial_setup
  560. function_check install_tor
  561. install_tor
  562. #function_check resolve_dns_via_tor
  563. #resolve_dns_via_tor
  564. function_check install_command_line_browser
  565. install_command_line_browser
  566. function_check enable_ssh_via_onion
  567. enable_ssh_via_onion
  568. function_check check_date
  569. check_date
  570. function_check install_dynamicdns
  571. install_dynamicdns
  572. function_check randomize_cron
  573. randomize_cron
  574. function_check create_freedns_updater
  575. create_freedns_updater
  576. function_check mark_admin_user_account
  577. mark_admin_user_account
  578. function_check enforce_good_passwords
  579. enforce_good_passwords
  580. function_check change_login_message
  581. change_login_message
  582. function_check enable_zram
  583. enable_zram
  584. function_check random_number_generator
  585. random_number_generator
  586. function_check set_your_domain_name
  587. set_your_domain_name
  588. function_check configure_internet_protocol
  589. configure_internet_protocol
  590. function_check create_git_project
  591. create_git_project
  592. function_check setup_wifi
  593. setup_wifi
  594. function_check configure_ssh
  595. configure_ssh
  596. function_check configure_ssh_onion
  597. configure_ssh_onion
  598. function_check allow_ssh_to_onion_address
  599. allow_ssh_to_onion_address
  600. function_check remove_instructions_from_motd
  601. remove_instructions_from_motd
  602. function_check check_hwrng
  603. check_hwrng
  604. function_check search_for_attached_usb_drive
  605. search_for_attached_usb_drive
  606. function_check regenerate_ssh_keys
  607. regenerate_ssh_keys
  608. function_check create_mirrors
  609. create_mirrors
  610. function_check create_upgrade_script
  611. create_upgrade_script
  612. function_check letsencrypt_renewals
  613. letsencrypt_renewals
  614. function_check install_watchdog_script
  615. install_watchdog_script
  616. function_check install_avahi
  617. install_avahi
  618. function_check create_avahi_onion_domains
  619. create_avahi_onion_domains
  620. #function_check install_atheros_wifi
  621. #install_atheros_wifi
  622. function_check route_outgoing_traffic_through_tor
  623. route_outgoing_traffic_through_tor
  624. function_check upgrade_golang
  625. upgrade_golang
  626. function_check install_tomb
  627. install_tomb
  628. function_check admin_user_sudo
  629. admin_user_sudo
  630. function_check limit_user_logins
  631. limit_user_logins
  632. function_check schedule_stig_tests
  633. schedule_stig_tests
  634. }
  635. function setup_email {
  636. function_check create_completion_file
  637. create_completion_file
  638. function_check install_email
  639. install_email
  640. function_check create_procmail
  641. create_procmail
  642. function_check handle_admin_emails
  643. handle_admin_emails
  644. function_check spam_filtering
  645. spam_filtering
  646. function_check configure_imap
  647. configure_imap
  648. #function_check configure_imap_client_certs
  649. #configure_imap_client_certs
  650. function_check configure_gpg
  651. configure_gpg
  652. function_check refresh_gpg_keys
  653. refresh_gpg_keys
  654. function_check configure_backup_key
  655. configure_backup_key
  656. function_check install_monkeysphere
  657. install_monkeysphere
  658. function_check encrypt_incoming_email
  659. encrypt_incoming_email
  660. function_check encrypt_outgoing_email
  661. encrypt_outgoing_email
  662. function_check email_client
  663. email_client
  664. function_check email_archiving
  665. email_archiving
  666. function_check email_from_address
  667. email_from_address
  668. function_check create_public_mailing_list
  669. #create_public_mailing_list
  670. #function check create_private_mailing_list
  671. #create_private_mailing_list
  672. function_check encrypt_all_email
  673. encrypt_all_email
  674. function_check import_email
  675. import_email
  676. }
  677. function setup_web {
  678. function_check create_completion_file
  679. create_completion_file
  680. function_check install_web_server
  681. install_web_server
  682. function_check install_web_server_access_control
  683. install_web_server_access_control
  684. }
  685. function upgrade_apps {
  686. function_check create_completion_file
  687. create_completion_file
  688. APPS_COMPLETED=()
  689. FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
  690. # for all the app scripts
  691. for filename in $FILES
  692. do
  693. app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
  694. item_in_array "${app_name}" "${APPS_COMPLETED[@]}"
  695. if [[ $? != 0 ]]; then
  696. function_check app_is_installed
  697. if [[ "$(app_is_installed $a)" == "1" ]]; then
  698. echo ''
  699. echo ''
  700. echo $"Upgrading $a"
  701. app_load_variables ${app_name}
  702. APPS_COMPLETED+=("${app_name}")
  703. function_check upgrade_${app_name}
  704. upgrade_${app_name}
  705. fi
  706. fi
  707. done
  708. }
  709. function setup_apps {
  710. is_interactive=$1
  711. function_check create_completion_file
  712. create_completion_file
  713. function_check detect_installable_apps
  714. detect_installable_apps
  715. function_check choose_apps_for_variant
  716. choose_apps_for_variant "$SYSTEM_TYPE"
  717. echo $"System variant: $SYSTEM_TYPE"
  718. echo $'The following apps have been selected'
  719. echo ''
  720. function_check list_chosen_apps
  721. list_chosen_apps
  722. echo ''
  723. function_check upgrade_apps
  724. upgrade_apps
  725. if [[ $is_interactive == "noninteractive" || $is_interactive == "headless" ]]; then
  726. function_check install_apps
  727. install_apps
  728. if [ ! $APP_INSTALLED_SUCCESS ]; then
  729. echo $'One or more apps failed to install'
  730. fi
  731. fi
  732. }
  733. function combine_all_scripts {
  734. combined_filename=$1
  735. # initial variables
  736. cp $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars $combined_filename
  737. # utilities
  738. UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
  739. for f in $UTILS_FILES
  740. do
  741. # this removes the first line, which is #!/bin/bash
  742. tail -n +2 "$f" >> $combined_filename
  743. done
  744. # base system
  745. BASE_SYSTEM_FILES=/usr/share/${PROJECT_NAME}/base/${PROJECT_NAME}-base-*
  746. for f in $BASE_SYSTEM_FILES
  747. do
  748. tail -n +2 "$f" >> $combined_filename
  749. done
  750. # apps
  751. APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
  752. for f in $APP_FILES
  753. do
  754. tail -n +2 "$f" >> $combined_filename
  755. done
  756. }
  757. # NOTE: deliberately no exit 0