freedombone-utils-setup 37KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # Setup functions
  10. #
  11. # License
  12. # =======
  13. #
  14. # Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU Affero General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU Affero General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU Affero General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. if [ ! "$PROJECT_NAME" ]; then
  29. PROJECT_NAME='freedombone'
  30. fi
  31. if [ ! "$LOCAL_NAME" ]; then
  32. LOCAL_NAME=${PROJECT_NAME}
  33. fi
  34. DEFAULT_DOMAIN_NAME=
  35. DEFAULT_DOMAIN_CODE=
  36. MY_USERNAME=
  37. if [ ! "$SYSTEM_TYPE" ]; then
  38. SYSTEM_TYPE="full"
  39. fi
  40. # An optional configuration file which overrides some of these variables
  41. if [ ! "$CONFIGURATION_FILE" ]; then
  42. CONFIGURATION_FILE="$HOME/${PROJECT_NAME}.cfg"
  43. fi
  44. # Directory where source code is downloaded and compiled
  45. INSTALL_DIR=$HOME/build
  46. # device name for an attached usb drive
  47. USB_DRIVE=/dev/sda1
  48. # Location where the USB drive is mounted to
  49. USB_MOUNT=/mnt/usb
  50. # Number of days to keep backups for
  51. BACKUP_MAX_DAYS=30
  52. # file containing a list of remote locations to backup to
  53. # Format: [username@friendsdomain//home/username] [ssh_password]
  54. # With the only space character being between the server and the password
  55. FRIENDS_SERVERS_LIST="/home/$MY_USERNAME/backup.list"
  56. export DEBIAN_FRONTEND=noninteractive
  57. # used to limit CPU usage
  58. CPULIMIT='/usr/bin/cpulimit -l 20 -e'
  59. # command to create a git repository
  60. CREATE_GIT_PROJECT_COMMAND='create-project'
  61. # File which keeps track of what has already been installed
  62. COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
  63. # log file where details of remote backups are stored
  64. REMOTE_BACKUPS_LOG=/var/log/remotebackups.log
  65. # message if something fails to install
  66. CHECK_MESSAGE="Check your internet connection, /etc/network/interfaces and /etc/resolvconf/resolv.conf.d/head, 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."
  67. # Default diffie-hellman key length in bits
  68. DH_KEYLENGTH=2048
  69. function support_256_colours {
  70. if ! grep 'xterm-256color' /etc/skel/.profile; then
  71. echo '' >> /etc/skel/.profile
  72. echo 'export TERM=xterm-256color' >> /etc/skel/.profile
  73. fi
  74. if ! grep 'xterm-256color' /home/$MY_USERNAME/.profile; then
  75. echo '' >> /home/$MY_USERNAME/.profile
  76. echo 'export TERM=xterm-256color' >> /home/$MY_USERNAME/.profile
  77. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.profile
  78. fi
  79. }
  80. function detect_usb_drive {
  81. # sets to the highest available drive letter
  82. # which is likely to be the last drive connected
  83. read_config_param USB_DRIVE
  84. partition_number='1'
  85. #if [[ "$1" == "nopath" ]]; then
  86. # partition_number=''
  87. #fi
  88. if [ -b /dev/sda${partition_number} ]; then
  89. USB_DRIVE=/dev/sda${partition_number}
  90. fi
  91. if [ -b /dev/sdb${partition_number} ]; then
  92. USB_DRIVE=/dev/sdb${partition_number}
  93. fi
  94. if [ -b /dev/sdc${partition_number} ]; then
  95. USB_DRIVE=/dev/sdc${partition_number}
  96. fi
  97. if [ -b /dev/sdd${partition_number} ]; then
  98. USB_DRIVE=/dev/sdd${partition_number}
  99. fi
  100. if [ -b /dev/sde${partition_number} ]; then
  101. USB_DRIVE=/dev/sde${partition_number}
  102. fi
  103. if [ -b /dev/sdf${partition_number} ]; then
  104. USB_DRIVE=/dev/sdf${partition_number}
  105. fi
  106. if [ -b /dev/sdg${partition_number} ]; then
  107. USB_DRIVE=/dev/sdg${partition_number}
  108. fi
  109. if [ -b /dev/sdh${partition_number} ]; then
  110. USB_DRIVE=/dev/sdh${partition_number}
  111. fi
  112. write_config_param USB_DRIVE "$USB_DRIVE"
  113. }
  114. function separate_tmp_filesystem {
  115. tmp_filesystem_size_mb=$1
  116. if [ ! -d /tmp ]; then
  117. mkdir -p /tmp
  118. fi
  119. if ! grep -q '/tmp' /etc/fstab; then
  120. mount -t tmpfs -o size="${tmp_filesystem_size_mb}m" tmpfs /tmp
  121. echo "tmpfs /tmp tmpfs nodev,nosuid,noexec,nodiratime,size=${tmp_filesystem_size_mb}M 0 0" >> /etc/fstab
  122. fi
  123. }
  124. function proc_filesystem_settings {
  125. if ! grep -q "proc proc defaults,nodev,nosuid " /etc/fstab; then
  126. sed -i 's|proc /proc proc defaults |proc /proc proc defaults,nodev,nosuid |g' /etc/fstab
  127. fi
  128. }
  129. function remove_bluetooth {
  130. bluetooth_changed=
  131. bnep_exists=$(lsmod | grep bnep)
  132. if [[ "$bnep_exists" == "bnep"* ]]; then
  133. rmmod -f bnep
  134. bluetooth_changed=1
  135. fi
  136. bluetooth_exists=$(lsmod | grep bluetooth)
  137. if [[ "$bluetooth_exists" == "bluetooth"* ]]; then
  138. rmmod -f bluetooth
  139. bluetooth_changed=1
  140. fi
  141. if [ -f /etc/default/bluetooth ]; then
  142. if grep -q "BLUETOOTH_ENABLED=" /etc/default/bluetooth; then
  143. sed -i 's|BLUETOOTH_ENABLED=.*|BLUETOOTH_ENABLED=0|g' /etc/default/bluetooth
  144. else
  145. echo "BLUETOOTH_ENABLED=0" >> /etc/default/bluetooth
  146. fi
  147. bluetooth_changed=1
  148. fi
  149. if ! grep -q 'blacklist bnep' /etc/modprobe.d/bluetooth.conf; then
  150. echo 'blacklist bnep' >> /etc/modprobe.d/bluetooth.conf
  151. bluetooth_changed=1
  152. fi
  153. if ! grep -q 'blacklist btusb' /etc/modprobe.d/bluetooth.conf; then
  154. echo 'blacklist btusb' >> /etc/modprobe.d/bluetooth.conf
  155. bluetooth_changed=1
  156. fi
  157. if ! grep -q 'blacklist bluetooth' /etc/modprobe.d/bluetooth.conf; then
  158. echo 'blacklist bluetooth' >> /etc/modprobe.d/bluetooth.conf
  159. bluetooth_changed=1
  160. fi
  161. if [ $bluetooth_changed ]; then
  162. update-initramfs -u -k "$(uname -r)" -v
  163. update-rc.d bluetooth remove
  164. fi
  165. }
  166. function running_as_root {
  167. if [[ $EUID != 0 ]] ; then
  168. echo "0"
  169. else
  170. echo "1"
  171. fi
  172. }
  173. function reset_usb_devices {
  174. for xhci in /sys/bus/pci/drivers/?hci-pci ; do
  175. if ! cd "$xhci" ; then
  176. return
  177. fi
  178. echo "Resetting devices from $xhci..."
  179. for i in ????:??:??.? ; do
  180. echo -n "$i" > unbind
  181. echo -n "$i" > bind
  182. done
  183. done
  184. udevadm control --reload-rules
  185. }
  186. function install_backports_kernel {
  187. # install backports kernel if possible
  188. architecture_type=$(uname -a)
  189. if [[ "$architecture_type" == *"amd64"* ]]; then
  190. package_installed=$(dpkg-query -W -f='${Package}\n' linux-image-amd64 2>/dev/null)
  191. if [ ! "$package_installed" ]; then
  192. apt-get -yq install linux-image-amd64
  193. fi
  194. fi
  195. }
  196. function save_rsys_header {
  197. { echo "";
  198. echo "#################";
  199. echo "#### MODULES ####";
  200. echo "#################";
  201. echo '';
  202. echo 'module(load="imuxsock")';
  203. echo 'module(load="imklog")';
  204. echo '';
  205. echo '###########################';
  206. echo '#### GLOBAL DIRECTIVES ####';
  207. echo '###########################';
  208. echo '';
  209. echo "\$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat";
  210. echo '';
  211. echo "\$FileOwner root";
  212. echo "\$FileGroup adm";
  213. echo "\$FileCreateMode 0640";
  214. echo "\$DirCreateMode 0755";
  215. echo "\$Umask 0022";
  216. echo '';
  217. echo "\$WorkDirectory /var/spool/rsyslog";
  218. echo '';
  219. echo "\$IncludeConfig /etc/rsyslog.d/*.conf";
  220. echo '';
  221. echo '###############';
  222. echo '#### RULES ####';
  223. echo '###############';
  224. echo ''; } > /etc/rsyslog.conf
  225. }
  226. function turn_off_rsys_logging {
  227. save_rsys_header
  228. echo '*.* ~' >> /etc/rsyslog.conf
  229. rm -rf /var/log/wtmp*
  230. rm -rf /var/log/debug*
  231. rm -rf /var/log/cron.*
  232. rm -rf /var/log/auth.*
  233. rm -rf /var/log/mail.*
  234. rm -rf /var/log/daemon.*
  235. rm -rf /var/log/user.*
  236. rm -rf /var/log/messages*
  237. rm -rf /var/log/syslog*
  238. rm -rf /var/log/alternatives*
  239. rm -rf /var/log/faillog
  240. rm -rf /var/log/kern.log*
  241. }
  242. function initial_setup {
  243. if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
  244. return
  245. fi
  246. apt-get -yq remove --purge apache2-bin*
  247. apt-get -yq dist-upgrade
  248. apt-get -yq install ca-certificates
  249. apt-get -yq install apt-utils
  250. apt-get -yq install cryptsetup libgfshare-bin duplicity sshpass wget avahi-daemon
  251. apt-get -yq install avahi-utils avahi-discover connect-proxy openssh-server
  252. apt-get -yq install sudo git dialog build-essential avahi-daemon avahi-utils
  253. apt-get -yq install avahi-discover iptables dnsutils net-tools
  254. apt-get -yq install network-manager iputils-ping libnss-mdns libnss-myhostname
  255. apt-get -yq install libnss-gw-name nano man ntp locales locales-all debconf
  256. apt-get -yq install wireless-tools wpasupplicant usbutils zsh cpulimit screen
  257. apt-get -yq install pinentry-curses eatmydata iotop bc hostapd
  258. # With some VMs, the hardware cycles counter is emulated and deterministic,
  259. # and thus predictible, so havege should not be used
  260. if [[ $ARCHITECTURE != 'qemu'* ]]; then
  261. apt-get -yq install haveged
  262. fi
  263. if [[ $ARCHITECTURE == 'qemu'* || $ARCHITECTURE == 'amd64' || $ARCHITECTURE == 'x86_64' || $ARCHITECTURE == 'i686' || $ARCHITECTURE == 'i386' ]]; then
  264. apt-get -yq install grub2 lvm2
  265. fi
  266. if [ ! -d "$INSTALL_DIR" ]; then
  267. mkdir -p "$INSTALL_DIR"
  268. fi
  269. mark_completed "${FUNCNAME[0]}"
  270. }
  271. function turn_off_magic_sysrq {
  272. if grep -q 'kernel.sysrq = 0' /etc/sysctl.conf; then
  273. return
  274. fi
  275. if grep -q 'kernel.sysrq' /etc/sysctl.conf; then
  276. sed -i 's|#kernel.sysrq.*|kernel.sysrq = 0|g' /etc/sysctl.conf
  277. sed -i 's|kernel.sysrq.*|kernel.sysrq = 0|g' /etc/sysctl.conf
  278. else
  279. echo 'kernel.sysrq = 0' >> /etc/sysctl.conf
  280. fi
  281. }
  282. function setup_grub {
  283. if [[ $ARCHITECTURE == 'qemu'* || $ARCHITECTURE == 'amd64' || $ARCHITECTURE == 'x86_64' || $ARCHITECTURE == 'i686' || $ARCHITECTURE == 'i386' ]]; then
  284. if ! grep -q 'ifnames=0' /etc/default/grub; then
  285. sed -i 's|GRUB_CMDLINE_LINUX_DEFAULT=.*|GRUB_CMDLINE_LINUX_DEFAULT="quiet ifnames=0 slub_debug=FZP slab_nomerge page_poison=1 panic=0"|g' /etc/default/grub
  286. update-grub
  287. fi
  288. fi
  289. }
  290. function admin_user_sudo {
  291. # shellcheck disable=SC2154
  292. if ! grep -q "$MY_USERNAME ALL=(ALL) ALL" "$rootdir/etc/sudoers"; then
  293. echo "$MY_USERNAME ALL=(ALL) ALL" >> "$rootdir/etc/sudoers"
  294. fi
  295. }
  296. function search_for_attached_usb_drive {
  297. # If a USB drive is attached then search for email,
  298. # gpg, ssh keys and emacs configuration
  299. if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
  300. return
  301. fi
  302. detect_usb_drive
  303. if [ -b $USB_DRIVE ]; then
  304. if [ ! -d $USB_MOUNT ]; then
  305. echo $'Mounting USB drive'
  306. mkdir $USB_MOUNT
  307. mount $USB_DRIVE $USB_MOUNT
  308. fi
  309. if [ -d $USB_MOUNT/.gnupg ]; then
  310. echo $'Importing GPG keyring'
  311. cp -r $USB_MOUNT/.gnupg /home/$MY_USERNAME
  312. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.gnupg
  313. if [ ! -f /home/$MY_USERNAME/.gnupg/secring.gpg ]; then
  314. echo $'GPG files did not copy'
  315. exit 73529
  316. fi
  317. fi
  318. if [ -f $USB_MOUNT/private_key.gpg ]; then
  319. echo $'GPG private key found on USB drive'
  320. MY_GPG_PRIVATE_KEY="$USB_MOUNT/private_key.gpg"
  321. fi
  322. if [ -f $USB_MOUNT/public_key.gpg ]; then
  323. echo $'GPG public key found on USB drive'
  324. MY_GPG_PUBLIC_KEY="$USB_MOUNT/public_key.gpg"
  325. fi
  326. if [ -f $USB_MOUNT/letsencrypt ]; then
  327. echo $'Copying letsencrypt keys"'
  328. cp -r $USB_MOUNT/letsencrypt /etc
  329. fi
  330. if [ -d $USB_MOUNT/.ssh ]; then
  331. echo $'Importing ssh keys'
  332. cp -r $USB_MOUNT/.ssh /home/$MY_USERNAME
  333. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
  334. # for security delete the ssh keys from the usb drive
  335. if [ ! -f /home/$MY_USERNAME/.ssh/id_rsa ]; then
  336. echo $'ssh files did not copy'
  337. exit 8
  338. fi
  339. fi
  340. if [ -f $USB_MOUNT/.emacs ]; then
  341. echo $'Importing .emacs file'
  342. cp -f $USB_MOUNT/.emacs /home/$MY_USERNAME/.emacs
  343. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs
  344. fi
  345. if [ -d $USB_MOUNT/.emacs.d ]; then
  346. echo $'Importing .emacs.d directory'
  347. cp -r $USB_MOUNT/.emacs.d /home/$MY_USERNAME
  348. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs.d
  349. fi
  350. if [ -d $USB_MOUNT/ssl ]; then
  351. echo $'Importing SSL certificates'
  352. cp -r $USB_MOUNT/ssl/* /etc/ssl
  353. chmod 640 /etc/ssl/certs/*
  354. chmod 400 /etc/ssl/private/*
  355. # change ownership of some certificates
  356. if [ -d /etc/prosody ]; then
  357. chown prosody:prosody /etc/ssl/private/xmpp.*
  358. chown prosody:prosody /etc/ssl/certs/xmpp.*
  359. fi
  360. if [ -d /etc/dovecot ]; then
  361. chown root:dovecot /etc/ssl/certs/dovecot.*
  362. chown root:dovecot /etc/ssl/private/dovecot.*
  363. fi
  364. if [ -f /etc/ssl/private/exim.key ]; then
  365. cp /etc/ssl/private/exim.key /etc/exim4
  366. cp /etc/ssl/certs/exim.crt /etc/exim4
  367. cp /etc/ssl/certs/exim.dhparam /etc/exim4
  368. chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  369. chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  370. fi
  371. fi
  372. if [ -d $USB_MOUNT/personal ]; then
  373. echo $'Importing personal directory'
  374. cp -r $USB_MOUNT/personal /home/$MY_USERNAME
  375. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/personal
  376. fi
  377. else
  378. if [ -d $USB_MOUNT ]; then
  379. umount $USB_MOUNT
  380. rm -rf $USB_MOUNT
  381. fi
  382. echo $'No USB drive attached'
  383. fi
  384. mark_completed "${FUNCNAME[0]}"
  385. }
  386. function mark_admin_user_account {
  387. set_completion_param "Admin user" "$MY_USERNAME"
  388. }
  389. function remove_instructions_from_motd {
  390. if grep -q "## " /etc/motd; then
  391. sed -i '/## /d' /etc/motd
  392. fi
  393. }
  394. function remove_default_user {
  395. # make sure you don't use the default user account
  396. if [[ $MY_USERNAME == "debian" ]]; then
  397. echo 'Do not use the default debian user account. Create a different user with: adduser [username]'
  398. exit 68
  399. fi
  400. # remove the default debian user to prevent it from becoming an attack vector
  401. if [ -d /home/debian ]; then
  402. userdel -r debian
  403. echo 'Default debian user account removed'
  404. fi
  405. }
  406. function create_completion_file {
  407. if [ ! -f "$COMPLETION_FILE" ]; then
  408. touch "$COMPLETION_FILE"
  409. fi
  410. }
  411. function remove_management_engine_interface {
  412. # see https://www.kernel.org/doc/Documentation/misc-devices/mei/mei.txt
  413. # Disabling this interface doesn't cure the problems of ME, but it
  414. # might stop an adversary in control of AMT from using the command
  415. # interface to control the operating system.
  416. if [ -f /dev/mei0 ]; then
  417. rmmod mei_me
  418. rmmod mei0
  419. fi
  420. blacklist_changed=
  421. if [ ! -f /etc/modprobe.d/blacklist.conf ]; then
  422. touch /etc/modprobe.d/blacklist.conf
  423. blacklist_changed=1
  424. fi
  425. if ! grep -q "blacklist mei" /etc/modprobe.d/blacklist.conf; then
  426. echo "blacklist mei" >> /etc/modprobe.d/blacklist.conf
  427. blacklist_changed=1
  428. fi
  429. if ! grep -q "blacklist mei_me" /etc/modprobe.d/blacklist.conf; then
  430. echo "blacklist mei_me" >> /etc/modprobe.d/blacklist.conf
  431. blacklist_changed=1
  432. fi
  433. if [ $blacklist_changed ]; then
  434. depmod -ae -E
  435. update-initramfs -u
  436. fi
  437. }
  438. function set_login_umask {
  439. logindefs_umask=$(grep UMASK /etc/login.defs | grep -v '#')
  440. if [[ "$logindefs_umask" != *'077' ]]; then
  441. sed -i 's|UMASK\t.*|UMASK\t\t077|g' /etc/login.defs
  442. fi
  443. }
  444. function disable_deferred_execution {
  445. systemctl stop atd
  446. systemctl disable atd
  447. }
  448. function set_shadow_permissions {
  449. chown root:root /etc/shadow
  450. chmod 0000 /etc/shadow
  451. chown root:root /etc/gshadow
  452. chmod 0000 /etc/gshadow
  453. }
  454. function set_max_login_tries {
  455. max_tries=$1
  456. if ! grep -q ' deny=' /etc/pam.d/common-auth; then
  457. 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
  458. else
  459. if ! grep -q " deny=$max_tries" /etc/pam.d/common-auth; then
  460. sed -i "s| deny=.*| deny=$max_tries|g" /etc/pam.d/common-auth
  461. fi
  462. fi
  463. if ! grep -q 'pam_tally.so' /etc/pam.d/common-account; then
  464. sed -i '/pam_deny.so/a account required\t\t\tpam_tally.so' /etc/pam.d/common-account
  465. fi
  466. }
  467. function limit_user_logins {
  468. # overall max logins
  469. if ! grep -q '\* hard maxsyslogins' /etc/security/limits.conf; then
  470. echo '* hard maxsyslogins 10' >> /etc/security/limits.conf
  471. else
  472. if ! grep -q '\* hard maxsyslogins 10' /etc/security/limits.conf; then
  473. sed -i 's|hard maxsyslogins.*|hard maxsyslogins 10|g' /etc/security/limits.conf
  474. fi
  475. fi
  476. # Max logins for each user
  477. if ! grep -q '\* hard maxlogins' /etc/security/limits.conf; then
  478. echo '* hard maxlogins 2' >> /etc/security/limits.conf
  479. else
  480. if ! grep -q '\* hard maxlogins 2' /etc/security/limits.conf; then
  481. sed -i 's|hard maxlogins.*|hard maxlogins 2|g' /etc/security/limits.conf
  482. fi
  483. fi
  484. }
  485. function remove_serial_logins {
  486. if grep -q 'ttyS' /etc/securetty; then
  487. cp /etc/securetty /etc/securetty_old
  488. sed -i '/ttyS/d' /etc/securetty
  489. fi
  490. }
  491. function set_sticky_bits {
  492. world_writable=$(find / -xdev -type d -perm -002 \! -perm -1000)
  493. for w in $world_writable; do
  494. echo "Setting sticky bit on $w"
  495. chmod +t "$w"
  496. done
  497. }
  498. function disable_ctrl_alt_del {
  499. ctrl_alt_del=$(ls -l /etc/systemd/system/ctrl-alt-del.target)
  500. if [[ "$ctrl_alt_del" != *'/dev/null' ]]; then
  501. ln -sf /dev/null /etc/systemd/system/ctrl-alt-del.target
  502. fi
  503. }
  504. function lockdown_permissions {
  505. if [ -d /root/.npm ]; then
  506. chmod -R 700 /root/.npm
  507. fi
  508. # All commands owned by root
  509. if [ -d /root/.cache/yarn ]; then
  510. rm -rf /root/.cache/yarn
  511. fi
  512. if [ -d /usr/local/share/.cache/yarn ]; then
  513. rm -rf /usr/local/share/.cache/yarn
  514. fi
  515. if [ -f /usr/lib/ssl/certs/ssl-cert-snakeoil.pem ]; then
  516. chown root:root /usr/lib/ssl/certs/ssl-cert-snake*
  517. fi
  518. if [ -d /bin ]; then
  519. chown root:root /bin/*
  520. fi
  521. if [ -d /usr/bin ]; then
  522. chown root:root /usr/bin/*
  523. fi
  524. if [ -d /usr/local/bin ]; then
  525. chown root:root /usr/local/bin/*
  526. fi
  527. if [ -d /sbin ]; then
  528. chown root:root /sbin/*
  529. fi
  530. if [ -d /usr/sbin ]; then
  531. chown root:root /usr/sbin/*
  532. fi
  533. if [ -d /usr/local/sbin ]; then
  534. chown root:root /usr/local/sbin/*
  535. fi
  536. if [ -d /usr/share/${PROJECT_NAME} ]; then
  537. chown -R root:root /usr/share/${PROJECT_NAME}
  538. chmod -R +r /usr/share/${PROJECT_NAME}
  539. fi
  540. # All libraries owned by root
  541. if [ -d /lib ]; then
  542. chown -R root:root /lib/*
  543. fi
  544. if [ -d /lib64 ]; then
  545. chown -R root:root /lib64/*
  546. fi
  547. if [ -d /usr/lib ]; then
  548. chown -R root:root /usr/lib/*
  549. if [ -d /usr/lib/node_modules ]; then
  550. chmod -R 750 /usr/lib/node_modules/*
  551. fi
  552. if [ -d /usr/lib/prosody ]; then
  553. chown -R prosody:prosody /usr/lib/prosody
  554. fi
  555. fi
  556. if [ -d /usr/lib64 ]; then
  557. chown -R root:root /usr/lib64/*
  558. fi
  559. # sudo permissions
  560. chmod 4755 /usr/bin/sudo
  561. chmod 4755 /usr/lib/sudo/sudoers.so
  562. chown root:root /etc/sudoers
  563. # permissions on email commands
  564. if [ -f /usr/bin/procmail ]; then
  565. chmod 6755 /usr/bin/procmail
  566. fi
  567. if [ -f /usr/sbin/exim ]; then
  568. chmod u+s /usr/sbin/exim
  569. fi
  570. if [ -f /usr/sbin/exim4 ]; then
  571. chmod u+s /usr/sbin/exim4
  572. fi
  573. set_sticky_bits
  574. # Create some directories to correspond with users in passwords file
  575. if [ ! -d /var/spool/lpd ]; then
  576. mkdir /var/spool/lpd
  577. fi
  578. if [ ! -d /var/spool/news ]; then
  579. mkdir /var/spool/news
  580. fi
  581. if [ ! -d /var/spool/uucp ]; then
  582. mkdir /var/spool/uucp
  583. fi
  584. if [ ! -d /var/list ]; then
  585. mkdir /var/list
  586. fi
  587. if [ ! -d /var/lib/gnats ]; then
  588. mkdir /var/lib/gnats
  589. fi
  590. if [ ! -d /var/lib/saned ]; then
  591. mkdir /var/lib/saned
  592. fi
  593. if [ -d /etc/prosody ]; then
  594. chown -R prosody /etc/prosody
  595. chmod -R 700 /etc/prosody/conf.d
  596. fi
  597. if [ -d /var/lib/prosody ]; then
  598. chown -R prosody /var/lib/prosody
  599. fi
  600. if [ -d /etc/letsencrypt ]; then
  601. chmod -R 600 /etc/letsencrypt
  602. chmod -R g=rX /etc/letsencrypt
  603. chown -R root:ssl-cert /etc/letsencrypt
  604. fi
  605. chown -f root:root /etc/motd /etc/issue*
  606. chmod -f 0444 /etc/motd /etc/issue*
  607. }
  608. function disable_core_dumps {
  609. if ! grep -q '\* hard core' /etc/security/limits.conf; then
  610. echo '* hard core 0' >> /etc/security/limits.conf
  611. else
  612. if ! grep -q '\* hard core 0' /etc/security/limits.conf; then
  613. sed -i 's|hard core.*|hard core 0|g' /etc/security/limits.conf
  614. fi
  615. fi
  616. }
  617. function dummy_nologin_command {
  618. if [ ! -f /sbin/nologin ]; then
  619. echo '#!/bin/bash' > /sbin/nologin
  620. chmod +x /sbin/nologin
  621. fi
  622. }
  623. function disable_null_passwords {
  624. if grep -q ' nullok_secure' /etc/pam.d/common-auth; then
  625. sed -i 's| nullok_secure||g' /etc/pam.d/common-auth
  626. fi
  627. }
  628. function create_usb_canary {
  629. if [[ $SYSTEM_TYPE == "mesh"* ]]; then
  630. return
  631. fi
  632. if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
  633. return
  634. fi
  635. echo "ACTION==\"add\", KERNEL==\"sd*[!0-9]\", RUN+=\"/usr/local/bin/${PROJECT_NAME}-usb-canary\"" > /etc/udev/rules.d/00-usb-canary.rules
  636. udevadm control --reload-rules
  637. mark_completed "${FUNCNAME[0]}"
  638. }
  639. function setup_firewall {
  640. function_check create_completion_file
  641. create_completion_file
  642. function_check configure_firewall
  643. configure_firewall
  644. function_check block_firefox_telemetry
  645. block_firefox_telemetry
  646. function_check configure_firewall_ping
  647. configure_firewall_ping
  648. function_check firewall_handle_port_scans
  649. firewall_handle_port_scans
  650. function_check firewall_drop_telnet
  651. firewall_drop_telnet
  652. function_check firewall_drop_spoofed_packets
  653. firewall_drop_spoofed_packets
  654. function_check firewall_rate_limits
  655. firewall_rate_limits
  656. function_check configure_firewall_for_dns
  657. configure_firewall_for_dns
  658. function_check configure_firewall_for_avahi
  659. configure_firewall_for_avahi
  660. function_check global_rate_limit
  661. global_rate_limit
  662. function_check firewall_block_bad_ip_ranges
  663. firewall_block_bad_ip_ranges
  664. }
  665. function setup_powerline {
  666. if [ -f ~/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline ]; then
  667. if [ ! -f ~/.powerline.bash ]; then
  668. cp ~/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline ~/.powerline.bash
  669. else
  670. HASH1=$(sha256sum ~/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline | awk -F ' ' '{print $1}')
  671. HASH2=$(sha256sum ~/.powerline.bash | awk -F ' ' '{print $1}')
  672. if [[ "$HASH1" != "$HASH2" ]]; then
  673. cp ~/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline ~/.powerline.bash
  674. fi
  675. fi
  676. if [ ! -f /etc/skel/.powerline.bash ]; then
  677. cp ~/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline /etc/skel/.powerline.bash
  678. else
  679. HASH1=$(sha256sum ~/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline | awk -F ' ' '{print $1}')
  680. HASH2=$(sha256sum /etc/skel/.powerline.bash | awk -F ' ' '{print $1}')
  681. if [[ "$HASH1" != "$HASH2" ]]; then
  682. cp ~/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline /etc/skel/.powerline.bash
  683. fi
  684. fi
  685. else
  686. if [ -f /home/${MY_USERNAME}/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline ]; then
  687. if [ ! -f ~/.powerline.bash ]; then
  688. cp /home/${MY_USERNAME}/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline ~/.powerline.bash
  689. else
  690. HASH1=$(sha256sum /home/${MY_USERNAME}/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline | awk -F ' ' '{print $1}')
  691. HASH2=$(sha256sum ~/.powerline.bash | awk -F ' ' '{print $1}')
  692. if [[ "$HASH1" != "$HASH2" ]]; then
  693. cp /home/${MY_USERNAME}/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline ~/.powerline.bash
  694. fi
  695. fi
  696. if [ ! -f /etc/skel/.powerline.bash ]; then
  697. cp /home/${MY_USERNAME}/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline /etc/skel/.powerline.bash
  698. else
  699. HASH1=$(sha256sum /home/${MY_USERNAME}/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline | awk -F ' ' '{print $1}')
  700. HASH2=$(sha256sum /etc/skel/.powerline.bash | awk -F ' ' '{print $1}')
  701. if [[ "$HASH1" != "$HASH2" ]]; then
  702. cp /home/${MY_USERNAME}/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline /etc/skel/.powerline.bash
  703. fi
  704. fi
  705. fi
  706. fi
  707. if ! grep -q "powerline" ~/.bashrc; then
  708. if [ -f ~/.powerline.bash ]; then
  709. echo 'source ~/.powerline.bash' >> ~/.bashrc
  710. fi
  711. fi
  712. if ! grep -q "powerline" /etc/skel/.bashrc; then
  713. if [ -f /etc/skel/.powerline.bash ]; then
  714. echo 'source ~/.powerline.bash' >> /etc/skel/.bashrc
  715. fi
  716. fi
  717. }
  718. function congestion_control {
  719. # see /proc/sys/net/ipv4/tcp_congestion_control
  720. if [ ! -f /etc/sysctl.d/10-custom-kernel-bbr.conf ]; then
  721. echo 'net.core.default_qdisc=fq' > /etc/sysctl.d/10-custom-kernel-bbr.conf
  722. echo 'net.ipv4.tcp_congestion_control=bbr' >> /etc/sysctl.d/10-custom-kernel-bbr.conf
  723. sysctl --system
  724. fi
  725. }
  726. function install_shellcheck {
  727. # Used by the tests command
  728. apt-get -yq install shellcheck
  729. }
  730. function microsd_card_optimisations {
  731. # These values can improve performance on microSD cards
  732. apt-get -yq install hdparm
  733. printf '#!/bin/bash\n' > /usr/bin/enable_optimisations
  734. if [ -f /sys/devices/virtual/bdi/179:0/read_ahead_kb ]; then
  735. echo -n '4096' > /sys/devices/virtual/bdi/179:0/read_ahead_kb
  736. echo "echo -n '4096' > /sys/devices/virtual/bdi/179:0/read_ahead_kb" >> /usr/bin/enable_optimisations
  737. fi
  738. if [ -f /proc/sys/vm/dirty_expire_centisecs ]; then
  739. echo -n '100' > /proc/sys/vm/dirty_expire_centisecs
  740. echo "echo -n '100' > /proc/sys/vm/dirty_expire_centisecs" >> /usr/bin/enable_optimisations
  741. fi
  742. if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
  743. echo -n '100' > /proc/sys/vm/dirty_writeback_centisecs
  744. echo "echo -n '100' > /proc/sys/vm/dirty_writeback_centisecs" >> /usr/bin/enable_optimisations
  745. fi
  746. chmod +x /usr/bin/enable_optimisations
  747. { echo '[Unit]';
  748. echo "Description=${PROJECT_NAME} optimisations";
  749. echo 'After=syslog.target';
  750. echo 'After=network.target';
  751. echo 'After=remote-fs.target';
  752. echo '';
  753. echo '[Service]';
  754. echo 'Type=simple';
  755. echo 'User=root';
  756. echo 'Group=root';
  757. echo 'WorkingDirectory=/root';
  758. echo 'ExecStart=/usr/bin/enable_optimisations';
  759. echo '';
  760. echo '[Install]';
  761. echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/optimisations.service
  762. systemctl enable optimisations
  763. }
  764. function setup_utils {
  765. read_config_param "PROJECT_REPO"
  766. write_config_param "PROJECT_REPO" "$PROJECT_REPO"
  767. function_check remove_management_engine_interface
  768. remove_management_engine_interface
  769. function_check support_256_colours
  770. support_256_colours
  771. function_check congestion_control
  772. congestion_control
  773. function_check enable_predictable_device_names
  774. enable_predictable_device_names
  775. function_check turn_off_magic_sysrq
  776. turn_off_magic_sysrq
  777. function_check separate_tmp_filesystem
  778. separate_tmp_filesystem 150
  779. function_check microsd_card_optimisations
  780. microsd_card_optimisations
  781. function_check proc_filesystem_settings
  782. proc_filesystem_settings
  783. function_check optimise_filesystem
  784. optimise_filesystem
  785. function_check disable_null_passwords
  786. disable_null_passwords
  787. function_check disable_ctrl_alt_del
  788. disable_ctrl_alt_del
  789. function_check dummy_nologin_command
  790. dummy_nologin_command
  791. function_check disable_core_dumps
  792. disable_core_dumps
  793. function_check remove_serial_logins
  794. remove_serial_logins
  795. function_check set_max_login_tries
  796. set_max_login_tries 10
  797. function_check set_shadow_permissions
  798. set_shadow_permissions
  799. function_check remove_bluetooth
  800. remove_bluetooth
  801. function_check set_login_umask
  802. set_login_umask
  803. function_check disable_deferred_execution
  804. disable_deferred_execution
  805. function_check turn_off_rsys_logging
  806. turn_off_rsys_logging
  807. function_check install_backports_kernel
  808. install_backports_kernel
  809. function_check create_completion_file
  810. create_completion_file
  811. function_check read_configuration
  812. read_configuration
  813. function_check check_system_type
  814. check_system_type
  815. function_check set_default_onion_domains
  816. set_default_onion_domains
  817. function_check locale_setup
  818. locale_setup
  819. function_check parse_args
  820. parse_args
  821. function_check check_domains
  822. check_domains
  823. function_check install_static_network
  824. install_static_network
  825. function_check remove_default_user
  826. remove_default_user
  827. function_check setup_firewall
  828. setup_firewall
  829. function_check create_repo_sources
  830. create_repo_sources
  831. function_check configure_dns
  832. configure_dns
  833. function_check initial_setup
  834. initial_setup
  835. function_check setup_grub
  836. setup_grub
  837. function_check install_tor
  838. install_tor
  839. function_check check_tor_health
  840. check_tor_health
  841. function_check install_command_line_browser
  842. install_command_line_browser
  843. function_check enable_ssh_via_onion
  844. enable_ssh_via_onion
  845. function_check check_date
  846. check_date
  847. function_check install_dynamicdns
  848. install_dynamicdns
  849. function_check randomize_cron
  850. randomize_cron
  851. function_check create_freedns_updater
  852. create_freedns_updater
  853. function_check mark_admin_user_account
  854. mark_admin_user_account
  855. function_check enforce_good_passwords
  856. enforce_good_passwords
  857. function_check change_login_message
  858. change_login_message
  859. function_check enable_zram
  860. enable_zram
  861. function_check random_number_generator
  862. random_number_generator
  863. function_check set_your_domain_name
  864. set_your_domain_name
  865. function_check configure_internet_protocol
  866. configure_internet_protocol
  867. function_check create_git_project
  868. create_git_project
  869. function_check setup_wifi
  870. setup_wifi
  871. function_check configure_ssh
  872. configure_ssh
  873. function_check configure_ssh_onion
  874. configure_ssh_onion
  875. function_check allow_ssh_to_onion_address
  876. allow_ssh_to_onion_address
  877. function_check remove_instructions_from_motd
  878. remove_instructions_from_motd
  879. function_check check_hwrng
  880. check_hwrng
  881. function_check search_for_attached_usb_drive
  882. search_for_attached_usb_drive
  883. function_check regenerate_ssh_keys
  884. regenerate_ssh_keys
  885. function_check create_upgrade_script
  886. create_upgrade_script
  887. function_check letsencrypt_renewals
  888. letsencrypt_renewals
  889. function_check install_watchdog_script
  890. install_watchdog_script
  891. function_check install_avahi
  892. install_avahi
  893. function_check keep_avahi_running
  894. keep_avahi_running
  895. function_check create_avahi_onion_domains
  896. create_avahi_onion_domains
  897. #function_check install_atheros_wifi
  898. #install_atheros_wifi
  899. function_check route_outgoing_traffic_through_tor
  900. route_outgoing_traffic_through_tor
  901. function_check upgrade_golang
  902. upgrade_golang
  903. function_check install_tomb
  904. install_tomb
  905. function_check admin_user_sudo
  906. admin_user_sudo
  907. function_check limit_user_logins
  908. limit_user_logins
  909. function_check schedule_stig_tests
  910. schedule_stig_tests
  911. function_check create_usb_canary
  912. create_usb_canary
  913. function_check setup_powerline
  914. setup_powerline
  915. function_check install_shellcheck
  916. install_shellcheck
  917. }
  918. function setup_email {
  919. function_check create_completion_file
  920. create_completion_file
  921. function_check install_email
  922. install_email
  923. function_check remove_ip_addresses_from_email_logs
  924. remove_ip_addresses_from_email_logs
  925. function_check create_procmail
  926. create_procmail
  927. function_check handle_admin_emails
  928. handle_admin_emails
  929. function_check spam_filtering
  930. spam_filtering
  931. function_check configure_imap
  932. configure_imap
  933. #function_check configure_imap_client_certs
  934. #configure_imap_client_certs
  935. function_check configure_gpg
  936. configure_gpg
  937. function_check refresh_gpg_keys
  938. refresh_gpg_keys
  939. function_check configure_backup_key
  940. configure_backup_key
  941. #function_check install_monkeysphere
  942. #install_monkeysphere
  943. function_check email_client
  944. email_client
  945. function_check encrypt_incoming_email
  946. encrypt_incoming_email
  947. function_check encrypt_outgoing_email
  948. encrypt_outgoing_email
  949. function_check email_archiving
  950. email_archiving
  951. function_check email_from_address
  952. email_from_address
  953. function_check create_public_mailing_list
  954. #create_public_mailing_list
  955. #function check create_private_mailing_list
  956. #create_private_mailing_list
  957. function_check encrypt_all_email
  958. encrypt_all_email
  959. function_check import_email
  960. import_email
  961. }
  962. function setup_web {
  963. function_check create_completion_file
  964. create_completion_file
  965. function_check install_web_server
  966. install_web_server
  967. function_check install_web_server_access_control
  968. install_web_server_access_control
  969. function_check install_web_local_user_interface
  970. install_web_local_user_interface
  971. }
  972. function upgrade_apps {
  973. function_check create_completion_file
  974. create_completion_file
  975. APPS_COMPLETED=()
  976. FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
  977. # for all the app scripts
  978. for filename in $FILES
  979. do
  980. app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
  981. # shellcheck disable=SC2068
  982. if ! item_in_array "${app_name}" ${APPS_COMPLETED[@]}; then
  983. function_check app_is_installed
  984. if [[ "$(app_is_installed "$app_name")" == "1" ]]; then
  985. echo ''
  986. echo ''
  987. echo $"Upgrading $app_name"
  988. app_load_variables "${app_name}"
  989. APPS_COMPLETED+=("${app_name}")
  990. function_check "upgrade_${app_name}"
  991. "upgrade_${app_name}"
  992. fi
  993. fi
  994. done
  995. }
  996. function setup_apps {
  997. is_interactive=$1
  998. function_check create_completion_file
  999. create_completion_file
  1000. function_check detect_installable_apps
  1001. detect_installable_apps
  1002. function_check choose_apps_for_variant
  1003. choose_apps_for_variant "$SYSTEM_TYPE"
  1004. echo $"System variant: $SYSTEM_TYPE"
  1005. #echo $'The following apps have been selected'
  1006. #echo ''
  1007. #function_check list_chosen_apps
  1008. #list_chosen_apps
  1009. #echo ''
  1010. function_check upgrade_apps
  1011. upgrade_apps
  1012. if [[ $is_interactive == "noninteractive" || $is_interactive == "headless" ]]; then
  1013. function_check install_apps
  1014. install_apps
  1015. if [ ! "$APP_INSTALLED_SUCCESS" ]; then
  1016. echo $'One or more apps failed to install'
  1017. fi
  1018. fi
  1019. }
  1020. function combine_all_scripts {
  1021. combined_filename=$1
  1022. # initial variables
  1023. cp "$PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars" "$combined_filename"
  1024. # utilities
  1025. UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
  1026. for f in $UTILS_FILES
  1027. do
  1028. # this removes the first line, which is #!/bin/bash
  1029. tail -n +2 "$f" >> "$combined_filename"
  1030. done
  1031. # base system
  1032. BASE_SYSTEM_FILES="/usr/share/${PROJECT_NAME}/base/${PROJECT_NAME}-base-*"
  1033. for f in $BASE_SYSTEM_FILES
  1034. do
  1035. tail -n +2 "$f" >> "$combined_filename"
  1036. done
  1037. # apps
  1038. APP_FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
  1039. for f in $APP_FILES
  1040. do
  1041. tail -n +2 "$f" >> "$combined_filename"
  1042. done
  1043. }
  1044. function check_ram_availability {
  1045. minimum_ram_MB="$1"
  1046. minimum_ram_bytes=$((minimum_ram_MB * 1024))
  1047. ram_available=$(grep MemTotal /proc/meminfo | awk '{print $2}')
  1048. if [ "$ram_available" -lt "$minimum_ram_bytes" ]; then
  1049. echo $"Need at least ${minimum_ram_MB}MB RAM to install this app"
  1050. exit 783524
  1051. fi
  1052. }
  1053. # NOTE: deliberately no exit 0