Last active
July 3, 2024 16:10
-
-
Save MissKittin/45b6c54a801e3336b609613be1bad13b to your computer and use it in GitHub Desktop.
Quickly setup dev environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# (mainly) web dev env builder for debian/ubuntu | |
# | |
# Note: | |
# running the script on a freshly installed system is recommended | |
# run this script as non-privileged user | |
# reboot after installation | |
# all servers except ssh listens only on localhost | |
# | |
# Usage: | |
# build-dev-env.sh ["package1 package2 packageN"] | |
# | |
# Packages: | |
# |Containers | |
# ||docker.io with docker-compose | |
# || note: on systemd uses socket activation (starts on demand) | |
# |Databases | |
# ||jq | |
# ||libxml2 utils | |
# ||DB Browser for SQLite (editor) | |
# ||memcached-phpmemcachedadmin | |
# || note: on systemd uses socket activation (starts on demand) | |
# ||postgresql-phppgadmin | |
# || note: a working phppgadmin package for bookworm is in backports | |
# || postresql & phppgadmin login/password: postgres/postgres | |
# || note: on systemd uses socket activation (starts on demand) | |
# ||postgresql overlay | |
# || all operations are saved in RAM (overlay fs driver is required) | |
# ||mariadb-phpmyadmin | |
# || note: phpmyadmin package may be in backports repo | |
# || note: on systemd uses socket activation (starts on demand) | |
# || mysql login/password: root/root | |
# || phpmyadmin login/password: phpmyadmin/phpmyadmin | |
# || note: you may encounter | |
# || "Specified key was too long; max key length is 1000 bytes" | |
# || export BDE_NO_MYISAM=yes # to disable MyISAM engine | |
# ||mysql overlay | |
# || all operations are saved in RAM (overlay fs driver is required) | |
# ||redis-phpredisadmin | |
# || note: on systemd uses socket activation (starts on demand) | |
# ||sqlite3 | |
# ||ekvedaras' redis-gui | |
# ||Juraj Novak's SQLite Viewer | |
# ||Joe Beach's JSON Path Finder | |
# |Debian tools | |
# ||non-free/multiverse repository list | |
# ||universe repository list | |
# ||buster-backports repository list | |
# ||bookworm-backports repository list | |
# ||"System is ready" message on ttyS0 | |
# || useful when running qemu with the -nographic option | |
# ||dpkg development tools | |
# ||debootstrap | |
# ||ethtool | |
# ||evince | |
# ||fdisk-cfdisk-gdisk-cgdisk | |
# ||gparted | |
# ||htop | |
# ||icewm dev tools menu | |
# ||lxqt-sudo | |
# || with thunar customization | |
# ||net tools | |
# ||synaptic | |
# ||tango icon theme | |
# ||Tiny Core Linux | |
# ||xchm | |
# ||xfce4 taskmanager | |
# |Drivers | |
# ||VirtualBox Guest Additions latest stable | |
# |Editors and IDEs | |
# ||bless | |
# ||dos2unix | |
# ||mousepad | |
# ||notepadqq | |
# || from debian/ubuntu repo or ppa | |
# ||tmux-vim | |
# || with Plug and NERDTree | |
# |Encryption tools | |
# ||cryptsetup | |
# ||keepassxc | |
# ||veracrypt | |
# |File utils | |
# ||curl | |
# ||fdupes | |
# ||file utility (libmagic) | |
# ||file roller-bzip2-cabextract-p7zip-lzma-zip-unzip-unrar-unshield-xz-arj | |
# || unrar is in the non-free/multiverse section | |
# ||filezilla | |
# ||git-gitk-git gui | |
# ||gnome screenshot | |
# ||inotify tools | |
# ||isomaster-xorriso-syslinux utils | |
# || with isohybrid tool | |
# ||midnight commander | |
# ||mirage | |
# ||squashfs tools | |
# ||transmission | |
# ||tree | |
# ||thunar archive plugin | |
# || if thunar is installed | |
# ||wget | |
# |(HTTP) servers | |
# ||apache | |
# || disabled by default | |
# ||apache-modphp | |
# ||nginx | |
# ||nginx-php fpm | |
# || note: on systemd uses socket activation (starts on demand) | |
# ||lighttpd | |
# ||lighttpd-php fpm | |
# || note: on systemd uses socket activation (starts on demand) | |
# ||netcat | |
# ||proftpd | |
# || /var/www login/password: www-data/www-data | |
# || note: on systemd uses socket activation (starts on demand) | |
# ||stunnel | |
# ||ucspi tcp | |
# |Interpreters, package managers, compilers and debuggers | |
# ||binutils | |
# ||gcc-g++-make-libc6 dev | |
# ||nodejs with npm and yarn | |
# ||lessc | |
# ||php-phpbrew with composer | |
# ||sassc | |
# ||strace | |
# |Launchers | |
# ||docker portainer | |
# ||docker smtp4dev | |
# |Remote access | |
# ||putty | |
# ||ssh | |
# ||vinagre | |
# ||x11vnc | |
# |Virtualization | |
# ||qemu | |
# || userspace emulator, qemu-img and qemu-nbd | |
# |Web browsers | |
# ||chromium | |
# || default browser | |
# ||firefox | |
# |Scripts | |
# ||add-localhost-domain.sh hosts patcher | |
# ||Apache2 temporary a2en a2dis helpers | |
# ||Apache2-nginx switcher (switch-apache-nginx.sh) | |
# ||cpSUM (cpsum.sh) | |
# ||debootstrap-quick.pl helper | |
# ||docker helpers (docker-*.sh) | |
# ||git-toolbox.sh (in ~/git/git-toolbox.sh) | |
# ||luks-container.sh create/mount helper | |
# ||SMB/CIFS mount helper (mount-smb.sh) | |
# ||PHP CLI docker launcher | |
# ||shell cheats and "include" function | |
# ||Lorem ipsum generator | |
# ||/etc/nginx tmpfs overlay | |
# ||/var/www tmpfs overlay | |
# |Docs | |
# ||HTML & CSS: The Complete Reference | |
### Internal functions | |
create_shortcut() | |
{ | |
local file="/usr/local/share/dev-tools-menu/share/applications/${1}" | |
local type="${2}" | |
local name="${3}" | |
local exec="${4}" | |
local icon="${5}" | |
if [ ! -e '/usr/local/share/dev-tools-menu' ]; then | |
mkdir '/usr/local/share/dev-tools-menu' | |
chown 'root:root' '/usr/local/share/dev-tools-menu' | |
chmod -s '/usr/local/share/dev-tools-menu' | |
mkdir '/usr/local/share/dev-tools-menu/etc' | |
mkdir '/usr/local/share/dev-tools-menu/share' | |
mkdir '/usr/local/share/dev-tools-menu/share/applications' | |
mkdir '/usr/local/share/dev-tools-menu/share/desktop-directories' | |
echo '<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN" "http://www.freedesktop.org/standards/menu-spec/1.0/menu.dtd">' > '/usr/local/share/dev-tools-menu/etc/dev-tools.menu' | |
echo '<Menu>' >> '/usr/local/share/dev-tools-menu/etc/dev-tools.menu' | |
echo '<Name>Applications</Name>' >> '/usr/local/share/dev-tools-menu/etc/dev-tools.menu' | |
echo '<Menu>' >> '/usr/local/share/dev-tools-menu/etc/dev-tools.menu' | |
echo '<Name>Dev Tools</Name>' >> '/usr/local/share/dev-tools-menu/etc/dev-tools.menu' | |
echo '<DirectoryDir>/usr/local/share/dev-tools-menu/share/desktop-directories</DirectoryDir>' >> '/usr/local/share/dev-tools-menu/etc/dev-tools.menu' | |
echo '<AppDir>/usr/local/share/dev-tools-menu/share/applications</AppDir>' >> '/usr/local/share/dev-tools-menu/etc/dev-tools.menu' | |
echo '<Directory>dev-tools.directory</Directory>' >> '/usr/local/share/dev-tools-menu/etc/dev-tools.menu' | |
echo '<Include>' >> '/usr/local/share/dev-tools-menu/etc/dev-tools.menu' | |
echo '<Category>Dev-Tools</Category>' >> '/usr/local/share/dev-tools-menu/etc/dev-tools.menu' | |
echo '</Include>' >> '/usr/local/share/dev-tools-menu/etc/dev-tools.menu' | |
echo '</Menu>' >> '/usr/local/share/dev-tools-menu/etc/dev-tools.menu' | |
echo '</Menu>' >> '/usr/local/share/dev-tools-menu/etc/dev-tools.menu' | |
echo '[Desktop Entry]' > '/usr/local/share/dev-tools-menu/share/desktop-directories/dev-tools.directory' | |
echo 'Version=1.0' >> '/usr/local/share/dev-tools-menu/share/desktop-directories/dev-tools.directory' | |
echo 'Type=Directory' >> '/usr/local/share/dev-tools-menu/share/desktop-directories/dev-tools.directory' | |
echo 'Icon=applications-system' >> '/usr/local/share/dev-tools-menu/share/desktop-directories/dev-tools.directory' | |
echo 'Name=Dev Tools' >> '/usr/local/share/dev-tools-menu/share/desktop-directories/dev-tools.directory' | |
mkdir -p '/etc/xdg/menus/applications-merged' | |
ln -s '/usr/local/share/dev-tools-menu/etc/dev-tools.menu' '/etc/xdg/menus/applications-merged/dev-tools.menu' | |
fi | |
case "${type}" in | |
'application'|'console-application') | |
echo '[Desktop Entry]' > "${file}" | |
echo 'Version=1.0' >> "${file}" | |
echo 'Type=Application' >> "${file}" | |
echo 'Categories=Dev-Tools;' >> "${file}" | |
echo "Name=${name}" >> "${file}" | |
echo 'Comment=' >> "${file}" | |
echo "Exec=${exec}" >> "${file}" | |
echo "Icon=${icon}" >> "${file}" | |
echo 'Path=' >> "${file}" | |
if [ "${type}" = 'console-application' ]; then | |
echo 'Terminal=true' >> "${file}" | |
else | |
echo 'Terminal=false' >> "${file}" | |
fi | |
echo 'StartupNotify=false' >> "${file}" | |
;; | |
'link') | |
echo '[Desktop Entry]' > "${file}" | |
echo 'Version=1.0' >> "${file}" | |
echo 'Type=Link' >> "${file}" | |
echo 'Categories=Dev-Tools;' >> "${file}" | |
echo "Name=${name}" >> "${file}" | |
echo 'Comment=' >> "${file}" | |
echo "Icon=${icon}" >> "${file}" | |
echo "URL=${exec}" >> "${file}" | |
;; | |
esac | |
} | |
create_socket_activation_unit() | |
{ | |
local service_name="${1}" | |
local pretty_service_name="${2}" | |
local socket_type="${3}" | |
local original_socket_addr="${4}" | |
local new_socket_addr="${5}" | |
local user="${6}" | |
local group="${7}" | |
local mode="${8}" | |
local output_file | |
case "${socket_type}" in | |
'inet') | |
pretty_socket_type='TCP/IP' | |
;; | |
'unix') | |
pretty_socket_type='UNIX' | |
;; | |
esac | |
if [ ! -e '/usr/local/etc/systemd' ]; then | |
mkdir -p '/usr/local/etc/systemd' | |
chown 'root:root' '/usr/local/etc/systemd' | |
chmod -s '/usr/local/etc/systemd' | |
mkdir '/usr/local/etc/systemd/system' | |
fi | |
output_file="/usr/local/etc/systemd/system/socket-proxyd_${service_name}_${socket_type}.socket" | |
echo '[Unit]' > "${output_file}" | |
echo "Description=${pretty_socket_type} socket proxy for ${pretty_service_name}" >> "${output_file}" | |
echo '' >> "${output_file}" | |
echo '[Socket]' >> "${output_file}" | |
echo "ListenStream=${original_socket_addr}" >> "${output_file}" | |
[ ! "${user}" = 'null' ] && echo "SocketUser=${user}" >> "${output_file}" | |
[ ! "${group}" = 'null' ] && echo "SocketGroup=${group}" >> "${output_file}" | |
[ ! "${mode}" = 'null' ] && echo "SocketMode=${mode}" >> "${output_file}" | |
echo '' >> "${output_file}" | |
echo '[Install]' >> "${output_file}" | |
echo 'WantedBy=sockets.target' >> "${output_file}" | |
ln -s "${output_file}" "/etc/systemd/system/socket-proxyd_${service_name}_${socket_type}.socket" | |
output_file="/usr/local/etc/systemd/system/socket-proxyd_${service_name}_${socket_type}.service" | |
echo '[Unit]' > "${output_file}" | |
echo "Requires=${service_name}.service" >> "${output_file}" | |
echo "After=${service_name}.service" >> "${output_file}" | |
echo "Requires=socket-proxyd_${service_name}_${socket_type}.socket" >> "${output_file}" | |
echo "After=socket-proxyd_${service_name}_${socket_type}.socket" >> "${output_file}" | |
echo '' >> "${output_file}" | |
echo '[Service]' >> "${output_file}" | |
echo 'Type=notify' >> "${output_file}" | |
echo "ExecStart=/usr/lib/systemd/systemd-socket-proxyd ${new_socket_addr}" >> "${output_file}" | |
echo 'PrivateTmp=no' >> "${output_file}" | |
echo 'PrivateNetwork=no' >> "${output_file}" | |
ln -s "${output_file}" "/etc/systemd/system/socket-proxyd_${service_name}_${socket_type}.service" | |
systemctl enable "socket-proxyd_${service_name}_${socket_type}.socket" | |
} | |
install_packages() | |
{ | |
local loops | |
if ! "${_apt_updated}"; then | |
for loops in 1 2 3; do | |
if apt-get update; then | |
_apt_updated='true' | |
break | |
fi | |
if [ "${loops}" = '3' ]; then | |
echo " -> apt-get update failed, not retrying..." | |
else | |
echo " -> apt-get update failed, retrying..." | |
sleep 1 | |
fi | |
done | |
fi | |
local return_code | |
local package | |
for package in ${@}; do | |
for loops in 1 2 3; do | |
DEBIAN_FRONTEND='noninteractive' apt-get install -y --no-install-recommends "${package}" && return_code='0' && break || return_code='1' | |
echo '' | |
if [ "${loops}" = '3' ]; then | |
echo " -> package ${package} install failed, not retrying..." | |
else | |
echo " -> package ${package} install failed, retrying..." | |
sleep 1 | |
fi | |
done | |
done | |
apt-get clean | |
return "${return_code}" | |
} | |
_apt_updated='false' | |
### Header | |
(return 0 2>/dev/null) && _script_sourced='true' || _script_sourced='false' | |
if ! "${_script_sourced}"; then | |
if [ "${1}" = '--help' ] || [ "${1}" = '-h' ]; then | |
first_line='true' | |
while IFS= read -r line; do | |
"${first_line}" && first_line='false' && continue | |
[ ! "${line:0:2}" = '# ' ] && break | |
echo "${line:2}" | |
done < "${0}" | |
exit 0 | |
fi | |
if [ ! "$(whoami)" = 'root' ]; then | |
if ! command -v sudo > /dev/null 2>&1; then | |
echo 'sudo not found' | |
exit 1 | |
fi | |
echo -n 'Install? (Y/[n]) ' | |
read answer | |
[ ! "${answer}" = 'Y' ] && exit 0 | |
exec sudo "${0}" "$(whoami)" "${HOME}" "${1}" | |
fi | |
if [ "${1}" = '' ]; then | |
echo 'root? really?' | |
exit 1 | |
fi | |
username="${1}" | |
if [ "${2}" = '' ]; then | |
echo '$HOME is not set' | |
exit 1 | |
fi | |
if [ ! -e "${2}" ]; then | |
echo "${2} does not exist - mission failed" | |
exit 1 | |
fi | |
HOME="${2}" | |
# ${3} is for $packages_list in Main | |
fi | |
### Containers | |
install__docker_ce() | |
{ | |
local docker_compose_version='v2.28.1' | |
local debian_version=$(cat '/etc/os-release' | grep '^VERSION_CODENAME=') | |
local i | |
if [ "${debian_version}" = '' ]; then | |
echo "debian version not found" | |
return 1 | |
fi | |
install_packages wget apt-transport-https ca-certificates gpg | |
if [ ! -e '/usr/local/etc/apt/sources.list.d' ]; then | |
mkdir -p '/usr/local/etc/apt' | |
chown 'root:root' '/usr/local/etc/apt' | |
chmod -s '/usr/local/etc/apt' | |
mkdir '/usr/local/etc/apt/sources.list.d' | |
fi | |
echo 'deb https://download.docker.com/linux/debian '"${debian_version##*=}"' stable' > /usr/local/etc/apt/sources.list.d/docker.list | |
ln -s '/usr/local/etc/apt/sources.list.d/docker.list' '/etc/apt/sources.list.d/docker.list' | |
GNUPGHOME=$(mktemp -d) | |
chmod 700 "${GNUPGHOME}" | |
export GNUPGHOME | |
GPG_TEMP_DIR=$(mktemp -d) | |
export GPG_TEMP_DIR | |
mkdir -p '/usr/local/etc/apt/trusted.gpg.d'; | |
for i in 1 2 3; do | |
wget -O - 'https://download.docker.com/linux/debian/gpg' | gpg --dearmor --yes -o '/usr/local/etc/apt/trusted.gpg.d/docker.gpg' && break | |
done | |
ln -s '/usr/local/etc/apt/trusted.gpg.d/docker.gpg' '/etc/apt/trusted.gpg.d/docker.gpg' | |
rm -r "${GPG_TEMP_DIR}" | |
GPG_TEMP_DIR='' | |
export GPG_TEMP_DIR | |
rm -r -f "${GNUPGHOME}" | |
GNUPGHOME='' | |
export GNUPGHOME | |
_apt_updated='false' | |
install_packages docker-ce | |
for i in 1 2 3; do | |
if wget -O '/usr/local/bin/docker-compose' "https://github.com/docker/compose/releases/download/${docker_compose_version}/docker-compose-$(uname -s)-$(uname -m)"; then | |
chown 'root:root' '/usr/local/bin/docker-compose' | |
chmod 755 '/usr/local/bin/docker-compose' | |
break | |
fi | |
done | |
service docker stop | |
service containerd stop | |
} | |
install__docker_io() | |
{ | |
install_packages docker.io docker-compose | |
if [ -d '/etc/systemd/system' ] && command -v 'systemctl' > /dev/null 2>&1 && systemctl enable docker.socket; then | |
systemctl disable docker.service | |
systemctl stop docker.service | |
systemctl disable containerd.service | |
systemctl stop containerd.service | |
fi | |
service docker stop | |
service containerd stop | |
} | |
install__docker() | |
{ | |
if ! install__docker_io; then | |
install__docker_ce | |
fi | |
} | |
### Databases | |
install__jq() { install_packages jq; } | |
install__libxmlutils() { install_packages libxml2-utils; } | |
install__sqlitebrowser() { install_packages sqlitebrowser; } | |
install__memcached_phpmemcachedadmin() | |
{ | |
### memcached | |
local script_path | |
local i | |
install_packages memcached libmemcached-tools | |
if [ -e '/etc/memcached.conf' ]; then | |
cp -p '/etc/memcached.conf' '/etc/memcached.conf.old' | |
mv '/etc/memcached.conf' '/usr/local/etc/memcached.conf' | |
ln -s '/usr/local/etc/memcached.conf' '/etc/memcached.conf' | |
script_path='/usr/local/etc/memcached.conf' | |
echo '' >> "${script_path}" | |
echo '# Uncomment this to enable unix socket' >> "${script_path}" | |
echo '#-s /var/run/memcached/memcached.sock' >> "${script_path}" | |
echo '#-a 0777' >> "${script_path}" | |
rm '/var/log/memcached.log' | |
ln -s '/var/run/memcached/memcached.log' '/var/log/memcached.log' | |
fi | |
### bash aliases | |
if [ ! -e "${HOME}/.bashrc" ]; then | |
echo -n '' > "${HOME}/.bashrc" | |
chown "${username}:${username}" "${HOME}/.bashrc" | |
else | |
echo '' >> "${HOME}/.bashrc" | |
fi | |
for i in memccat memccp memcdump memcexist memcflush memcping memcrm memcslap memcstat memctouch; do | |
echo -n "alias ${i}='${i} --servers=127.0.0.1:11211';" >> "${HOME}/.bashrc" | |
done | |
echo '' >> "${HOME}/.bashrc" | |
### phpmemcachedadmin | |
local current_dir=$(pwd) | |
install_packages ca-certificates git | |
mkdir '/usr/local/share/phpmemcachedadmin' | |
chown 'root:root' '/usr/local/share/phpmemcachedadmin' | |
chmod -s '/usr/local/share/phpmemcachedadmin' | |
cd '/usr/local/share/phpmemcachedadmin' | |
for i in 1 2 3; do | |
if git clone 'https://github.com/elijaa/phpmemcachedadmin.git' .; then | |
rm -r './docker' | |
rm -r -f './.git'; rm './.gitignore' | |
rm './composer.json'; rm './README.md'; rm './LICENSE' | |
if [ ! -e '/usr/local/etc/apache2' ]; then | |
mkdir -p '/usr/local/etc/apache2' | |
chown 'root:root' '/usr/local/etc/apache2' | |
chmod -s '/usr/local/etc/apache2' | |
fi | |
[ ! -e '/usr/local/etc/apache2/conf-available' ] && mkdir '/usr/local/etc/apache2/conf-available' | |
script_path='/usr/local/etc/apache2/conf-available/phpmemcachedadmin.conf' | |
echo 'Alias /phpmemcachedadmin /usr/local/share/phpmemcachedadmin' > "${script_path}" | |
#### | |
echo '<Directory /usr/local/share/phpmemcachedadmin>' >> "${script_path}" | |
echo '<IfModule mod_dir.c>' >> "${script_path}" | |
echo 'DirectoryIndex index.php' >> "${script_path}" | |
echo '</IfModule>' >> "${script_path}" | |
#### | |
echo 'AllowOverride None' >> "${script_path}" | |
echo 'Require local' >> "${script_path}" | |
echo '</Directory>' >> "${script_path}" | |
if [ -e '/etc/apache2/conf-available' ]; then | |
ln -s '/usr/local/etc/apache2/conf-available/phpmemcachedadmin.conf' '/etc/apache2/conf-available/phpmemcachedadmin.conf' | |
a2enconf phpmemcachedadmin | |
service apache2 status > /dev/null 2>&1 && service apache2 restart | |
fi | |
[ -e '/var/www/html' ] && ln -s '/usr/local/share/phpmemcachedadmin' '/var/www/html/phpmemcachedadmin' | |
create_shortcut 'phpmemcachedadmin.desktop' \ | |
'link' \ | |
'phpMemcachedAdmin' \ | |
'http://localhost/phpmemcachedadmin' \ | |
'internet-web-browser' | |
break | |
else | |
cd "${current_dir}" | |
rmdir '/usr/local/share/phpmemcachedadmin' | |
fi | |
done | |
cd "${current_dir}" | |
### systemd socket activation | |
if [ -d '/etc/systemd/system' ] && command -v 'systemctl' > /dev/null 2>&1; then | |
sed -i 's/-p 11211/#-p 11211\n-p 11212/g' '/usr/local/etc/memcached.conf' | |
sed -i 's/-s \/var\/run\/memcached\/memcached.sock/-s \/var\/run\/memcached\/memcached.sockx/g' '/usr/local/etc/memcached.conf' | |
create_socket_activation_unit \ | |
memcached Memcached inet \ | |
'127.0.0.1:11211' \ | |
'127.0.0.1:11212' \ | |
null null null | |
create_socket_activation_unit \ | |
memcached Memcached unix \ | |
'/run/memcached/memcached.sock' \ | |
'/run/memcached/memcached.sockx' \ | |
memcache memcache 0777 | |
systemctl disable memcached.service | |
fi | |
service memcached stop | |
} | |
_create_mysql_postgresql_overlay() | |
{ | |
# used in install__mysql_overlay | |
# used in install__postgresql_overlay | |
# only systemd and sysvinit are supported | |
local output_file="${1}" | |
local pretty_service_name="${2}" | |
local service_name="${3}" | |
local overlay_name="${4}" | |
local data_dir="${5}" | |
local uid="${6}" | |
local gid="${7}" | |
echo '#!/bin/sh' > "${output_file}" | |
#### | |
echo '### BEGIN INIT INFO' >> "${output_file}" | |
echo '# Provides: '"${overlay_name}" >> "${output_file}" | |
echo '# Required-Start:' >> "${output_file}" | |
echo '# Required-Stop: '"${service_name}" >> "${output_file}" | |
echo '# Default-Start: 2 3 4 5' >> "${output_file}" | |
echo '# Default-Stop: 0 1 6' >> "${output_file}" | |
echo '# Short-Description: '"${pretty_service_name}"' data overlay' >> "${output_file}" | |
echo '# Description: All operations are saved in RAM' >> "${output_file}" | |
echo '# X-Start-Before: '"${service_name}" >> "${output_file}" | |
echo '### END INIT INFO' >> "${output_file}" | |
#### | |
echo 'service_name="'"${service_name}"'"' >> "${output_file}" | |
echo 'overlay_name="'"${overlay_name}"'"' >> "${output_file}" | |
echo 'data_dir="'"${data_dir}"'"' >> "${output_file}" | |
echo 'uid="'"${uid}"'"' >> "${output_file}" | |
echo 'gid="'"${gid}"'"' >> "${output_file}" | |
#### | |
echo 'script_name="${0##*/}"' >> "${output_file}" | |
echo 'if [ "${script_name#'"${output_file##*/}"'}" = "-toggle" ]; then' >> "${output_file}" | |
echo '"$(readlink -f "${0}")" toggle' >> "${output_file}" | |
echo 'exit "$?"' >> "${output_file}" | |
echo 'fi' >> "${output_file}" | |
#### | |
echo 'if ! /sbin/modinfo overlay > /dev/null 2>&1; then' >> "${output_file}" | |
echo 'echo "Error: overlay fs driver is not available"' >> "${output_file}" | |
echo 'exit 1' >> "${output_file}" | |
echo 'fi' >> "${output_file}" | |
#### | |
echo 'if [ ! -e "${data_dir}" ]; then' >> "${output_file}" | |
echo 'echo "Error: ${data_dir} does not exist"' >> "${output_file}" | |
echo 'exit 1' >> "${output_file}" | |
echo 'fi' >> "${output_file}" | |
#### | |
echo 'case "${1}" in' >> "${output_file}" | |
echo '"start")' >> "${output_file}" | |
echo 'if [ -e "/var/run/.${overlay_name}" ]; then' >> "${output_file}" | |
echo 'echo "Error (start): /var/run/.${overlay_name} already exists"' >> "${output_file}" | |
echo 'exit 1' >> "${output_file}" | |
echo 'fi' >> "${output_file}" | |
#### | |
echo 'mkdir "/var/run/.${overlay_name}"' >> "${output_file}" | |
echo 'mount \' >> "${output_file}" | |
echo '-t tmpfs \' >> "${output_file}" | |
echo '-o "nodev,nosuid,noexec,uid=${uid},gid=${gid},mode=0711" \' >> "${output_file}" | |
echo '"${overlay_name}" \' >> "${output_file}" | |
echo '"/var/run/.${overlay_name}"' >> "${output_file}" | |
#### | |
echo 'mkdir "/var/run/.${overlay_name}/lower"' >> "${output_file}" | |
echo 'mkdir "/var/run/.${overlay_name}/diff"' >> "${output_file}" | |
echo 'mkdir "/var/run/.${overlay_name}/tmp"' >> "${output_file}" | |
#### | |
echo 'mount \' >> "${output_file}" | |
echo '--bind --make-rslave \' >> "${output_file}" | |
echo '"${data_dir}" \' >> "${output_file}" | |
echo '"/var/run/.${overlay_name}/lower"' >> "${output_file}" | |
#### | |
echo 'if ! mount \' >> "${output_file}" | |
echo '-t overlay \' >> "${output_file}" | |
echo '-o "lowerdir=/var/run/.${overlay_name}/lower,upperdir=/var/run/.${overlay_name}/diff,workdir=/var/run/.${overlay_name}/tmp" \' >> "${output_file}" | |
echo '"${overlay_name}" \' >> "${output_file}" | |
echo '"${data_dir}"' >> "${output_file}" | |
echo 'then' >> "${output_file}" | |
echo '"${0}" stop' >> "${output_file}" | |
echo 'exit 1' >> "${output_file}" | |
echo 'fi' >> "${output_file}" | |
#### | |
echo 'chown "${uid}:${gid}" "${data_dir}"' >> "${output_file}" | |
echo 'chmod 755 "${data_dir}"' >> "${output_file}" | |
echo ';;' >> "${output_file}" | |
echo '"stop")' >> "${output_file}" | |
echo 'if [ ! -e "/var/run/.${overlay_name}" ]; then' >> "${output_file}" | |
echo 'echo "Error (stop): /var/run/.${overlay_name} does not exist"' >> "${output_file}" | |
echo 'exit 1' >> "${output_file}" | |
echo 'fi' >> "${output_file}" | |
#### | |
echo 'umount "${data_dir}"' >> "${output_file}" | |
echo 'umount "/var/run/.${overlay_name}/lower"' >> "${output_file}" | |
echo 'umount "/var/run/.${overlay_name}"' >> "${output_file}" | |
echo 'rmdir "/var/run/.${overlay_name}"' >> "${output_file}" | |
echo ';;' >> "${output_file}" | |
echo '"status")' >> "${output_file}" | |
echo 'if [ ! -e "/var/run/.${overlay_name}" ]; then' >> "${output_file}" | |
echo 'echo "Overlay mode disabled"' >> "${output_file}" | |
echo 'exit 1' >> "${output_file}" | |
echo 'fi' >> "${output_file}" | |
#### | |
echo 'echo "Overlay mode enabled"' >> "${output_file}" | |
echo ';;' >> "${output_file}" | |
echo '"toggle")' >> "${output_file}" | |
echo 'if [ ! "$(whoami)" = "root" ]; then' >> "${output_file}" | |
echo 'echo " The database can work in two modes: normal and"' >> "${output_file}" | |
echo 'echo " temporary. In temporary mode, changes made to"' >> "${output_file}" | |
echo 'echo " the databases are stored in RAM. Use this script"' >> "${output_file}" | |
echo 'echo " if you want to make permanent changes."' >> "${output_file}" | |
echo 'echo ""' >> "${output_file}" | |
echo 'echo -n " The database is currently in "' >> "${output_file}" | |
echo '"${0}" status > /dev/null 2>&1 && echo -n "temporary" || echo -n "normal"' >> "${output_file}" | |
echo 'echo " mode"' >> "${output_file}" | |
echo 'echo ""' >> "${output_file}" | |
#### | |
echo 'sudo "${0}" ${@}' >> "${output_file}" | |
echo 'exit "$?"' >> "${output_file}" | |
echo 'fi' >> "${output_file}" | |
#### | |
echo 'service_started="false"' >> "${output_file}" | |
echo 'service "${service_name}" status > /dev/null 2>&1 && service_started="true"' >> "${output_file}" | |
#### | |
echo '"${service_started}" && echo "Stopping ${service_name}" && service "${service_name}" stop' >> "${output_file}" | |
#### | |
echo 'if [ -e "/var/run/.${overlay_name}" ]; then' >> "${output_file}" | |
echo 'echo "Restarting ${service_name} in persistent mode"' >> "${output_file}" | |
echo '"${0}" stop' >> "${output_file}" | |
echo 'else' >> "${output_file}" | |
echo 'echo "Restarting ${service_name} in overlay mode"' >> "${output_file}" | |
echo '"${0}" start' >> "${output_file}" | |
echo 'fi' >> "${output_file}" | |
#### | |
echo '[ "$?" = "0" ] && echo "Restarted successfully" || echo "Restarting failed"' >> "${output_file}" | |
#### | |
echo '"${service_started}" && echo "Starting ${service_name}" && service "${service_name}" start' >> "${output_file}" | |
#### | |
echo 'echo ""' >> "${output_file}" | |
echo 'echo -n "Press [ENTER]"' >> "${output_file}" | |
echo 'read enter' >> "${output_file}" | |
echo ';;' >> "${output_file}" | |
echo '*)' >> "${output_file}" | |
echo 'echo "${0} start|stop|status|toggle"' >> "${output_file}" | |
echo 'exit 1' >> "${output_file}" | |
echo ';;' >> "${output_file}" | |
echo 'esac' >> "${output_file}" | |
#### | |
echo 'exit 0' >> "${output_file}" | |
chown 'root:root' "${output_file}" | |
chmod 755 "${output_file}" | |
ln -s "${output_file##*/}" "${output_file}-toggle" | |
create_shortcut "${overlay_name}.desktop" \ | |
'console-application' \ | |
"Toggle ${pretty_service_name} overlay" \ | |
"${output_file}-toggle" \ | |
'changes-allow' | |
if [ -d '/etc/systemd/system' ] && command -v 'systemctl' > /dev/null 2>&1; then | |
if [ ! -e '/usr/local/etc/systemd' ]; then | |
mkdir -p '/usr/local/etc/systemd' | |
chown 'root:root' '/usr/local/etc/systemd' | |
chmod -s '/usr/local/etc/systemd' | |
mkdir '/usr/local/etc/systemd/system' | |
fi | |
local unit_file="/usr/local/etc/systemd/system/${overlay_name}.service" | |
echo '[Unit]' > "${unit_file}" | |
echo 'Description='"${pretty_service_name}"' data overlay' >> "${unit_file}" | |
echo 'Before='"${service_name}"'.service' >> "${unit_file}" | |
echo '' >> "${unit_file}" | |
echo '[Service]' >> "${unit_file}" | |
echo 'Type=oneshot' >> "${unit_file}" | |
echo 'RemainAfterExit=yes' >> "${unit_file}" | |
echo 'ExecStart='"${output_file}"' start' >> "${unit_file}" | |
echo 'ExecStop='"${output_file}"' stop' >> "${unit_file}" | |
echo '' >> "${unit_file}" | |
echo '[Install]' >> "${unit_file}" | |
echo 'WantedBy=multi-user.target' >> "${unit_file}" | |
ln -s "${unit_file}" "/etc/systemd/system/${overlay_name}.service" | |
systemctl enable "${overlay_name}.service" | |
fi | |
if [ -d '/etc/init.d' ] && command -v 'insserv' > /dev/null 2>&1; then | |
ln -s "${output_file}" "/etc/init.d/${overlay_name}" | |
insserv -d "${overlay_name}" | |
fi | |
} | |
install__mysql_phpmyadmin() | |
{ | |
local configure_phpmyadmin='true' | |
install_packages mariadb-server | |
if grep 'VERSION_CODENAME=buster' '/etc/os-release' > /dev/null 2>&1; then | |
echo 'debian buster detected' | |
install_packages php-twig/buster-backports phpmyadmin/buster-backports || configure_phpmyadmin='false' | |
apt-mark auto php-twig | |
else | |
install_packages phpmyadmin || configure_phpmyadmin='false' | |
fi | |
#echo -e '\n\nroot\nroot\n\nn\nn\n\n ' | mysql_secure_installation 2>/dev/null | |
# https://lowendbox.com/blog/automating-mysql_secure_installation-in-mariadb-setup/ | |
#echo "UPDATE mysql.user SET Password=PASSWORD('root') WHERE User='root'" | |
# mysql --user=root -e "UPDATE mysql.user SET Password=PASSWORD('root') WHERE User='root'" | |
echo "ALTER USER 'root'@'localhost' IDENTIFIED BY 'root'" | |
mysql --user=root -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'root'" | |
echo "DELETE FROM mysql.user WHERE User=''" | |
mysql --user=root --password=root -e "DELETE FROM mysql.user WHERE User=''" | |
echo "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')" | |
mysql --user=root --password=root -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')" | |
echo "DROP DATABASE IF EXISTS test" | |
mysql --user=root --password=root -e "DROP DATABASE IF EXISTS test" | |
echo "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" | |
mysql --user=root --password=root -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" | |
# https://gist.github.com/AndreaCardamone/6f3da9e46b96869a10f8b67f4c7e2128 | |
echo "UPDATE mysql.global_priv SET priv=json_set(priv, '$.password_last_changed', UNIX_TIMESTAMP(), '$.plugin', 'mysql_native_password', '$.authentication_string', 'invalid', '$.auth_or', json_array(json_object(), json_object('plugin', 'unix_socket'))) WHERE User='root'" | |
mysql --user=root -e "UPDATE mysql.global_priv SET priv=json_set(priv, '$.password_last_changed', UNIX_TIMESTAMP(), '$.plugin', 'mysql_native_password', '$.authentication_string', 'invalid', '$.auth_or', json_array(json_object(), json_object('plugin', 'unix_socket'))) WHERE User='root'" | |
echo "UPDATE mysql.global_priv SET priv=json_set(priv, '$.plugin', 'mysql_native_password', '$.authentication_string', PASSWORD('root')) WHERE User='root'" | |
mysql --user=root -e "UPDATE mysql.global_priv SET priv=json_set(priv, '$.plugin', 'mysql_native_password', '$.authentication_string', PASSWORD('root')) WHERE User='root'" | |
echo "DELETE FROM mysql.global_priv WHERE User=''" | |
mysql --user=root --password=root -e "DELETE FROM mysql.global_priv WHERE User=''" | |
echo "DELETE FROM mysql.global_priv WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')" | |
mysql --user=root --password=root -e "DELETE FROM mysql.global_priv WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')" | |
echo "FLUSH PRIVILEGES" | |
mysql --user=root --password=root -e "FLUSH PRIVILEGES" | |
if "${configure_phpmyadmin}"; then | |
echo 'DROP USER IF EXISTS "phpmyadmin"@"localhost"' | |
mysql --user=root --password=root -e 'DROP USER IF EXISTS "phpmyadmin"@"localhost"' | |
echo 'CREATE USER "phpmyadmin"@"localhost" IDENTIFIED BY "phpmyadmin"' | |
mysql --user=root --password=root -e 'CREATE USER "phpmyadmin"@"localhost" IDENTIFIED BY "phpmyadmin"' | |
echo 'GRANT ALL PRIVILEGES ON *.* TO "phpmyadmin"@"localhost" WITH GRANT OPTION' | |
mysql --user=root --password=root -e 'GRANT ALL PRIVILEGES ON *.* TO "phpmyadmin"@"localhost" WITH GRANT OPTION' | |
echo 'FLUSH PRIVILEGES' | |
mysql --user=root --password=root -e 'FLUSH PRIVILEGES' | |
if [ "${BDE_NO_MYISAM}" = 'yes' ]; then | |
echo 'CONVERT InnoDB TO MyISAM [SKIP]' | |
else | |
echo 'CONVERT InnoDB TO MyISAM' | |
mysql --user=root --password=root phpmyadmin -e "SHOW table status WHERE Engine='InnoDB';" | awk 'NR>1 {print "ALTER TABLE "$1" ENGINE = MyISAM;"}' | mysql --user=root --password=root phpmyadmin | |
fi | |
if [ -d '/etc/phpmyadmin/conf.d' ]; then | |
echo '<?php' > '/etc/phpmyadmin/conf.d/build-dev-env.php' | |
echo '$cfg['"'"'Servers'"'"'][1]['"'"'controluser'"'"'] = '"'"'root'"'"';' >> '/etc/phpmyadmin/conf.d/build-dev-env.php' | |
echo '$cfg['"'"'Servers'"'"'][1]['"'"'controlpass'"'"'] = '"'"'root'"'"';' >> '/etc/phpmyadmin/conf.d/build-dev-env.php' | |
chown 'root:www-data' '/etc/phpmyadmin/conf.d/build-dev-env.php' | |
chmod 640 '/etc/phpmyadmin/conf.d/build-dev-env.php' | |
fi | |
mkdir -p '/etc/apache2/conf-available' | |
ln -sf '../../phpmyadmin/apache.conf' '/etc/apache2/conf-available/phpmyadmin.conf' | |
a2enconf phpmyadmin | |
service apache2 status > /dev/null 2>&1 && service apache2 restart | |
[ -e '/var/www/html' ] && ln -s '/usr/share/phpmyadmin' '/var/www/html/phpmyadmin' | |
create_shortcut 'phpmyadmin.desktop' \ | |
'link' \ | |
'phpMyAdmin' \ | |
'http://localhost/phpmyadmin' \ | |
'phpmyadmin' | |
fi | |
mkdir -p '/usr/local/etc/mysql/conf.d' | |
chown -R 'root:root' '/usr/local/etc/mysql' | |
chmod -s '/usr/local/etc/mysql/conf.d' | |
chmod -s '/usr/local/etc/mysql' | |
local script_path='/usr/local/etc/mysql/conf.d/build-dev-env.cnf' | |
echo '[mysqld]' > "${script_path}" | |
echo 'skip-innodb' >> "${script_path}" | |
echo 'innodb=OFF' >> "${script_path}" | |
echo 'default-storage-engine=MyISAM' >> "${script_path}" | |
echo 'default-tmp-storage-engine=MyISAM' >> "${script_path}" | |
echo 'key_buffer_size=2M' >> "${script_path}" | |
echo 'query_cache_size=3M' >> "${script_path}" | |
echo 'max_connections=40' >> "${script_path}" | |
ln -s "${script_path}" "/etc/mysql/conf.d/${script_path##*/}" | |
if [ "${BDE_NO_MYISAM}" = 'yes' ]; then | |
echo ' -> disabling MyISAM engine' | |
sed -i 's/skip-innodb/#skip-innodb/g' "${script_path}" | |
sed -i 's/innodb=OFF/#innodb=OFF/g' "${script_path}" | |
sed -i 's/default-storage-engine=MyISAM/#default-storage-engine=MyISAM/g' "${script_path}" | |
sed -i 's/default-tmp-storage-engine=MyISAM/#default-tmp-storage-engine=MyISAM/g' "${script_path}" | |
fi | |
local restart_mysql='false' | |
service mysql status > /dev/null 2>&1 && restart_mysql='true' | |
"${restart_mysql}" && service mysql stop | |
rm -r '/var/log/mysql' | |
ln -s '/var/run/mysqld' '/var/log/mysql' | |
"${restart_mysql}" && service mysql start | |
[ -d '/etc/systemd/system' ] && command -v 'systemctl' > /dev/null 2>&1 && if systemctl enable mariadb.socket; then | |
systemctl disable mariadb.service | |
systemctl stop mariadb.service | |
systemctl disable mariadb.socket | |
mkdir '/usr/local/etc/systemd/system/proftpd.socket.d' | |
script_path='/usr/local/etc/systemd/system/proftpd.socket.d/localhost.conf' | |
echo '[Socket]' > "${script_path}" | |
echo 'ListenStream=' >> "${script_path}" | |
echo 'ListenStream=127.0.0.1:21' >> "${script_path}" | |
echo 'ListenStream=[::1]:21' >> "${script_path}" | |
ln -s '/usr/local/etc/systemd/system/proftpd.socket.d' '/etc/systemd/system/proftpd.socket.d' | |
systemctl start mariadb.socket | |
script_path='/usr/local/etc/systemd/system/mariadb-socket-start.service' | |
echo '[Unit]' > "${script_path}" | |
echo 'Description=this fucking MariaDB socket' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo '[Service]' >> "${script_path}" | |
echo 'Type=oneshot' >> "${script_path}" | |
echo 'ExecStart=systemctl start mariadb.socket' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo '[Install]' >> "${script_path}" | |
echo 'WantedBy=multi-user.target' >> "${script_path}" | |
ln -s '/usr/local/etc/systemd/system/mariadb-socket-start.service' '/etc/systemd/system/mariadb-socket-start.service' | |
systemctl enable mariadb-socket-start.service | |
else | |
script_path='/usr/local/bin/mysql' | |
echo '#!/bin/bash' > "${script_path}" | |
#### | |
echo '_mysql_sock="--socket=/var/run/mysqld/mysqld.sock"' >> "${script_path}" | |
#### | |
echo 'for _i in ${@}; do' >> "${script_path}" | |
echo '[ "${_i}" = "-h" ] && _mysql_sock=""' >> "${script_path}" | |
echo '[ "${_i}" = "-S" ] && _mysql_sock=""' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
#### | |
echo 'echo -n "${@}" | grep "\--host=" > /dev/null 2>&1 && _mysql_sock=""' >> "${script_path}" | |
echo 'echo -n "${@}" | grep "\--socket=" > /dev/null 2>&1 && _mysql_sock=""' >> "${script_path}" | |
#### | |
echo 'exec /usr/bin/${0##*/} ${_mysql_sock} "${@}"' >> "${script_path}" | |
chown 'root:root' "${script_path}" | |
chmod 755 "${script_path}" | |
script_path='/usr/local/etc/mysql/conf.d/build-dev-env_socket-activation.cnf' | |
echo '[client-server]' > "${script_path}" | |
echo 'port=13306' >> "${script_path}" | |
echo 'socket=/run/mysqld/mysqld.sockx' >> "${script_path}" | |
ln -s "${script_path}" '/etc/mysql/conf.d/build-dev-env_socket-activation.cnf' | |
create_socket_activation_unit \ | |
mysql MySQL inet \ | |
'127.0.0.1:3306' \ | |
'127.0.0.1:13306' \ | |
null null null | |
create_socket_activation_unit \ | |
mysql MySQL unix \ | |
'/run/mysqld/mysqld.sock' \ | |
'/run/mysqld/mysqld.sockx' \ | |
mysql mysql 0777 | |
systemctl disable mysql.service | |
fi | |
service mysql stop | |
} | |
install__mysql_overlay() | |
{ | |
local service_started='false' | |
service mysql status > /dev/null 2>&1 && service_started='true' | |
"${service_started}" && service mysql stop | |
_create_mysql_postgresql_overlay \ | |
'/usr/local/sbin/mysql-overlay.sh' \ | |
'MySQL' \ | |
'mysql' \ | |
'mysql-overlay' \ | |
'/var/lib/mysql' \ | |
'mysql' \ | |
'mysql' | |
[ -e '/usr/local/etc/systemd/system/mysql-overlay.service' ] && sed -i \ | |
's/Before=mysql.service/Before=mysql.service\nBefore=mariadb.socket/g' \ | |
'/usr/local/etc/systemd/system/mysql-overlay.service' | |
service mysql-overlay start | |
"${service_started}" && service mysql start | |
} | |
install__postgresql_phppgadmin() | |
{ | |
local script_path | |
install_packages postgresql | |
if grep 'VERSION_CODENAME=bookworm' '/etc/os-release' > /dev/null 2>&1; then | |
echo 'debian bookworm detected' | |
install_packages phppgadmin/bookworm-backports || install_packages phppgadmin | |
else | |
install_packages phppgadmin | |
fi | |
if [ -e '/etc/postgresql' ]; then | |
echo "ALTER USER postgres WITH PASSWORD 'postgres';" | |
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'postgres';" | |
# https://www.postgresql.org/message-id/46a038f90809141756k43f984d7o29b40a0983ff90bf%40mail.gmail.com | |
local cfg_dir_create='true' | |
local i | |
for i in /etc/postgresql/*; do | |
[ "${i}" = '/etc/postgresql/*' ] && break | |
if "${cfg_dir_create}"; then | |
mkdir -p '/usr/local/etc/postgresql' | |
chown 'root:root' '/usr/local/etc/postgresql' | |
chmod -s '/usr/local/etc/postgresql' | |
cfg_dir_create='false' | |
fi | |
mkdir -p "/usr/local/etc/postgresql/${i##*/}/main/conf.d" | |
script_path="/usr/local/etc/postgresql/${i##*/}/main/conf.d/build-dev-env.conf" | |
echo 'max_connections = 45' > "${script_path}" | |
echo 'shared_buffers = 32MB' >> "${script_path}" | |
echo 'temp_buffers = 8MB' >> "${script_path}" | |
echo 'max_prepared_transactions = 5' >> "${script_path}" | |
echo 'work_mem = 2MB' >> "${script_path}" | |
echo 'maintenance_work_mem = 16MB' >> "${script_path}" | |
echo 'max_stack_depth = 2MB' >> "${script_path}" | |
echo 'wal_buffers = 1MB' >> "${script_path}" | |
echo 'wal_writer_delay = 1000ms' >> "${script_path}" | |
ln -s "${script_path}" "${i}/main/conf.d/build-dev-env.conf" | |
done | |
fi | |
if [ -e '/etc/phppgadmin' ]; then | |
mkdir -p '/usr/local/etc/phppgadmin' | |
chown 'root:root' '/usr/local/etc/phppgadmin' | |
chmod -s '/usr/local/etc/phppgadmin' | |
cp -p '/etc/phppgadmin/config.inc.php' '/etc/phppgadmin/config.inc.php.old' | |
mv '/etc/phppgadmin/config.inc.php' '/usr/local/etc/phppgadmin/config.inc.php' | |
ln -s '/usr/local/etc/phppgadmin/config.inc.php' '/etc/phppgadmin/config.inc.php' | |
sed -i 's/$conf['"'"'extra_login_security'"'"'] = true;/$conf['"'"'extra_login_security'"'"'] = false;/g' '/usr/local/etc/phppgadmin/config.inc.php' | |
sed -i "s/$conf\['extra_login_security'\] = true;/$conf\['extra_login_security'\] = false;/" '/usr/local/etc/phppgadmin/config.inc.php' | |
[ -e '/var/www/html' ] && ln -s '/usr/share/phppgadmin' '/var/www/html/phppgadmin' | |
create_shortcut 'phppgadmin.desktop' \ | |
'link' \ | |
'phpPgAdmin' \ | |
'http://localhost/phppgadmin' \ | |
'internet-web-browser' | |
fi | |
local service_started='false' | |
service postgresql status > /dev/null 2>&1 && service_started='true' | |
"${service_started}" && service postgresql stop | |
rm -r '/var/log/postgresql' | |
ln -s '/var/run/postgresql' '/var/log/postgresql' | |
"${service_started}" && service postgresql start | |
if [ -d '/etc/systemd/system' ] && command -v 'systemctl' > /dev/null 2>&1; then | |
script_path='/usr/local/bin/psql' | |
echo '#!/bin/sh' > "${script_path}" | |
#### | |
echo 'if [ "${1}" = "__systemd_prepare__" ]; then' >> "${script_path}" | |
echo 'for i in /etc/postgresql/*; do' >> "${script_path}" | |
echo '[ "${i}" = "/etc/postgresql/*" ] && break' >> "${script_path}" | |
echo '[ ! -e "${i}/main/pg_hba.conf" ] && continue' >> "${script_path}" | |
echo '[ -e "/var/run/.postgresql-${i##*/}-hba-patch.conf" ] && continue' >> "${script_path}" | |
#### | |
echo 'sed -E "s/local([[:space:]]+)all([[:space:]]+)postgres([[:space:]]+)peer/local\1all\2postgres\3md5/" "${i}/main/pg_hba.conf" > "/var/run/.postgresql-${i##*/}-hba-patch.conf"' >> "${script_path}" | |
echo 'mount --bind "/var/run/.postgresql-${i##*/}-hba-patch.conf" "${i}/main/pg_hba.conf"' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
#### | |
echo 'exit 0' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo '_psql_host="--host=/var/run/postgresql"' >> "${script_path}" | |
echo '_psql_port="--port=5432"' >> "${script_path}" | |
#### | |
echo 'for _i in ${@}; do' >> "${script_path}" | |
echo '[ "${_i}" = "-h" ] && _psql_host=""' >> "${script_path}" | |
echo '[ "${_i}" = "-p" ] && _psql_port=""' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
#### | |
echo 'echo -n "${@}" | grep "\--host=" > /dev/null 2>&1 && _psql_host=""' >> "${script_path}" | |
echo 'echo -n "${@}" | grep "\--port=" > /dev/null 2>&1 && _psql_port=""' >> "${script_path}" | |
#### | |
echo 'exec /usr/bin/${0##*/} ${_psql_host} ${_psql_port} ${@}' >> "${script_path}" | |
chown 'root:root' "${script_path}" | |
chmod 755 "${script_path}" | |
ln -s "${script_path##*/}" '/usr/local/bin/createdb' | |
for i in /etc/postgresql/*; do | |
[ "${i}" = '/etc/postgresql/*' ] && break | |
script_path="/usr/local/etc/postgresql/${i##*/}/main/conf.d/build-dev-env_socket-activation.conf" | |
echo "unix_socket_directories = '/var/run/postgresql/sock'" > "${script_path}" | |
echo "port = 15432" >> "${script_path}" | |
ln -s "${script_path}" "${i}/main/conf.d/build-dev-env_socket-activation.conf" | |
done | |
create_socket_activation_unit \ | |
postgresql PostgreSQL inet \ | |
'127.0.0.1:5432' \ | |
'127.0.0.1:15432' \ | |
null null null | |
create_socket_activation_unit \ | |
postgresql PostgreSQL unix \ | |
'/run/postgresql/.s.PGSQL.5432' \ | |
'/run/postgresql/sock/.s.PGSQL.15432' \ | |
postgres postgres 0777 | |
systemctl disable postgresql.service | |
script_path='/usr/local/etc/systemd/system/socket-proxyd_postgresql_helper.service' | |
echo '[Unit]' > "${script_path}" | |
echo 'Description=PostgreSQL pg_hba.conf patch for socket activation' >> "${script_path}" | |
echo 'Before=postgresql.service' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo '[Service]' >> "${script_path}" | |
echo 'Type=oneshot' >> "${script_path}" | |
echo 'ExecStart=/usr/local/bin/psql __systemd_prepare__' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo '[Install]' >> "${script_path}" | |
echo 'WantedBy=multi-user.target' >> "${script_path}" | |
ln -s "${script_path}" '/etc/systemd/system/socket-proxyd_postgresql_helper.service' | |
systemctl enable 'socket-proxyd_postgresql_helper.service' | |
fi | |
service postgresql stop | |
} | |
install__postgresql_overlay() | |
{ | |
local service_started='false' | |
service postgresql status > /dev/null 2>&1 && service_started='true' | |
"${service_started}" && service postgresql stop | |
_create_mysql_postgresql_overlay \ | |
'/usr/local/sbin/postgresql-overlay.sh' \ | |
'PostgreSQL' \ | |
'postgresql' \ | |
'postgresql-overlay' \ | |
'/var/lib/postgresql' \ | |
'postgres' \ | |
'postgres' | |
service postgresql-overlay start | |
"${service_started}" && service postgresql start | |
} | |
install__redis_phpredisadmin() | |
{ | |
local i | |
local y | |
### redis | |
install_packages redis-server redis-tools | |
if [ -e '/etc/redis' ]; then | |
mkdir -p '/usr/local/etc/redis' | |
chown 'root:root' '/usr/local/etc/redis' | |
chmod -s '/usr/local/etc/redis' | |
cp -p '/etc/redis/redis.conf' '/etc/redis/redis.conf.old' | |
mv '/etc/redis/redis.conf' '/usr/local/etc/redis/redis.conf' | |
ln -s '/usr/local/etc/redis/redis.conf' '/etc/redis/redis.conf' | |
echo '' >> '/usr/local/etc/redis/redis.conf' | |
echo 'save ""' > '/usr/local/etc/redis/no-save.conf' | |
echo 'include /usr/local/etc/redis/no-save.conf' >> '/usr/local/etc/redis/redis.conf' | |
echo 'unixsocket /var/run/redis/redis.sock' > '/usr/local/etc/redis/unix-socket.conf' | |
echo 'unixsocketperm 777' >> '/usr/local/etc/redis/unix-socket.conf' | |
echo 'include /usr/local/etc/redis/unix-socket.conf' >> '/usr/local/etc/redis/redis.conf' | |
local service_started='false' | |
service redis status > /dev/null 2>&1 && service_started='true' | |
"${service_started}" && service redis stop | |
rm -r '/var/log/redis' | |
ln -s '/var/run/redis' '/var/log/redis' | |
"${service_started}" && service redis start | |
fi | |
### phpredisadmin | |
local current_dir=$(pwd) | |
install_packages ca-certificates git | |
mkdir '/usr/local/share/phpredisadmin' | |
chown 'root:root' '/usr/local/share/phpredisadmin' | |
chmod -s '/usr/local/share/phpredisadmin' | |
cd '/usr/local/share/phpredisadmin' | |
for i in 1 2 3; do | |
if git clone 'https://github.com/erikdubbelboer/phpRedisAdmin.git' .; then | |
for y in 1 2 3; do | |
git clone 'https://github.com/nrk/predis.git' './vendor' && break | |
done | |
ln -s 'config.sample.inc.php' './includes/config.inc.php' | |
rm -r -f './.git'; rm -r './.github'; rm './.gitignore' | |
rm \ | |
'./Dockerfile' \ | |
'./README.markdown' \ | |
'./SECURITY.md' \ | |
'./composer.json' \ | |
'./composer.lock' \ | |
'./docker-compose.yml' | |
rm -r -f './vendor/.git'; rm -r './vendor/.github'; rm './vendor/.gitattributes' './vendor/.gitignore' | |
rm -r \ | |
'./vendor/bin' \ | |
'./vendor/examples' \ | |
'./vendor/tests' | |
rm \ | |
'./vendor/.codespellrc' \ | |
'./vendor/.coveralls.yml' \ | |
'./vendor/.editorconfig' \ | |
'./vendor/.php-cs-fixer.dist.php' \ | |
'./vendor/CHANGELOG.md' \ | |
'./vendor/FAQ.md' \ | |
'./vendor/LICENSE' \ | |
'./vendor/README.md' \ | |
'./vendor/VERSION' \ | |
'./vendor/composer.json' \ | |
'./vendor/phpstan-tests.dist.neon' \ | |
'./vendor/phpstan.dist.neon' \ | |
'./vendor/phpunit.relay.xml' \ | |
'./vendor/phpunit.xml.dist' | |
if [ ! -e '/usr/local/etc/apache2' ]; then | |
mkdir -p '/usr/local/etc/apache2' | |
chown 'root:root' '/usr/local/etc/apache2' | |
chmod -s '/usr/local/etc/apache2' | |
fi | |
[ ! -e '/usr/local/etc/apache2/conf-available' ] && mkdir '/usr/local/etc/apache2/conf-available' | |
local script_path='/usr/local/etc/apache2/conf-available/phpredisadmin.conf' | |
echo 'Alias /phpredisadmin /usr/local/share/phpredisadmin' > "${script_path}" | |
#### | |
echo '<Directory /usr/local/share/phpredisadmin>' >> "${script_path}" | |
echo '<IfModule mod_dir.c>' >> "${script_path}" | |
echo 'DirectoryIndex index.php' >> "${script_path}" | |
echo '</IfModule>' >> "${script_path}" | |
#### | |
echo 'AllowOverride None' >> "${script_path}" | |
echo 'Require local' >> "${script_path}" | |
echo '</Directory>' >> "${script_path}" | |
if [ -e '/etc/apache2/conf-available' ]; then | |
ln -s '/usr/local/etc/apache2/conf-available/phpredisadmin.conf' '/etc/apache2/conf-available/phpredisadmin.conf' | |
a2enconf phpredisadmin | |
service apache2 status > /dev/null 2>&1 && service apache2 restart | |
fi | |
[ -e '/var/www/html' ] && ln -s '/usr/local/share/phpredisadmin' '/var/www/html/phpredisadmin' | |
create_shortcut 'phpredisadmin.desktop' \ | |
'link' \ | |
'phpRedisAdmin' \ | |
'http://localhost/phpredisadmin' \ | |
'internet-web-browser' | |
break | |
else | |
cd "${current_dir}" | |
rmdir '/usr/local/share/phpredisadmin' | |
fi | |
done | |
cd "${current_dir}" | |
### systemd socket activation | |
if [ -d '/etc/systemd/system' ] && command -v 'systemctl' > /dev/null 2>&1; then | |
echo 'unixsocket /var/run/redis/redis.sockx' > '/usr/local/etc/redis/socket-activation.conf' | |
echo 'port 16379' > '/usr/local/etc/redis/socket-activation.conf' | |
echo 'include /usr/local/etc/redis/socket-activation.conf' >> '/usr/local/etc/redis/redis.conf' | |
create_socket_activation_unit \ | |
redis-server Redis inet \ | |
'127.0.0.1:6379' \ | |
'127.0.0.1:16379' \ | |
null null null | |
create_socket_activation_unit \ | |
redis-server Redis unix \ | |
'/run/redis/redis.sock' \ | |
'/run/redis/redis.sockx' \ | |
redis redis 0777 | |
systemctl disable redis-server.service | |
fi | |
service redis-server stop | |
} | |
install__redis_gui() | |
{ | |
install_packages wget ca-certificates | |
[ -e '/sbin/mount.fuse3' ] || install_packages fuse | |
install_packages libnss3 libasound2 | |
local script_path='/usr/local/bin/redis-gui-update.sh' | |
echo '#!/bin/sh' > "${script_path}" | |
#### | |
echo 'if [ ! "$(whoami)" = "root" ]; then' >> "${script_path}" | |
echo 'echo "No superuser"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'version=$(wget -O- -q "https://api.github.com/repos/ekvedaras/redis-gui/releases/latest" | grep -oP "(?<=\"name\": \")[^\"]*" | grep ".AppImage\$")' >> "${script_path}" | |
echo 'version="${version##*-}"' >> "${script_path}" | |
echo 'version="${version%.*}"' >> "${script_path}" | |
echo 'filename="redis-gui-${version}.AppImage"' >> "${script_path}" | |
#### | |
echo 'if [ "${version}" = "" ]; then' >> "${script_path}" | |
echo 'echo "Release info download error"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if [ -e "/usr/local/bin/${filename}" ]; then' >> "${script_path}" | |
echo 'echo "Release ${release} already installed"' >> "${script_path}" | |
echo 'exit 0' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if wget -O "/usr/local/bin/${filename}" "https://github.com/ekvedaras/redis-gui/releases/download/v""${version}""/""${filename}"; then' >> "${script_path}" | |
echo 'chown "root:root" "/usr/local/bin/${filename}"' >> "${script_path}" | |
echo 'chmod 755 "/usr/local/bin/${filename}"' >> "${script_path}" | |
#### | |
echo '[ -e "/usr/local/bin/redis-gui" ] && rm "/usr/local/bin/redis-gui"' >> "${script_path}" | |
echo 'ln -s "./${filename}" "/usr/local/bin/redis-gui"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'exit 0' >> "${script_path}" | |
chown 'root:root' "${script_path}" | |
chmod 755 "${script_path}" | |
local i | |
for i in 1 2 3; do | |
"${script_path}" && break | |
done | |
if [ -e '/usr/local/bin/redis-gui' ]; then | |
local temp_dir=$(mktemp -d) | |
local current_dir=$(pwd) | |
cd "${temp_dir}" | |
redis-gui --appimage-extract 'redis-gui.png' | |
[ -L './squashfs-root/redis-gui.png' ] && \ | |
redis-gui --appimage-extract "$(readlink './squashfs-root/redis-gui.png')" | |
cd "${current_dir}" | |
if [ ! -e '/usr/local/share/icons' ]; then | |
mkdir -p '/usr/local/share/icons' | |
chown 'root:root' '/usr/local/share/icons' | |
chmod -s '/usr/local/share/icons' | |
fi | |
cp "$(readlink -f "${temp_dir}/squashfs-root/redis-gui.png")" '/usr/local/share/icons/redis-gui.png' | |
chown 'root:root' '/usr/local/share/icons/redis-gui.png' | |
chmod 644 '/usr/local/share/icons/redis-gui.png' | |
if [ ! -e '/usr/local/share/applications' ]; then | |
mkdir -p '/usr/local/share/applications' | |
chown 'root:root' '/usr/local/share/applications' | |
chmod -s '/usr/local/share/applications' | |
fi | |
create_shortcut 'redis-gui.desktop' \ | |
'application' \ | |
'Redis GUI' \ | |
'redis-gui' \ | |
'redis-gui' | |
rm -r -f "${temp_dir}" | |
else | |
echo ' -> redis-gui install failed' | |
rm "${script_path}" | |
fi | |
} | |
install__sqlite3() { install_packages sqlite3; } | |
install__inloop_sqlite_viewer() | |
{ | |
local current_dir=$(pwd) | |
install_packages ca-certificates git | |
mkdir '/usr/local/share/inloop-sqlite-viewer' | |
chown 'root:root' '/usr/local/share/inloop-sqlite-viewer' | |
chmod -s '/usr/local/share/inloop-sqlite-viewer' | |
cd '/usr/local/share/inloop-sqlite-viewer' | |
local i | |
for i in 1 2 3; do | |
if git clone 'https://github.com/inloop/sqlite-viewer.git' .; then | |
rm -r './examples' | |
rm -r -f './.git'; rm './.gitignore' | |
rm './README.md'; rm './img/preview.png' | |
rm './css/ribbons.min.css' # remove fonts.googleapis.com call | |
sed -i 's/www.google-analytics.com/localhost:0/g' './index.html' | |
sed -i '/id="sample-db-link"/d' './index.html' | |
create_shortcut 'inloop-sqlite-viewer.desktop' \ | |
'link' \ | |
'SQLite Viewer' \ | |
'/usr/local/share/inloop-sqlite-viewer/index.html' \ | |
'/usr/local/share/inloop-sqlite-viewer/img/icon.png' | |
break | |
else | |
cd "${current_dir}" | |
rmdir '/usr/local/share/inloop-sqlite-viewer' | |
fi | |
done | |
cd "${current_dir}" | |
} | |
install__joebeach_json_path_finder() | |
{ | |
local current_dir=$(pwd) | |
local line | |
local file | |
local i | |
install_packages ca-certificates git | |
mkdir '/usr/local/share/joebeach-json-path-finder' | |
chown 'root:root' '/usr/local/share/joebeach-json-path-finder' | |
chmod -s '/usr/local/share/joebeach-json-path-finder' | |
cd '/usr/local/share/joebeach-json-path-finder' | |
for i in 1 2 3; do | |
if git clone 'https://github.com/joebeachjoebeach/json-path-finder.git' .; then | |
rm './.eslintrc.json' | |
rm -r -f './.git'; rm './.gitignore' | |
rm './CNAME' | |
rm './README.md' | |
sed -i 's/fonts.googleapis.com/localhost:0/g' './index.html' | |
mkdir './cdn' | |
cat './index.html' | \ | |
grep '<link ' | \ | |
grep -io 'href=['"'"'"][^"'"'"']*['"'"'"]' | \ | |
sed -e 's/^href=["'"'"']//i' -e 's/["'"'"']$//i' | \ | |
grep '^http.*://' | \ | |
grep -v '://localhost:0' | \ | |
while read line; do | |
# css | |
file="./cdn/${line##*/}" | |
for i in 1 2 3; do | |
wget -O "${file}" "${line}" && break || rm "${file}" | |
done | |
sed -i "s\\${line}\\${file}\\g" './index.html' | |
done | |
cat './index.html' | \ | |
grep -io 'src=['"'"'"][^"'"'"']*['"'"'"]' | \ | |
sed -e 's/^src=["'"'"']//i' -e 's/["'"'"']$//i' | \ | |
grep '^http.*://' | \ | |
grep -v '://localhost:0' | \ | |
while read line; do | |
# js | |
file="./cdn/${line##*/}" | |
for i in 1 2 3; do | |
wget -O "${file}" "${line}" && break || rm "${file}" | |
done | |
sed -i "s\\${line}\\${file}\\g" './index.html' | |
done | |
create_shortcut 'joebeach-json-path-finder.desktop' \ | |
'link' \ | |
'JSON Path Finder' \ | |
'/usr/local/share/joebeach-json-path-finder/index.html' \ | |
'text-x-generic' | |
break | |
else | |
cd "${current_dir}" | |
rmdir '/usr/local/share/joebeach-json-path-finder' | |
fi | |
done | |
cd "${current_dir}" | |
} | |
### Debian tools | |
install__nonfree_repo() | |
{ | |
if [ -e '/etc/apt/sources.list.d/build-dev-env-nonfree.list' ]; then | |
echo 'Already installed' | |
return 0 | |
fi | |
local debian_vendor=$(cat '/etc/os-release' | grep '^NAME=') | |
debian_vendor="$(echo -n ${debian_vendor##*=} | tr -d \")" | |
local debian_version=$(cat '/etc/os-release' | grep '^VERSION_CODENAME=') | |
debian_version="${debian_version##*=}" | |
if [ "${debian_vendor}" = '' ]; then | |
echo "debian vendor not found" | |
return 1 | |
fi | |
if [ "${debian_version}" = '' ]; then | |
echo "debian version not found" | |
return 1 | |
fi | |
case "${debian_vendor}" in | |
'Debian GNU/Linux') | |
local source='http://ftp.debian.org/debian' | |
local section='non-free' | |
;; | |
'Ubuntu') | |
local source='http://archive.ubuntu.com/ubuntu' | |
local section='multiverse' | |
;; | |
*) | |
echo "Unknown vendor ${debian_vendor}" | |
return 1 | |
;; | |
esac | |
echo "Vendor: ${debian_vendor}" | |
echo "Version: ${debian_version}" | |
echo "Source: ${source}" | |
echo "Section: ${section}" | |
local i | |
for i in /etc/apt/sources.list /etc/apt/sources.list.d/*; do | |
[ ! -e "${i}" ] && continue | |
[ "${i}" = '/etc/apt/sources.list.d/*' ] && continue | |
if cat "${i}" | grep "${source}" | grep "${section}" > /dev/null 2>&1; then | |
echo "${section} section found for ${source}" | |
return 1 | |
fi | |
done | |
mkdir -p '/usr/local/etc/apt/sources.list.d' | |
chown -R 'root:root' '/usr/local/etc/apt' | |
chmod -s '/usr/local/etc/apt/sources.list.d' | |
chmod -s '/usr/local/etc/apt' | |
echo "deb ${source} ${debian_version} ${section}" > '/usr/local/etc/apt/sources.list.d/build-dev-env-nonfree.list' | |
ln -s '/usr/local/etc/apt/sources.list.d/build-dev-env-nonfree.list' '/etc/apt/sources.list.d/build-dev-env-nonfree.list' | |
_apt_updated='false' | |
} | |
install__universe_repo() | |
{ | |
if [ -e '/etc/apt/sources.list.d/build-dev-env-universe.list' ]; then | |
echo 'Already installed' | |
return 0 | |
fi | |
local debian_vendor=$(cat '/etc/os-release' | grep '^NAME=') | |
debian_vendor="$(echo -n ${debian_vendor##*=} | tr -d \")" | |
local debian_version=$(cat '/etc/os-release' | grep '^VERSION_CODENAME=') | |
debian_version="${debian_version##*=}" | |
if [ ! "${debian_vendor}" = 'Ubuntu' ]; then | |
echo 'This is not ubuntu' | |
return 1 | |
fi | |
if [ "${debian_version}" = '' ]; then | |
echo 'debian version not found' | |
return 1 | |
fi | |
local source='http://archive.ubuntu.com/ubuntu' | |
local section='universe' | |
local i | |
for i in /etc/apt/sources.list /etc/apt/sources.list.d/*; do | |
[ ! -e "${i}" ] && continue | |
[ "${i}" = '/etc/apt/sources.list.d/*' ] && continue | |
if cat "${i}" | grep "${source}" | grep "${section}" > /dev/null 2>&1; then | |
echo "${section} section found for ${source}" | |
return 1 | |
fi | |
done | |
mkdir -p '/usr/local/etc/apt/sources.list.d' | |
chown -R 'root:root' '/usr/local/etc/apt' | |
chmod -s '/usr/local/etc/apt/sources.list.d' | |
chmod -s '/usr/local/etc/apt' | |
echo "deb ${source} ${debian_version} ${section}" > '/usr/local/etc/apt/sources.list.d/build-dev-env-universe.list' | |
ln -s '/usr/local/etc/apt/sources.list.d/build-dev-env-universe.list' '/etc/apt/sources.list.d/build-dev-env-universe.list' | |
_apt_updated='false' | |
} | |
_add_debian_backports_repo() | |
{ | |
if [ -e '/etc/apt/sources.list.d/build-dev-env-backports.list' ]; then | |
echo 'Already installed' | |
return 0 | |
fi | |
local debian_version=$(cat '/etc/os-release' | grep '^VERSION_CODENAME=') | |
debian_version="${debian_version##*=}" | |
local source='http://ftp.debian.org/debian' | |
if [ "${debian_version}" = '' ]; then | |
echo 'debian version not found' | |
return 1 | |
fi | |
if [ ! "${debian_version}" = "${1}" ]; then | |
echo "This is not ${1}" | |
return 1 | |
fi | |
local i | |
for i in /etc/apt/sources.list /etc/apt/sources.list.d/*; do | |
[ ! -e "${i}" ] && continue | |
[ "${i}" = '/etc/apt/sources.list.d/*' ] && continue | |
if cat "${i}" | grep "${source}" | grep "${1}-backports" > /dev/null 2>&1; then | |
echo "${1}-backports found for ${source}" | |
return 1 | |
fi | |
done | |
mkdir -p '/usr/local/etc/apt/sources.list.d' | |
chown -R 'root:root' '/usr/local/etc/apt' | |
chmod -s '/usr/local/etc/apt/sources.list.d' | |
chmod -s '/usr/local/etc/apt' | |
echo "deb ${source} ${1}-backports main contrib non-free" > '/usr/local/etc/apt/sources.list.d/build-dev-env-backports.list' | |
ln -s '/usr/local/etc/apt/sources.list.d/build-dev-env-backports.list' '/etc/apt/sources.list.d/build-dev-env-backports.list' | |
_apt_updated='false' | |
} | |
install__buster_backports_repo() { _add_debian_backports_repo buster; } | |
install__bookworm_backports_repo() { _add_debian_backports_repo bookworm; } | |
install__rclocal_message() | |
{ | |
if [ -L '/usr/local/etc/rc.local' ]; then | |
mv '/usr/local/etc/rc.local' '/usr/local/etc/rc.local.old' | |
echo '#!/bin/sh' > '/usr/local/etc/rc.local' | |
echo 'exit 0' >> '/usr/local/etc/rc.local' | |
chown 'root:root' '/usr/local/etc/rc.local' | |
chmod 755 '/usr/local/etc/rc.local' | |
chmod -s '/usr/local/etc/rc.local' | |
fi | |
if [ -L '/etc/rc.local' ]; then | |
if [ ! "$(readlink -f /etc/rc.local)" = '/usr/local/etc/rc.local' ]; then | |
mv '/etc/rc.local' '/etc/rc.local.old' | |
cat '/etc/rc.local.old' > '/etc/rc.local' | |
chmod 755 '/etc/rc.local' | |
mv '/etc/rc.local' '/usr/local/etc/rc.local' | |
ln -s '/usr/local/etc/rc.local' '/etc/rc.local' | |
fi | |
elif [ -e '/etc/rc.local' ]; then | |
cp -p '/etc/rc.local' '/etc/rc.local.old' | |
mv '/etc/rc.local' '/usr/local/etc/rc.local' | |
ln -s '/usr/local/etc/rc.local' '/etc/rc.local' | |
else | |
echo '#!/bin/sh' > '/etc/rc.local' | |
echo 'exit 0' >> '/etc/rc.local' | |
chmod 755 '/etc/rc.local' | |
fi | |
sed -i 's/exit 0//g' '/usr/local/etc/rc.local' | |
echo -n 'if [ -e "/dev/ttyS0" ]; then ' >> '/usr/local/etc/rc.local' | |
echo -n 'echo "" > /dev/ttyS0;' >> '/usr/local/etc/rc.local' | |
echo -n 'echo "" > /dev/ttyS0;' >> '/usr/local/etc/rc.local' | |
echo -n 'echo " ==> System is ready" > /dev/ttyS0;' >> '/usr/local/etc/rc.local' | |
echo -n 'echo "" > /dev/ttyS0;' >> '/usr/local/etc/rc.local' | |
echo 'fi' >> '/usr/local/etc/rc.local' | |
echo 'exit 0' >> '/usr/local/etc/rc.local' | |
} | |
install__dpkg_dev() { install_packages dpkg-dev; } | |
install__debootstrap() { install_packages debootstrap; } | |
install__ethtool() { install_packages ethtool; } | |
install__evince() { install_packages evince; } | |
install__fdisk_gdisk() { install_packages fdisk gdisk; } | |
install__gparted() | |
{ | |
install_packages gparted \ | |
dosfstools mtools \ | |
e2fsprogs \ | |
jfsutils \ | |
ntfs-3g \ | |
reiser4progs reiserfsprogs \ | |
xfsprogs xfsdump \ | |
btrfs-progs \ | |
exfat-utils exfatprogs \ | |
f2fs-tools \ | |
hfsutils hfsprogs \ | |
cryptsetup dmsetup \ | |
lvm2 \ | |
nilfs-tools \ | |
udftools | |
if [ -e '/usr/bin/lxqt-sudo' ] && [ ! -e '/usr/local/share/applications/gparted.desktop' ]; then | |
if [ ! -e '/usr/local/share/applications' ]; then | |
mkdir -p '/usr/local/share/applications' | |
chown 'root:root' '/usr/local/share/applications' | |
chmod -s '/usr/local/share/applications' | |
fi | |
cp -p '/usr/share/applications/gparted.desktop' '/usr/local/share/applications/gparted.desktop' | |
sed -i 's/Exec=/Exec=lxqt-sudo sudo /g' '/usr/local/share/applications/gparted.desktop' | |
fi | |
} | |
install__htop() { install_packages htop; } | |
install__icewm_devtools_menu() | |
{ | |
if [ -e '/usr/share/icewm/menu' ]; then | |
local script_path='/usr/local/bin/icewm-menu-devtools.sh' | |
echo '#!/bin/sh' > "${script_path}" | |
#### | |
echo 'username=$(whoami)' >> "${script_path}" | |
echo 'first_item="true"' >> "${script_path}" | |
#### | |
echo 'if [ -e "/tmp/.icewm-dev-menu-${username}" ]; then' >> "${script_path}" | |
echo 'while IFS= read -r line; do' >> "${script_path}" | |
echo 'echo "${line}"' >> "${script_path}" | |
echo 'done < "/tmp/.icewm-dev-menu-${username}"' >> "${script_path}" | |
#### | |
echo 'exit 0' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'find_icon()' >> "${script_path}" | |
echo '{' >> "${script_path}" | |
echo 'if echo -n "${icon}" | grep "^/" > /dev/null 2>&1; then' >> "${script_path}" | |
echo 'echo -n "${icon}"' >> "${script_path}" | |
echo 'return' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'local i # /usr/share/icons/ICONTHEME' >> "${script_path}" | |
echo 'local y # ${i}/ICONSIZE/ICONGROUP' >> "${script_path}" | |
#### | |
echo 'for i in ${HOME}/.icons/* /usr/local/share/icons/* /usr/share/icons/Tango /usr/share/icons/*; do' >> "${script_path}" | |
echo '[ "${i}" = "${HOME}/.icons/*" ] && continue' >> "${script_path}" | |
echo '[ "${i}" = "/usr/local/share/icons/*" ] && continue' >> "${script_path}" | |
echo '[ "${i}" = "/usr/share/icons/Tango" ] && [ ! -e "/usr/share/icons/Tango" ] && continue' >> "${script_path}" | |
echo '[ "${i}" = "/usr/share/icons/*" ] && continue' >> "${script_path}" | |
#### | |
echo 'for y in ${i}/48x48/* ${i}/32x32/*; do' >> "${script_path}" | |
echo '[ "${y}" = "${i}/48x48/*" ] && continue' >> "${script_path}" | |
echo '[ "${y}" = "${i}/32x32/*" ] && continue' >> "${script_path}" | |
#### | |
echo 'if [ -e "${y}/${1}.png" ]; then' >> "${script_path}" | |
echo 'echo -n "${y}/${1}.png"' >> "${script_path}" | |
echo 'return' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
#### | |
echo 'echo -n "${1}"' >> "${script_path}" | |
echo '}' >> "${script_path}" | |
#### | |
echo 'echo -n "" > "/tmp/.icewm-dev-menu-${username}"' >> "${script_path}" | |
#### | |
echo 'for i in /usr/local/share/dev-tools-menu/share/applications/*.desktop; do' >> "${script_path}" | |
echo '[ "${i}" = "/usr/local/share/dev-tools-menu/share/applications/*.desktop" ] && break' >> "${script_path}" | |
#### | |
echo 'if "${first_item}"; then' >> "${script_path}" | |
echo '[ "${1}" = "--debug" ] && echo "menu \"Dev Tools\" \"$(find_icon applications-system)\" {"' >> "${script_path}" | |
echo 'echo "menu \"Dev Tools\" \"$(find_icon applications-system)\" {" >> "/tmp/.icewm-dev-menu-${username}"' >> "${script_path}" | |
echo 'first_item="false"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo '[ "${1}" = "--debug" ] && echo "# ${i##*/}"' >> "${script_path}" | |
#### | |
echo 'app_type=""' >> "${script_path}" | |
echo 'app_name=""' >> "${script_path}" | |
echo 'app_exec=""' >> "${script_path}" | |
echo 'app_icon=""' >> "${script_path}" | |
echo 'app_terminal=""' >> "${script_path}" | |
echo 'app_url=""' >> "${script_path}" | |
echo 'first_line="true"' >> "${script_path}" | |
#### | |
echo 'while IFS= read -r line; do' >> "${script_path}" | |
echo '"${first_line}" && first_line="false" && continue' >> "${script_path}" | |
#### | |
echo 'case "${line%%=*}" in' >> "${script_path}" | |
echo '"Type")' >> "${script_path}" | |
echo 'app_type=${line#*=}' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo '"Name")' >> "${script_path}" | |
echo 'app_name=${line#*=}' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo '"Exec")' >> "${script_path}" | |
echo 'app_exec=${line#*=}' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo '"Icon")' >> "${script_path}" | |
echo 'app_icon=${line#*=}' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo '"Terminal")' >> "${script_path}" | |
echo 'app_terminal=${line#*=}' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo '"URL")' >> "${script_path}" | |
echo 'app_url=${line#*=}' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo 'esac' >> "${script_path}" | |
echo 'done < "${i}"' >> "${script_path}" | |
#### | |
echo 'if [ "${app_type}" = "Link" ]; then' >> "${script_path}" | |
echo 'app_exec="/usr/bin/sensible-browser ${app_url}"' >> "${script_path}" | |
echo 'elif [ "${app_terminal}" = "true" ]; then' >> "${script_path}" | |
echo 'app_exec="/usr/bin/x-terminal-emulator -e \"${app_exec}\""' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'app_icon="\"$(find_icon ${app_icon})\""' >> "${script_path}" | |
#### | |
echo '[ "${1}" = "--debug" ] && echo "prog \"${app_name}\" ${app_icon} ${app_exec}"' >> "${script_path}" | |
echo 'echo "prog \"${app_name}\" ${app_icon} ${app_exec}" >> "/tmp/.icewm-dev-menu-${username}"' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
#### | |
echo 'if ! "${first_item}"; then' >> "${script_path}" | |
echo '[ "${1}" = "--debug" ] && echo "}"' >> "${script_path}" | |
echo 'echo "}" >> "/tmp/.icewm-dev-menu-${username}"' >> "${script_path}" | |
#### | |
echo 'cat "/tmp/.icewm-dev-menu-${username}" | head -n 1 > "/tmp/.icewm-dev-menu-${username}-sort"' >> "${script_path}" | |
echo 'cat "/tmp/.icewm-dev-menu-${username}" | tail -n +2 | head -n -1 | sort >> "/tmp/.icewm-dev-menu-${username}-sort"' >> "${script_path}" | |
echo 'echo "}" >> "/tmp/.icewm-dev-menu-${username}-sort"' >> "${script_path}" | |
echo 'rm "/tmp/.icewm-dev-menu-${username}"' >> "${script_path}" | |
echo 'mv "/tmp/.icewm-dev-menu-${username}-sort" "/tmp/.icewm-dev-menu-${username}"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo '[ ! "${1}" = "--debug" ] && exec "${0}"' >> "${script_path}" | |
#### | |
echo 'exit 0' >> "${script_path}" | |
chown 'root:root' "${script_path}" | |
chmod 755 "${script_path}" | |
if [ ! -e '/usr/local/etc/X11' ]; then | |
mkdir -p '/usr/local/etc/X11' | |
chown 'root:root' '/usr/local/etc/X11' | |
chmod -s '/usr/local/etc/X11' | |
fi | |
mkdir '/usr/local/etc/X11/icewm' | |
cp '/usr/share/icewm/menu' '/usr/local/etc/X11/icewm/menu' | |
mkdir -p '/etc/X11/icewm' | |
ln -s '/usr/local/etc/X11/icewm/menu' '/etc/X11/icewm/menu' | |
echo '' >> '/usr/local/etc/X11/icewm/menu' | |
echo "includeprog ${script_path##*/}" >> '/usr/local/etc/X11/icewm/menu' | |
else | |
echo 'IceWM is not installed' | |
fi | |
} | |
install__lxqt_sudo() | |
{ | |
install_packages lxqt-sudo lxqt-sudo-l10n | |
if [ -e '/usr/bin/thunar' ]; then | |
mkdir -p "${HOME}/.config/Thunar" | |
local script_path="${HOME}/.config/Thunar/uca.xml" | |
echo '<?xml version="1.0" encoding="UTF-8"?>' > "${script_path}" | |
echo '<actions>' >> "${script_path}" | |
echo '<action>' >> "${script_path}" | |
echo '<icon>utilities-terminal</icon>' >> "${script_path}" | |
echo '<name>Open Terminal Here</name>' >> "${script_path}" | |
echo '<unique-id>1677522026733363-1</unique-id>' >> "${script_path}" | |
echo '<command>x-terminal-emulator</command>' >> "${script_path}" | |
echo '<description></description>' >> "${script_path}" | |
echo '<patterns>*</patterns>' >> "${script_path}" | |
echo '<startup-notify/>' >> "${script_path}" | |
echo '<directories/>' >> "${script_path}" | |
echo '</action>' >> "${script_path}" | |
echo '<action>' >> "${script_path}" | |
echo '<icon>utilities-terminal</icon>' >> "${script_path}" | |
echo '<name>Open Root Terminal Here</name>' >> "${script_path}" | |
echo '<unique-id>1677522376149564-1</unique-id>' >> "${script_path}" | |
echo '<command>lxqt-sudo x-terminal-emulator</command>' >> "${script_path}" | |
echo '<description></description>' >> "${script_path}" | |
echo '<patterns>*</patterns>' >> "${script_path}" | |
echo '<directories/>' >> "${script_path}" | |
echo '</action>' >> "${script_path}" | |
echo '<action>' >> "${script_path}" | |
echo '<icon>system-file-manager</icon>' >> "${script_path}" | |
echo '<name>Open Root Thunar Here</name>' >> "${script_path}" | |
echo '<unique-id>1677522441568083-2</unique-id>' >> "${script_path}" | |
echo '<command>lxqt-sudo thunar</command>' >> "${script_path}" | |
echo '<description></description>' >> "${script_path}" | |
echo '<patterns>*</patterns>' >> "${script_path}" | |
echo '<directories/>' >> "${script_path}" | |
echo '</action>' >> "${script_path}" | |
echo '</actions>' >> "${script_path}" | |
chown "${username}:${username}" "${script_path}" | |
fi | |
} | |
install__net_tools() { install_packages net-tools; } | |
install__synaptic() | |
{ | |
install_packages synaptic | |
if [ -e '/usr/bin/lxqt-sudo' ] && [ ! -e '/usr/local/share/applications/synaptic.desktop' ]; then | |
if [ ! -e '/usr/local/share/applications' ]; then | |
mkdir -p '/usr/local/share/applications' | |
chown 'root:root' '/usr/local/share/applications' | |
chmod -s '/usr/local/share/applications' | |
fi | |
cp -p '/usr/share/applications/synaptic.desktop' '/usr/local/share/applications/synaptic.desktop' | |
sed -i 's/Exec=/Exec=lxqt-sudo sudo /g' '/usr/local/share/applications/synaptic.desktop' | |
fi | |
} | |
install__tango_icon_theme() { install_packages tango-icon-theme; } | |
install__tinycorelinux() | |
{ | |
install_packages wget ca-certificates | |
local script_path='/usr/local/bin/tinycorelinux-update.sh' | |
echo '#!/bin/sh' > "${script_path}" | |
#### | |
echo 'if [ ! "$(whoami)" = "root" ]; then' >> "${script_path}" | |
echo 'echo "No superuser"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'release=$(wget -O- -q "https://distro.ibiblio.org/tinycorelinux/downloads.html" | grep -o "[0-9]*.x/x86/release/TinyCore-current.iso")' >> "${script_path}" | |
echo 'release="${release%%/*}"' >> "${script_path}" | |
#### | |
echo 'if [ "${release}" = "" ]; then' >> "${script_path}" | |
echo 'echo "Release info download error"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if [ -e "/usr/local/share/tinycorelinux/${release}" ]; then' >> "${script_path}" | |
echo 'echo "Release ${release} already installed"' >> "${script_path}" | |
echo 'exit 0' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'download_dir=$(mktemp -d)' >> "${script_path}" | |
#### | |
echo 'if wget -O "${download_dir}/core.iso" "http://www.tinycorelinux.net/${release}/x86/release/TinyCore-current.iso"; then' >> "${script_path}" | |
echo 'if [ ! -e "/usr/local/share/tinycorelinux" ]; then' >> "${script_path}" | |
echo 'mkdir -p "/usr/local/share/tinycorelinux"' >> "${script_path}" | |
echo 'chown "root:root" "/usr/local/share/tinycorelinux"' >> "${script_path}" | |
echo 'chmod -s "/usr/local/share/tinycorelinux"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo '[ -e "/boot/tinycorelinux" ] && rm "/boot/tinycorelinux"' >> "${script_path}" | |
#### | |
echo 'mkdir "/usr/local/share/tinycorelinux/${release}"' >> "${script_path}" | |
echo 'ln -s "/usr/local/share/tinycorelinux/${release}" "/boot/tinycorelinux"' >> "${script_path}" | |
#### | |
echo 'mkdir "${download_dir}/mnt"' >> "${script_path}" | |
echo 'mount -t iso9660 -o loop,ro "${download_dir}/core.iso" "${download_dir}/mnt"' >> "${script_path}" | |
#### | |
echo 'cp "${download_dir}/mnt/boot/vmlinuz" "/usr/local/share/tinycorelinux/${release}/vmlinuz"' >> "${script_path}" | |
echo 'chmod 644 "/usr/local/share/tinycorelinux/${release}/vmlinuz"' >> "${script_path}" | |
#### | |
echo 'cp "${download_dir}/mnt/boot/core.gz" "/usr/local/share/tinycorelinux/${release}/core.gz"' >> "${script_path}" | |
echo 'chmod 644 "/usr/local/share/tinycorelinux/${release}/core.gz"' >> "${script_path}" | |
#### | |
echo 'mkdir -p "${download_dir}/desktop/tmp"' >> "${script_path}" | |
echo 'cp -r "${download_dir}/mnt/cde" "${download_dir}/desktop/tmp/builtin"' >> "${script_path}" | |
echo 'rm "${download_dir}/desktop/tmp/builtin/copy2fs.lst" # mount loops instead of copying to ram' >> "${script_path}" | |
echo 'rm "${download_dir}/desktop/tmp/builtin/xbase.lst" # not needed' >> "${script_path}" | |
echo 'cd "${download_dir}/desktop"' >> "${script_path}" | |
echo 'find -type f | while read line; do' >> "${script_path}" | |
echo 'chmod 444 "${line}"' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
echo 'find -type d | while read line; do' >> "${script_path}" | |
echo 'chmod 555 "${line}"' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
echo 'chmod 1777 "${download_dir}/desktop/tmp" # must be' >> "${script_path}" | |
echo 'find | cpio --create --format=newc > "${download_dir}/desktop.img"' >> "${script_path}" | |
echo 'cd "/"' >> "${script_path}" | |
echo 'rm -r "${download_dir}/desktop"' >> "${script_path}" | |
echo 'gzip -9 "${download_dir}/desktop.img"' >> "${script_path}" | |
echo 'mv "${download_dir}/desktop.img.gz" "/usr/local/share/tinycorelinux/${release}/desktop.img"' >> "${script_path}" | |
#### | |
echo 'umount "${download_dir}/mnt"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'rm -r "${download_dir}"' >> "${script_path}" | |
#### | |
echo 'exit 0' >> "${script_path}" | |
chown 'root:root' "${script_path}" | |
chmod 755 "${script_path}" | |
local i | |
for i in 1 2 3; do | |
"${script_path}" && break | |
done | |
if [ -e '/boot/tinycorelinux' ]; then | |
local script_path='/usr/local/share/tinycorelinux/99_tinycorelinux' | |
echo '#!/bin/sh' > "${script_path}" | |
#### | |
echo 'if [ -e "/boot/tinycorelinux" ]; then' >> "${script_path}" | |
echo 'cat << EOF' >> "${script_path}" | |
echo 'submenu "Tiny Core Linux" {' >> "${script_path}" | |
echo 'menuentry "Tiny Core Linux (desktop)" {' >> "${script_path}" | |
echo 'linux /boot/tinycorelinux/vmlinuz loglevel=3 noswap' >> "${script_path}" | |
echo 'initrd /boot/tinycorelinux/core.gz /boot/tinycorelinux/desktop.img' >> "${script_path}" | |
echo '}' >> "${script_path}" | |
#### | |
echo 'menuentry "Micro Core Linux (console)" {' >> "${script_path}" | |
echo 'linux /boot/tinycorelinux/vmlinuz loglevel=3 noswap' >> "${script_path}" | |
echo 'initrd /boot/tinycorelinux/core.gz' >> "${script_path}" | |
echo '}' >> "${script_path}" | |
echo '}' >> "${script_path}" | |
echo 'EOF' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'exit 0' >> "${script_path}" | |
chmod 755 "${script_path}" | |
if [ -d '/etc/grub.d' ]; then | |
ln -s "${script_path}" '/etc/grub.d/99_tinycorelinux' | |
update-grub | |
fi | |
else | |
echo ' -> tinycorelinux install failed' | |
rm "${script_path}" | |
fi | |
} | |
install__xchm() { install_packages xchm; } | |
install__xfce_taskmanager() { install_packages xfce4-taskmanager; } | |
### Drivers | |
install__vbox_additions() | |
{ | |
local i | |
if [ ! -e '/sys/class/dmi/id/product_name' ] || [ ! "$(cat '/sys/class/dmi/id/product_name')" = 'VirtualBox' ]; then | |
echo 'VirtualBox not detected' | |
return 1 | |
fi | |
install_packages wget ca-certificates | |
local additions_version | |
for i in 1 2 3; do | |
additions_version=$(wget -O - -q 'https://download.virtualbox.org/virtualbox/LATEST-STABLE.TXT') | |
[ "${additions_version}" = '' ] || break | |
done | |
if [ "${additions_version}" = '' ]; then | |
echo 'VirtualBox additions version downloading failed' | |
return 1 | |
fi | |
local download_dir=$(mktemp -d) | |
for i in 1 2 3; do | |
if wget -O "${download_dir}/vboxadditions.iso" "https://download.virtualbox.org/virtualbox/${additions_version}/VBoxGuestAdditions_${additions_version}.iso"; then | |
install_packages build-essential dkms linux-headers-$(uname -r) procps | |
mkdir "${download_dir}/mnt" | |
mount -t iso9660 -o loop,ro "${download_dir}/vboxadditions.iso" "${download_dir}/mnt" | |
mount -o remount,exec '/tmp' | |
sh "${download_dir}/mnt/VBoxLinuxAdditions.run" | |
umount "${download_dir}/mnt" | |
break | |
fi | |
done | |
rm -r -f "${download_dir}" | |
} | |
### Editors and IDEs | |
install__bless() { install_packages bless; } | |
install__dos2unix() { install_packages dos2unix; } | |
install__mousepad() { install_packages mousepad dbus-x11; } | |
install__notepadqq_ppa() | |
{ | |
local ubuntu_version='xenial' | |
local ppa_pubkey_id='2E30EE6263DE9CD4' | |
install_packages gpg dirmngr | |
mkdir -p '/usr/local/etc/apt' | |
chown 'root:root' '/usr/local/etc/apt' | |
chmod -s '/usr/local/etc/apt' | |
mkdir '/usr/local/etc/apt/sources.list.d' | |
echo 'deb http://ppa.launchpad.net/notepadqq-team/notepadqq/ubuntu '"${ubuntu_version}"' main' > '/usr/local/etc/apt/sources.list.d/notepadqq.list' | |
ln -s '/usr/local/etc/apt/sources.list.d/notepadqq.list' '/etc/apt/sources.list.d/notepadqq.list' | |
mkdir -p '/usr/local/etc/apt/trusted.gpg.d' | |
GNUPGHOME=$(mktemp -d) | |
chmod 700 "${GNUPGHOME}" | |
export GNUPGHOME | |
GPG_TEMP_DIR=$(mktemp -d) | |
export GPG_TEMP_DIR | |
gpg --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-keys "0x${ppa_pubkey_id}" | |
gpg --export "0x${ppa_pubkey_id}" > '/usr/local/etc/apt/trusted.gpg.d/notepadqq.gpg' | |
rm -r "${GPG_TEMP_DIR}" | |
GPG_TEMP_DIR='' | |
export GPG_TEMP_DIR | |
rm -r -f "${GNUPGHOME}" | |
GNUPGHOME='' | |
export GNUPGHOME | |
ln -s '/usr/local/etc/apt/trusted.gpg.d/notepadqq.gpg' '/etc/apt/trusted.gpg.d/notepadqq.gpg' | |
chmod 644 '/usr/local/etc/apt/trusted.gpg.d/notepadqq.gpg' | |
_apt_updated='false' | |
if ! install_packages notepadqq-gtk; then | |
rm '/etc/apt/sources.list.d/notepadqq.list' | |
rm '/etc/apt/sources.list.d/notepadqq.list' | |
rm '/etc/apt/trusted.gpg.d/notepadqq.gpg' | |
rm '/usr/local/etc/apt/sources.list.d/notepadqq.list' | |
rm '/usr/local/etc/apt/trusted.gpg.d/notepadqq.gpg' | |
rmdir '/usr/local/etc/apt/sources.list.d' | |
rmdir '/usr/local/etc/apt/trusted.gpg.d' | |
rmdir '/usr/local/etc/apt' | |
_apt_updated='false' | |
fi | |
} | |
install__notepadqq() | |
{ | |
install_packages notepadqq || install__notepadqq_ppa | |
} | |
install__tmux_vim() | |
{ | |
local script_path | |
install_packages wget tmux vim ca-certificates | |
local i | |
for i in 1 2 3; do | |
if wget -O "${HOME}/plug.vim" 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'; then | |
mkdir -p "${HOME}/.vim/autoload" | |
mv "${HOME}/plug.vim" "${HOME}/.vim/autoload/plug.vim" | |
chown -R "${username}:${username}" "${HOME}/.vim" | |
script_path="${HOME}/.vimrc" | |
echo "call plug#begin('~/.vim/plugins')" > "${script_path}" | |
echo "Plug 'preservim/nerdtree'" >> "${script_path}" | |
echo 'call plug#end()' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo 'autocmd VimEnter * NERDTree' >> "${script_path}" | |
echo 'let g:NERDTreeQuitOnOpen = 0' >> "${script_path}" | |
echo "autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif" >> "${script_path}" | |
# https://gist.github.com/todgru/6224848 | |
script_path='/usr/local/bin/dev-tmux.sh' | |
echo '#!/bin/sh' > "${script_path}" | |
echo 'if ! tmux attach-session -t dev > /dev/null 2>&1; then' >> "${script_path}" | |
#### # set up tmux | |
echo 'tmux start-server' >> "${script_path}" | |
#### # create a new tmux session, starting vim from a saved session in the new window | |
echo 'tmux new-session -d -s dev -n vim' >> "${script_path}" | |
#### # Select pane 0, set dir to api, run vim | |
echo 'tmux selectp -t 0' >> "${script_path}" | |
echo 'tmux send-keys "vim" C-m' >> "${script_path}" | |
#### # Split pane 0 horizontal by 65% | |
echo 'tmux splitw -v -p 15' >> "${script_path}" | |
#### # Select pane 0 | |
echo 'tmux selectp -t 0' >> "${script_path}" | |
#### # create a new window called scratch | |
echo 'tmux new-window -t dev:1 -n scratch' >> "${script_path}" | |
#### # return to main vim window | |
echo 'tmux select-window -t dev:0' >> "${script_path}" | |
#### # Finished setup, attach to the tmux session! | |
echo 'tmux attach-session -t dev' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'exit 0' >> "${script_path}" | |
create_shortcut 'dev-tmux.desktop' \ | |
'console-application' \ | |
'Dev tmux' \ | |
"${script_path}" \ | |
'gvim' | |
chown -R "${username}:${username}" "${HOME}/.vimrc" | |
chmod 755 "${script_path}" | |
sudo -u "${username}" vim +PlugInstall +qall | |
break | |
fi | |
done | |
} | |
### Encryption tools | |
install__cryptsetup() { install_packages cryptsetup; } | |
install__keepassxc() { install_packages keepassxc; } | |
install__veracrypt() | |
{ | |
install_packages wget gpg ca-certificates bzip2 | |
local script_path='/usr/local/bin/veracrypt-update.sh' | |
echo '#!/bin/sh' > "${script_path}" | |
#### | |
echo 'if [ ! "$(whoami)" = "root" ]; then' >> "${script_path}" | |
echo 'echo "No superuser"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'vc_version=$(wget -O- -q "https://api.github.com/repos/veracrypt/VeraCrypt/releases/latest" | grep -oP "(?<=\"tag_name\": \")[^\"]*")' >> "${script_path}" | |
echo 'vc_version="${vc_version##*_}"' >> "${script_path}" | |
#### | |
echo 'if [ "${vc_version}" = "" ]; then' >> "${script_path}" | |
echo 'echo "Release info download error"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if [ -e "/usr/share/doc/veracrypt/UPDATER-VERSION" ] && [ "$(cat "/usr/share/doc/veracrypt/UPDATER-VERSION")" = "${vc_version}" ]; then' >> "${script_path}" | |
echo 'echo "Release ${vc_version} already installed"' >> "${script_path}" | |
echo 'exit 0' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'vc_pubkey_url="https://www.idrix.fr/VeraCrypt/VeraCrypt_PGP_public_key.asc"' >> "${script_path}" | |
echo 'vc_tar_url="https://launchpad.net/veracrypt/trunk/${vc_version}/+download/veracrypt-${vc_version}-setup.tar.bz2"' >> "${script_path}" | |
echo 'vc_type="gtk3-gui" # console gui gtk3-console gtk3-gui' >> "${script_path}" | |
if [ "$(dpkg --print-architecture)" = 'amd64' ]; then | |
echo 'vc_arch="x64"' >> "${script_path}" | |
else | |
echo 'vc_arch="x86"' >> "${script_path}" | |
fi | |
#### | |
echo 'GNUPGHOME=$(mktemp -d)' >> "${script_path}" | |
echo 'chmod 700 "${GNUPGHOME}"' >> "${script_path}" | |
echo 'export GNUPGHOME' >> "${script_path}" | |
#### | |
echo 'mkdir "${GNUPGHOME}/veracrypt"' >> "${script_path}" | |
#### | |
echo 'if ! wget -O "${GNUPGHOME}/veracrypt/pubkey.asc" "${vc_pubkey_url}"; then' >> "${script_path}" | |
echo 'echo "Error: public key download error"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'gpg --import "${GNUPGHOME}/veracrypt/pubkey.asc"' >> "${script_path}" | |
#### | |
echo 'if ! wget -O "${GNUPGHOME}/veracrypt/veracrypt.tar.bz2" "${vc_tar_url}"; then' >> "${script_path}" | |
echo 'echo "Error: tarball download error"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if ! wget -O "${GNUPGHOME}/veracrypt/veracrypt.tar.bz2.sig" "${vc_tar_url}.sig"; then' >> "${script_path}" | |
echo 'echo "Error: signature download error"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if gpg --verify "${GNUPGHOME}/veracrypt/veracrypt.tar.bz2.sig"; then' >> "${script_path}" | |
echo '[ -x "/usr/bin/veracrypt-uninstall.sh" ] && if ! /usr/bin/veracrypt-uninstall.sh; then' >> "${script_path}" | |
echo 'echo "Error: veracrypt-uninstall.sh failed"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'bunzip2 "${GNUPGHOME}/veracrypt/veracrypt.tar.bz2"' >> "${script_path}" | |
echo 'tar xvf "${GNUPGHOME}/veracrypt/veracrypt.tar" -C "${GNUPGHOME}/veracrypt"' >> "${script_path}" | |
#### | |
echo 'mkdir "${GNUPGHOME}/veracrypt/unattended"' >> "${script_path}" | |
#### | |
echo 'vc_tar_first_offset=$(cat "${GNUPGHOME}/veracrypt/veracrypt-${vc_version}-setup-${vc_type}-${vc_arch}" | grep -a "echo OLDSKIP=" | sed "s/echo OLDSKIP=//g" | xargs)' >> "${script_path}" | |
#### | |
echo 'tail -n "+${vc_tar_first_offset}" "${GNUPGHOME}/veracrypt/veracrypt-${vc_version}-setup-${vc_type}-${vc_arch}" | tar zxv -C "${GNUPGHOME}/veracrypt/unattended" && \' >> "${script_path}" | |
echo 'for i in ${GNUPGHOME}/veracrypt/unattended/*; do' >> "${script_path}" | |
echo '[ "${i}" = "${GNUPGHOME}/veracrypt/unattended/*" ] && break' >> "${script_path}" | |
#### | |
echo 'vc_tar_second_offset=$(cat "${i}" | grep -a "^PACKAGE_START=" | sed "s/PACKAGE_START=//g")' >> "${script_path}" | |
echo 'tail -n "+${vc_tar_second_offset}" "${i}" | tar zxv -C /' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
#### | |
echo 'echo -n "${vc_version}" > "/usr/share/doc/veracrypt/UPDATER-VERSION"' >> "${script_path}" | |
echo 'else' >> "${script_path}" | |
echo 'echo "Error: tarball verifying failed"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'rm -r -f "${GNUPGHOME}"' >> "${script_path}" | |
#### | |
echo '[ -e "/usr/share/doc/veracrypt/HTML" ] && rm -r "/usr/share/doc/veracrypt/HTML"' >> "${script_path}" | |
echo 'if [ -e "/usr/share/veracrypt" ]; then' >> "${script_path}" | |
echo 'rm -r "/usr/share/veracrypt/languages"' >> "${script_path}" | |
echo 'rmdir "/usr/share/veracrypt" > /dev/null 2>&1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'exit 0' >> "${script_path}" | |
chown 'root:root' "${script_path}" | |
chmod 755 "${script_path}" | |
local i | |
for i in 1 2 3; do | |
"${script_path}" && break | |
done | |
} | |
### File utils | |
install__curl() { install_packages ca-certificates curl; } | |
install__fdupes() { install_packages fdupes; } | |
install__file() { install_packages file; } | |
install__file_roller() { install_packages file-roller bzip2 cabextract p7zip lzma unrar zip unzip unshield xz-utils arj; } | |
install__filezilla() { install_packages filezilla; } | |
install__git() | |
{ | |
install_packages git gitk git-gui | |
local download_dir=$(mktemp -d) | |
local current_dir=$(pwd) | |
cd "${download_dir}" | |
local i | |
for i in 1 2 3; do | |
if git clone 'https://github.com/dracula/gitk.git' .; then | |
mkdir -p "${HOME}/.config/git" | |
cp "${download_dir}/gitk" "${HOME}/.config/git/gitk" | |
chown -R "${username}:${username}" "${HOME}/.config/git" | |
break | |
fi | |
done | |
cd "${current_dir}" | |
rm -r -f "${download_dir}" | |
} | |
install__gnome_screenshot() { install_packages gnome-screenshot; } | |
install__inotify_tools() { install_packages inotify-tools; } | |
install__isomaster_xorriso_syslinuxutils() { install_packages isomaster xorriso syslinux-utils; } | |
install__mc() { install_packages mc; } | |
install__mirage() { install_packages mirage; } | |
install__squashfs_tools() { install_packages squashfs-tools; } | |
install__transmission() { install_packages transmission-gtk; } | |
install__tree() { install_packages tree; } | |
install__thunar_archive_plugin() | |
{ | |
if [ ! -e '/usr/bin/thunar' ]; then | |
echo 'Thunar is not installed' | |
return 1 | |
fi | |
install_packages thunar-archive-plugin | |
} | |
install__wget() { install_packages ca-certificates wget; } | |
### (HTTP) servers | |
install__apache() | |
{ | |
local script_path | |
install_packages ssl-cert apache2 | |
service apache2 stop | |
update-rc.d -f apache2 remove | |
[ -d '/etc/systemd/system' ] && command -v 'systemctl' > /dev/null 2>&1 && systemctl disable apache2 | |
a2enmod ssl | |
#a2ensite default-ssl | |
mkdir -p '/usr/local/etc/apache2' | |
chown 'root:root' '/usr/local/etc/apache2' | |
chmod -s '/usr/local/etc/apache2' | |
if [ -e '/etc/apache2/ports.conf' ]; then | |
cp -p '/etc/apache2/ports.conf' '/etc/apache2/ports.conf.old' | |
mv '/etc/apache2/ports.conf' '/usr/local/etc/apache2/ports.conf' | |
ln -s '/usr/local/etc/apache2/ports.conf' '/etc/apache2/ports.conf' | |
sed -i 's/Listen 80/#Listen 80\nListen 127.0.0.1:80\nListen [::1]:80/g' '/usr/local/etc/apache2/ports.conf' | |
sed -i 's/Listen 443/#Listen 443\nListen 127.0.0.1:443\n\tListen [::1]:443/g' '/usr/local/etc/apache2/ports.conf' | |
fi | |
if [ -e '/etc/apache2/mods-available/mpm_prefork.conf' ]; then | |
mkdir '/usr/local/etc/apache2/mods-available' | |
cp -p '/etc/apache2/mods-available/mpm_prefork.conf' '/etc/apache2/mods-available/mpm_prefork.conf.old' | |
mv '/etc/apache2/mods-available/mpm_prefork.conf' '/usr/local/etc/apache2/mods-available/mpm_prefork.conf' | |
ln -s '/usr/local/etc/apache2/mods-available/mpm_prefork.conf' '/etc/apache2/mods-available/mpm_prefork.conf' | |
sed -i 's/StartServers.*/StartServers 1/g' '/usr/local/etc/apache2/mods-available/mpm_prefork.conf' | |
sed -i 's/MinSpareServers.*/MinSpareServers 1/g' '/usr/local/etc/apache2/mods-available/mpm_prefork.conf' | |
fi | |
# allow .htaccess in /var/www | |
mkdir '/usr/local/etc/apache2/conf-available' | |
script_path='/usr/local/etc/apache2/conf-available/allow-htaccess-in-var-www.conf' | |
echo '<Directory /var/www/>' > "${script_path}" | |
echo ' AllowOverride All' >> "${script_path}" | |
echo '</Directory>' >> "${script_path}" | |
ln -s '/usr/local/etc/apache2/conf-available/allow-htaccess-in-var-www.conf' '/etc/apache2/conf-available/allow-htaccess-in-var-www.conf' | |
ln -s '../conf-available/allow-htaccess-in-var-www.conf' '/etc/apache2/conf-enabled/allow-htaccess-in-var-www.conf' | |
# custom config | |
local i | |
for i in /etc/apache2/sites-enabled/*; do | |
[ "${i}" = '/etc/apache2/sites-enabled/*' ] && break | |
rm "${i}" | |
done | |
mkdir '/usr/local/etc/apache2/sites-available' | |
script_path='/usr/local/etc/apache2/sites-available/000-build-dev-env.conf' | |
echo '<VirtualHost *:80>' > "${script_path}" | |
echo ' #ServerName www.example.com' >> "${script_path}" | |
echo ' ServerAdmin webmaster@localhost' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' HostnameLookups off' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' DocumentRoot /var/www/html' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' #<Directory "/var/www/html">' >> "${script_path}" | |
echo ' # Options Indexes FollowSymlinks' >> "${script_path}" | |
echo ' # AllowOverride All' >> "${script_path}" | |
echo ' # Require all granted' >> "${script_path}" | |
echo ' #</Directory>' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' # Use PHP-FPM (you need to a2enmod proxy_fcgi)' >> "${script_path}" | |
echo ' #<FilesMatch \.php$>' >> "${script_path}" | |
echo ' # SetHandler "proxy:unix:/run/php/php-fpm.sock|fcgi://localhost"' >> "${script_path}" | |
echo ' #</FilesMatch>' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,' >> "${script_path}" | |
echo ' # error, crit, alert, emerg.' >> "${script_path}" | |
echo ' # It is also possible to configure the loglevel for particular' >> "${script_path}" | |
echo ' # modules, e.g.' >> "${script_path}" | |
echo ' #LogLevel info ssl:warn' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' ErrorLog ${APACHE_LOG_DIR}/error.log' >> "${script_path}" | |
echo ' CustomLog ${APACHE_LOG_DIR}/access.log combined' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' #Include conf-available/serve-cgi-bin.conf' >> "${script_path}" | |
echo '</VirtualHost>' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo '<IfModule mod_ssl.c>' >> "${script_path}" | |
echo ' #<VirtualHost *:80>' >> "${script_path}" | |
echo ' # RewriteEngine on' >> "${script_path}" | |
echo ' # RewriteCond %{HTTPS} !=on' >> "${script_path}" | |
echo ' # RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]' >> "${script_path}" | |
echo ' #</VirtualHost>' >> "${script_path}" | |
echo ' <VirtualHost *:443>' >> "${script_path}" | |
echo ' #ServerName www.example.com' >> "${script_path}" | |
echo ' ServerAdmin webmaster@localhost' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' HostnameLookups off' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' # You need to a2enmod ssl' >> "${script_path}" | |
echo ' SSLEngine on' >> "${script_path}" | |
echo ' SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem' >> "${script_path}" | |
echo ' SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key' >> "${script_path}" | |
echo ' #SSLCertificateChainFile /etc/apache2/ssl.crt/server-ca.crt' >> "${script_path}" | |
echo ' #SSLCACertificatePath /etc/ssl/certs/' >> "${script_path}" | |
echo ' #SSLCACertificateFile /etc/apache2/ssl.crt/ca-bundle.crt' >> "${script_path}" | |
echo ' #SSLCARevocationPath /etc/apache2/ssl.crl/' >> "${script_path}" | |
echo ' #SSLCARevocationFile /etc/apache2/ssl.crl/ca-bundle.crl' >> "${script_path}" | |
echo ' #SSLVerifyClient require' >> "${script_path}" | |
echo ' #SSLVerifyDepth 10' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' # SSL Engine Options:' >> "${script_path}" | |
echo ' # Set various options for the SSL engine.' >> "${script_path}" | |
echo ' # o FakeBasicAuth:' >> "${script_path}" | |
echo ' # Translate the client X.509 into a Basic Authorisation. This means that' >> "${script_path}" | |
echo ' # the standard Auth/DBMAuth methods can be used for access control. The' >> "${script_path}" | |
echo ' # user name is the `one line` version of the client`s X.509 certificate.' >> "${script_path}" | |
echo ' # Note that no password is obtained from the user. Every entry in the user' >> "${script_path}" | |
echo ' # file needs this password: `xxj31ZMTZzkVA`.' >> "${script_path}" | |
echo ' # o ExportCertData:' >> "${script_path}" | |
echo ' # This exports two additional environment variables: SSL_CLIENT_CERT and' >> "${script_path}" | |
echo ' # SSL_SERVER_CERT. These contain the PEM-encoded certificates of the' >> "${script_path}" | |
echo ' # server (always existing) and the client (only existing when client' >> "${script_path}" | |
echo ' # authentication is used). This can be used to import the certificates' >> "${script_path}" | |
echo ' # into CGI scripts.' >> "${script_path}" | |
echo ' # o StdEnvVars:' >> "${script_path}" | |
echo ' # This exports the standard SSL/TLS related `SSL_*` environment variables.' >> "${script_path}" | |
echo ' # Per default this exportation is switched off for performance reasons,' >> "${script_path}" | |
echo ' # because the extraction step is an expensive operation and is usually' >> "${script_path}" | |
echo ' # useless for serving static content. So one usually enables the' >> "${script_path}" | |
echo ' # exportation for CGI and SSI requests only.' >> "${script_path}" | |
echo ' # o OptRenegotiate:' >> "${script_path}" | |
echo ' # This enables optimized SSL connection renegotiation handling when SSL' >> "${script_path}" | |
echo ' # directives are used in per-directory context.' >> "${script_path}" | |
echo ' #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire' >> "${script_path}" | |
echo ' <FilesMatch "\.(cgi|shtml|phtml|php)$">' >> "${script_path}" | |
echo ' SSLOptions +StdEnvVars' >> "${script_path}" | |
echo ' </FilesMatch>' >> "${script_path}" | |
echo ' <Directory /usr/lib/cgi-bin>' >> "${script_path}" | |
echo ' SSLOptions +StdEnvVars' >> "${script_path}" | |
echo ' </Directory>' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' # SSL Protocol Adjustments:' >> "${script_path}" | |
echo ' # The safe and default but still SSL/TLS standard compliant shutdown' >> "${script_path}" | |
echo ' # approach is that mod_ssl sends the close notify alert but doesn`t wait for' >> "${script_path}" | |
echo ' # the close notify alert from client. When you need a different shutdown' >> "${script_path}" | |
echo ' # approach you can use one of the following variables:' >> "${script_path}" | |
echo ' # o ssl-unclean-shutdown:' >> "${script_path}" | |
echo ' # This forces an unclean shutdown when the connection is closed, i.e. no' >> "${script_path}" | |
echo ' # SSL close notify alert is send or allowed to received. This violates' >> "${script_path}" | |
echo ' # the SSL/TLS standard but is needed for some brain-dead browsers. Use' >> "${script_path}" | |
echo ' # this when you receive I/O errors because of the standard approach where' >> "${script_path}" | |
echo ' # mod_ssl sends the close notify alert.' >> "${script_path}" | |
echo ' # o ssl-accurate-shutdown:' >> "${script_path}" | |
echo ' # This forces an accurate shutdown when the connection is closed, i.e. a' >> "${script_path}" | |
echo ' # SSL close notify alert is send and mod_ssl waits for the close notify' >> "${script_path}" | |
echo ' # alert of the client. This is 100% SSL/TLS standard compliant, but in' >> "${script_path}" | |
echo ' # practice often causes hanging connections with brain-dead browsers. Use' >> "${script_path}" | |
echo ' # this only for browsers where you know that their SSL implementation' >> "${script_path}" | |
echo ' # works correctly.' >> "${script_path}" | |
echo ' # Notice: Most problems of broken clients are also related to the HTTP' >> "${script_path}" | |
echo ' # keep-alive facility, so you usually additionally want to disable' >> "${script_path}" | |
echo ' # keep-alive for those clients, too. Use variable "nokeepalive" for this.' >> "${script_path}" | |
echo ' # Similarly, one has to force some clients to use HTTP/1.0 to workaround' >> "${script_path}" | |
echo ' # their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and' >> "${script_path}" | |
echo ' # "force-response-1.0" for this.' >> "${script_path}" | |
echo ' # BrowserMatch "MSIE [2-6]" \' >> "${script_path}" | |
echo ' # nokeepalive ssl-unclean-shutdown \' >> "${script_path}" | |
echo ' # downgrade-1.0 force-response-1.0' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' # You need to a2enmod socache_shmcb' >> "${script_path}" | |
echo ' #SSLSessionCache shmcb:/run/httpd/sslcache(1024000)' >> "${script_path}" | |
echo ' #SSLSessionCacheTimeout 600' >> "${script_path}" | |
echo ' #KeepAlive On' >> "${script_path}" | |
echo ' #MaxKeepAliveRequests 50' >> "${script_path}" | |
echo ' #KeepAliveTimeout 70' >> "${script_path}" | |
echo ' #SSLProtocol TLSv1 TLSv1.1 TLSv1.2' >> "${script_path}" | |
echo ' #SSLCipherSuite HIGH:!aNULL:!MD5' >> "${script_path}" | |
echo ' #Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' DocumentRoot /var/www/html' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' #<Directory "/var/www/html">' >> "${script_path}" | |
echo ' # Options Indexes FollowSymlinks' >> "${script_path}" | |
echo ' # AllowOverride All' >> "${script_path}" | |
echo ' # Require all granted' >> "${script_path}" | |
echo ' #</Directory>' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' # Use PHP-FPM (you need to a2enmod proxy_fcgi)' >> "${script_path}" | |
echo ' #<FilesMatch \.php$>' >> "${script_path}" | |
echo ' # SetHandler "proxy:unix:/run/php/php-fpm.sock|fcgi://localhost"' >> "${script_path}" | |
echo ' #</FilesMatch>' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' #LogLevel info ssl:warn' >> "${script_path}" | |
echo ' ErrorLog ${APACHE_LOG_DIR}/error.log' >> "${script_path}" | |
echo ' CustomLog ${APACHE_LOG_DIR}/access.log combined' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' #Include conf-available/serve-cgi-bin.conf' >> "${script_path}" | |
echo ' </VirtualHost>' >> "${script_path}" | |
echo '</IfModule>' >> "${script_path}" | |
ln -s '/usr/local/etc/apache2/sites-available/000-build-dev-env.conf' '/etc/apache2/sites-available/000-build-dev-env.conf' | |
ln -s '../sites-available/000-build-dev-env.conf' '/etc/apache2/sites-enabled/000-build-dev-env.conf' | |
create_shortcut 'apache2.desktop' \ | |
'link' \ | |
'Apache2' \ | |
'http://localhost' \ | |
'internet-web-browser' | |
ln -s '/var/www/html' "${HOME}/apache-www" | |
local service_started='false' | |
service apache2 status > /dev/null 2>&1 && service_started='true' | |
"${service_started}" && service apache2 stop | |
rm -r '/var/log/apache2' | |
ln -s '/var/run/apache2' '/var/log/apache2' | |
"${service_started}" && service apache2 start | |
} | |
install__apache_modphp() | |
{ | |
install_packages libapache2-mod-php | |
service apache2 status > /dev/null 2>&1 && service apache2 restart | |
} | |
install__nginx_phpfpm() | |
{ | |
local i | |
local phpversion | |
install_packages php-fpm | |
local php_fpm_started='' | |
for phpversion in /etc/php/*; do | |
[ "${phpversion}" = '/etc/php/*' ] && break | |
phpversion="${phpversion##*/}" | |
if service "php${phpversion}-fpm" status > /dev/null 2>&1; then | |
php_fpm_started="${php_fpm_started} ${phpversion}" | |
service "php${phpversion}-fpm" stop | |
fi | |
done | |
# save memory (php) | |
local cfg_dir_create='true' | |
for i in /etc/php/*; do | |
[ "${i}" = '/etc/php/*' ] && break | |
if "${cfg_dir_create}"; then | |
mkdir -p '/usr/local/etc/php' | |
chown 'root:root' '/usr/local/etc/php' | |
chmod -s '/usr/local/etc/php' | |
cfg_dir_create='false' | |
fi | |
mkdir -p "/usr/local/etc/php/${i##*/}/fpm/pool.d" | |
cp -p "${i}/fpm/pool.d/www.conf" "/usr/local/etc/php/${i##*/}/fpm/pool.d/www.conf" | |
mv "${i}/fpm/pool.d/www.conf" "${i}/fpm/pool.d/www.conf.old" | |
ln -s "/usr/local/etc/php/${i##*/}/fpm/pool.d/www.conf" "${i}/fpm/pool.d/www.conf" | |
sed -i 's/pm.start_servers = 2/pm.start_servers = 1/g' "/usr/local/etc/php/${i##*/}/fpm/pool.d/www.conf" | |
service "php${i##*/}-fpm" status > /dev/null 2>&1 && service "php${i##*/}-fpm" restart | |
done | |
# move logs to ram (php) | |
for i in /etc/php/*; do | |
[ "${i}" = '/etc/php/*' ] && break | |
i="${i##*/}" | |
rm "/var/log/php${i}-fpm.log" | |
ln -s "/var/run/php/php${i}-fpm.log" "/var/log/php${i}-fpm.log" | |
done | |
# enable systemd socket activation (php) | |
[ -d '/etc/systemd/system' ] && command -v 'systemctl' > /dev/null 2>&1 && for i in /etc/php/*; do | |
[ "${i}" = '/etc/php/*' ] && break | |
sed -i 's/php'"${i##*/}"'-fpm.sock/php'"${i##*/}"'-fpm.sockx/g' "/usr/local/etc/php/${i##*/}/fpm/pool.d/www.conf" | |
create_socket_activation_unit \ | |
"php${i##*/}-fpm" PHP-FPM unix \ | |
"/run/php/php${i##*/}-fpm.sock" \ | |
"/run/php/php${i##*/}-fpm.sockx" \ | |
www-data www-data 0660 | |
systemctl disable "php${i##*/}-fpm.service" | |
done | |
#for phpversion in ${php_fpm_started}; do | |
# service "php${phpversion}-fpm" start | |
#done | |
} | |
install__nginx() | |
{ | |
local i | |
install_packages ssl-cert nginx | |
service nginx stop | |
#update-rc.d -f nginx remove | |
#[ -d '/etc/systemd/system' ] && command -v 'systemctl' > /dev/null 2>&1 && systemctl disable nginx | |
local service_started='false' | |
service nginx status > /dev/null 2>&1 && service_started='true' | |
"${service_started}" && service nginx stop | |
mkdir -p '/usr/local/etc/nginx' | |
chown 'root:root' '/usr/local/etc/nginx' | |
chmod -s '/usr/local/etc/nginx' | |
# save memory (nginx) | |
cp -p '/etc/nginx/nginx.conf' '/etc/nginx/nginx.conf.old' | |
mv '/etc/nginx/nginx.conf' '/usr/local/etc/nginx/nginx.conf' | |
ln -s '/usr/local/etc/nginx/nginx.conf' '/etc/nginx/nginx.conf' | |
sed -i 's/worker_processes.*/worker_processes 1;/g' '/usr/local/etc/nginx/nginx.conf' | |
# configure nginx | |
mkdir '/usr/local/etc/nginx/sites-available' | |
echo -n '' > '/usr/local/etc/nginx/sites-available/default' | |
mv '/etc/nginx/sites-available/default' '/etc/nginx/sites-available/default.old' | |
ln -s '/usr/local/etc/nginx/sites-available/default' '/etc/nginx/sites-available/default' | |
for i in /etc/php/*; do | |
: | |
done | |
local script_path='/usr/local/etc/nginx/sites-available/default' | |
echo 'server {' > "${script_path}" | |
echo ' # default server' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' listen 127.0.0.1:80 default_server;' >> "${script_path}" | |
echo ' listen [::1]:80 default_server;' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' listen 127.0.0.1:443 ssl default_server;' >> "${script_path}" | |
echo ' listen [::1]:443 ssl default_server;' >> "${script_path}" | |
echo ' # Note: You should disable gzip for SSL traffic. https://bugs.debian.org/773332' >> "${script_path}" | |
echo ' # Read up on ssl_ciphers to ensure a secure configuration. https://bugs.debian.org/765782' >> "${script_path}" | |
echo ' # Self signed certs generated by the ssl-cert package. Don t use them in a production server!' >> "${script_path}" | |
echo ' include snippets/snakeoil.conf;' >> "${script_path}" | |
echo ' #include snippets/ssl-params.conf;' >> "${script_path}" | |
echo ' #ssl_session_cache shared:SSL:10m;' >> "${script_path}" | |
echo ' #ssl_session_timeout 10m;' >> "${script_path}" | |
echo ' #keepalive_timeout 70;' >> "${script_path}" | |
echo ' #ssl_protocols TLSv1 TLSv1.1 TLSv1.2;' >> "${script_path}" | |
echo ' #ssl_ciphers HIGH:!aNULL:!MD5;' >> "${script_path}" | |
echo ' #add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' root /var/www/html;' >> "${script_path}" | |
echo ' index index.php index.html index.htm;' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' # you can change this to test.com www.test.com' >> "${script_path}" | |
echo ' server_name _;' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo ' location / {' >> "${script_path}" | |
echo ' try_files $uri $uri/ =404;' >> "${script_path}" | |
echo ' }' >> "${script_path}" | |
echo ' #location /proxy {' >> "${script_path}" | |
echo ' # proxy_pass http://127.0.0.1:8081;' >> "${script_path}" | |
echo ' # proxy_pass http://unix:/path/to/unix-socket.sock;' >> "${script_path}" | |
echo ' #}' >> "${script_path}" | |
if [ "${i}" = '/etc/php/*' ]; then | |
echo ' #location ~ \.php$ {' >> "${script_path}" | |
echo ' # include snippets/fastcgi-php.conf;' >> "${script_path}" | |
echo ' # fastcgi_pass unix:/run/php/phpVERSION-fpm.sock;' >> "${script_path}" | |
echo ' # #fastcgi_pass 127.0.0.1:9000;' >> "${script_path}" | |
echo ' #}' >> "${script_path}" | |
else | |
echo ' location ~ \.php$ {' >> "${script_path}" | |
echo ' include snippets/fastcgi-php.conf;' >> "${script_path}" | |
echo ' fastcgi_pass unix:/run/php/php'"${i##*/}"'-fpm.sock;' >> "${script_path}" | |
echo ' #fastcgi_pass 127.0.0.1:9000;' >> "${script_path}" | |
echo ' }' >> "${script_path}" | |
fi | |
echo ' location ~ /\.ht {' >> "${script_path}" | |
echo ' deny all;' >> "${script_path}" | |
echo ' }' >> "${script_path}" | |
echo '}' >> "${script_path}" | |
local tmp_conf=$(mktemp) | |
cat "${script_path}" > "${tmp_conf}" | |
sed -i 's/# default server/# server for mydomain.com (move to the top of the file);/g' "${tmp_conf}" | |
sed -i 's/ default_server//g' "${tmp_conf}" | |
sed -i 's/server_name _;/server_name mydom.com www.mydom.com;/g' "${tmp_conf}" | |
echo '' >> "${script_path}" | |
cat "${tmp_conf}" >> "${script_path}" | |
rm "${tmp_conf}" | |
# move logs to ram (nginx) | |
rm '/var/log/nginx/access.log' | |
rm '/var/log/nginx/error.log' | |
ln -s '/var/run/.nginx-access.log' '/var/log/nginx/access.log' | |
ln -s '/var/run/.nginx-error.log' '/var/log/nginx/error.log' | |
"${service_started}" && service nginx start | |
} | |
install__lighttpd() | |
{ | |
install_packages lighttpd | |
service lighttpd stop | |
update-rc.d -f lighttpd remove | |
[ -d '/etc/systemd/system' ] && command -v 'systemctl' > /dev/null 2>&1 && systemctl disable lighttpd | |
# listen only on localhost (IPv4) | |
if [ ! -e '/usr/local/etc/lighttpd/conf-available' ]; then | |
mkdir -p '/usr/local/etc/lighttpd' | |
chown 'root:root' '/usr/local/etc/lighttpd' | |
chmod -s '/usr/local/etc/lighttpd' | |
mkdir '/usr/local/etc/lighttpd/conf-available' | |
fi | |
cp -r '/etc/lighttpd/lighttpd.conf' '/usr/local/etc/lighttpd/lighttpd.conf' | |
sed -i 's\include_shell "/usr/share/lighttpd/use-ipv6.pl "\#include_shell "/usr/share/lighttpd/use-ipv6.pl "\g' '/usr/local/etc/lighttpd/lighttpd.conf' | |
mv '/etc/lighttpd/lighttpd.conf' '/etc/lighttpd/lighttpd.conf.old-bde' | |
ln -s '/usr/local/etc/lighttpd/lighttpd.conf' '/etc/lighttpd/lighttpd.conf' | |
echo 'server.bind = "127.0.0.1"' > '/usr/local/etc/lighttpd/conf-available/99-listen-on-localhost.conf' | |
ln -s '/usr/local/etc/lighttpd/conf-available/99-listen-on-localhost.conf' '/etc/lighttpd/conf-available/99-listen-on-localhost.conf' | |
lighttpd-enable-mod listen-on-localhost | |
# move logs to ram | |
rm -r '/var/log/lighttpd' | |
ln -s '/var/run/lighttpd' '/var/log/lighttpd' | |
} | |
install__lighttpd_phpfpm() | |
{ | |
[ ! -e '/usr/local/etc/php' ] && install__nginx_phpfpm | |
local phpversion | |
for phpversion in /etc/php/*; do | |
: | |
done | |
if [ ! "${phpversion}" = '/etc/php/*' ]; then | |
lighttpd-enable-mod fastcgi-php-fpm | |
lighttpd-disable-mod fastcgi-php-fpm | |
local fastcgi_script | |
for fastcgi_script in /etc/lighttpd/conf-available/*fastcgi-php-fpm.conf; do | |
: | |
done | |
if [ "${fastcgi_script}" = '/etc/lighttpd/conf-available/*fastcgi-php-fpm.conf' ]; then | |
lighttpd-enable-mod fastcgi-php-fpm | |
else | |
if [ ! -e '/usr/local/etc/lighttpd/conf-available' ]; then | |
mkdir -p '/usr/local/etc/lighttpd' | |
chown 'root:root' '/usr/local/etc/lighttpd' | |
chmod -s '/usr/local/etc/lighttpd' | |
mkdir '/usr/local/etc/lighttpd/conf-available' | |
fi | |
cp -r "${fastcgi_script}" "/usr/local/etc/lighttpd/conf-available/${fastcgi_script##*/}" | |
sed -i 's\/run/php/php-fpm.sock\/run/php/php'"${phpversion##*/}"'-fpm.sock\g' "/usr/local/etc/lighttpd/conf-available/${fastcgi_script##*/}" | |
mv "${fastcgi_script}" "${fastcgi_script}.old-bde" | |
ln -s "/usr/local/etc/lighttpd/conf-available/${fastcgi_script##*/}" "${fastcgi_script}" | |
lighttpd-enable-mod fastcgi-php-fpm | |
fi | |
fi | |
} | |
install__netcat() { install_packages netcat-openbsd; } | |
install__proftpd() | |
{ | |
local script_path | |
local apt_failed='false' | |
install_packages proftpd-core || apt_failed='true' | |
sed -i 's/LoadModule mod_unique_id.c/#LoadModule mod_unique_id.c/g' '/etc/proftpd/modules.conf' | |
script_path='/etc/proftpd/conf.d/build-dev-env.conf' | |
echo 'DefaultAddress 127.0.0.1' > "${script_path}" | |
echo 'SocketBindTight on' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo '#UseIPv6 off' >> "${script_path}" | |
echo 'UseReverseDNS off' >> "${script_path}" | |
echo 'IdentLookups off' >> "${script_path}" | |
echo 'ServerIdent off' >> "${script_path}" | |
echo 'ServerName "Dev FTP server"' >> "${script_path}" | |
echo 'DeferWelcome on' >> "${script_path}" | |
echo '#ShowSymlinks off' >> "${script_path}" | |
echo '#TimeoutNoTransfer 600' >> "${script_path}" | |
echo '#TimeoutStalled 600' >> "${script_path}" | |
echo '#TimeoutIdle 1200' >> "${script_path}" | |
echo 'RootLogin off' >> "${script_path}" | |
echo '#DefaultRoot ~' >> "${script_path}" | |
echo '#ListOptions "+a"' >> "${script_path}" | |
echo '#PassivePorts 49152 65534' >> "${script_path}" | |
echo '#MasqueradeAddress 1.2.3.4' >> "${script_path}" | |
# move logs to ram | |
rm -r -f '/var/log/proftpd' | |
ln -s '/var/run/.proftpd.log' '/var/log/proftpd' | |
mkdir '/var/run/.proftpd.log' | |
if [ -d '/etc/systemd/system' ] && command -v 'systemctl' > /dev/null 2>&1; then | |
if [ ! -e '/usr/local/etc/systemd' ]; then | |
mkdir -p '/usr/local/etc/systemd' | |
chown 'root:root' '/usr/local/etc/systemd' | |
chmod -s '/usr/local/etc/systemd' | |
mkdir '/usr/local/etc/systemd/system' | |
fi | |
script_path='/usr/local/etc/systemd/system/proftpd-logs.service' | |
echo '[Unit]' > "${script_path}" | |
echo 'Description=Create ProFTPD volatile logs directory' >> "${script_path}" | |
echo 'Before=proftpd.service' >> "${script_path}" | |
echo 'Before=proftpd.socket' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo '[Service]' >> "${script_path}" | |
echo 'Type=oneshot' >> "${script_path}" | |
echo 'ExecStart=mkdir /var/run/.proftpd.log' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo '[Install]' >> "${script_path}" | |
echo 'WantedBy=multi-user.target' >> "${script_path}" | |
ln -s '/usr/local/etc/systemd/system/proftpd-logs.service' '/etc/systemd/system/proftpd-logs.service' | |
systemctl enable proftpd-logs.service | |
fi | |
if [ -d '/etc/init.d' ] && command -v 'insserv' > /dev/null 2>&1; then | |
if [ ! -e '/usr/local/etc/init.d' ]; then | |
mkdir -p '/usr/local/etc/init.d' | |
chown 'root:root' '/usr/local/etc/init.d' | |
chmod -s '/usr/local/etc/init.d' | |
fi | |
script_path='/usr/local/etc/init.d/proftpd-logs.sh' | |
echo '#!/bin/sh' > "${script_path}" | |
#### | |
echo '### BEGIN INIT INFO' >> "${script_path}" | |
echo '# Provides: proftpd-logs' >> "${script_path}" | |
echo '# Required-Start:' >> "${script_path}" | |
echo '# Required-Stop: proftpd' >> "${script_path}" | |
echo '# Default-Start: 2 3 4 5' >> "${script_path}" | |
echo '# Default-Stop: 0 1 6' >> "${script_path}" | |
echo '# Short-Description: Create ProFTPD volatile logs directory' >> "${script_path}" | |
echo '# Description: All logs are saved in RAM' >> "${script_path}" | |
echo '# X-Start-Before: proftpd' >> "${script_path}" | |
echo '### END INIT INFO' >> "${script_path}" | |
#### | |
echo '[ "${1}" = "start" ] && exec mkdir "/var/run/.proftpd.log" > /dev/null 2>&1' >> "${script_path}" | |
#### | |
echo 'exit 0' >> "${script_path}" | |
chmod 755 "${script_path}" | |
ln -s "${script_path}" "/etc/init.d/${script_path##*/}" | |
insserv -d "${script_path##*/}" | |
fi | |
# continue configuration | |
"${apt_failed}" && DEBIAN_FRONTEND='noninteractive' apt-get install -f | |
# systemd socket activation | |
if [ -d '/etc/systemd/system' ] && command -v 'systemctl' > /dev/null 2>&1; then | |
sed -i 's/ServerType standalone/#ServerType standalone\nServerType inetd/g' '/etc/proftpd/proftpd.conf' | |
mkdir '/usr/local/etc/systemd/system/proftpd.socket.d' | |
script_path='/usr/local/etc/systemd/system/proftpd.socket.d/localhost.conf' | |
echo '[Socket]' > "${script_path}" | |
echo 'ListenStream=' >> "${script_path}" | |
echo 'ListenStream=127.0.0.1:21' >> "${script_path}" | |
echo 'ListenStream=[::1]:21' >> "${script_path}" | |
ln -s '/usr/local/etc/systemd/system/proftpd.socket.d' '/etc/systemd/system/proftpd.socket.d' | |
systemctl disable proftpd.service | |
systemctl stop proftpd.service | |
systemctl start proftpd.socket | |
script_path='/usr/local/etc/systemd/system/proftpd-socket-start.service' | |
echo '[Unit]' > "${script_path}" | |
echo 'Description=this fucking ProFTPD socket' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo '[Service]' >> "${script_path}" | |
echo 'Type=oneshot' >> "${script_path}" | |
echo 'ExecStart=systemctl start proftpd.socket' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo '[Install]' >> "${script_path}" | |
echo 'WantedBy=multi-user.target' >> "${script_path}" | |
ln -s '/usr/local/etc/systemd/system/proftpd-socket-start.service' '/etc/systemd/system/proftpd-socket-start.service' | |
systemctl enable proftpd-socket-start.service | |
fi | |
# www-data user | |
if [ -e '/var/www' ]; then | |
script_path='/etc/proftpd/conf.d/build-dev-env.conf' | |
echo '' >> "${script_path}" | |
echo 'RequireValidShell off' >> "${script_path}" | |
echo 'AuthUserFile /etc/proftpd/ftpd.passwd' >> "${script_path}" | |
echo 'www-data' | ftpasswd --stdin --passwd --file=/etc/proftpd/ftpd.passwd \ | |
--name=www-data \ | |
--uid=$(id -u www-data) \ | |
--gid=$(id -u www-data) \ | |
--home=/var/www \ | |
--shell=/bin/false | |
chown -R 'www-data:www-data' '/var/www' | |
fi | |
service proftpd stop | |
} | |
install__stunnel() { install_packages stunnel4; } | |
install__ucspi_tcp() { install_packages ucspi-tcp; } | |
### Interpreters, package managers, compilers and debuggers | |
install__binutils() { install_packages binutils; } | |
install__gcc_gpp() { install_packages gcc g++ make libc6-dev; } | |
install__nodejs() | |
{ | |
install_packages npm unzip yarnpkg | |
ln -s '/usr/bin/yarnpkg' '/usr/local/bin/yarn' | |
create_shortcut 'js-reference.desktop' \ | |
'link' \ | |
'JavaScript reference' \ | |
'https://devdocs.io/javascript' \ | |
'help-browser' | |
} | |
install__lessc() { install_packages node-less; } | |
install__php_phpbrew() | |
{ | |
local i | |
install_packages \ | |
php-cli \ | |
composer php-xml php-zip \ | |
php-memcache php-memcached \ | |
php-redis \ | |
php-apcu \ | |
php-sqlite3 \ | |
php-curl \ | |
php-gd php-imagick | |
### php docs | |
install_packages wget | |
for i in 1 2 3; do | |
if wget -O '/usr/local/share/php-manual.chm' 'https://www.php.net/distributions/manual/php_enhanced_en.chm'; then | |
chown 'root:root' '/usr/local/share/php-manual.chm' | |
mkdir '/usr/local/share/php-manual' | |
chown 'root:root' '/usr/local/share/php-manual' | |
chmod -s '/usr/local/share/php-manual' | |
mv '/usr/local/share/php-manual.chm' '/usr/local/share/php-manual/php-manual.chm' | |
create_shortcut 'PHP-manual.desktop' \ | |
'application' \ | |
'PHP manual' \ | |
'xchm /usr/local/share/php-manual/php-manual.chm' \ | |
'help-browser' | |
break | |
fi | |
done | |
### phpredis reference | |
local download_dir=$(mktemp -d) | |
local current_dir=$(pwd) | |
install_packages ca-certificates git | |
cd "${download_dir}" | |
for i in 1 2 3; do | |
if git clone 'https://github.com/phpredis/phpredis.git' .; then | |
rm \ | |
'./docs/DOCTUM_VERSION' \ | |
'./docs/opensearch.xml' \ | |
'./docs/PROJECT_VERSION' \ | |
'./docs/renderer.index' | |
local doctumjs_patch_file=$(mktemp) | |
echo "this.responseText='$(cat './docs/doctum-search.json' | sed "s/'/\\\'/g" | sed 's/\\n/<br>/g')';reqListener();" > "${doctumjs_patch_file}" | |
sed -i -e '/oReq.send();/r '"${doctumjs_patch_file}" -e '/oReq.send();/d' './docs/doctum.js' | |
rm './docs/doctum-search.json' | |
rm "${doctumjs_patch_file}" | |
mv './docs' '/usr/local/share/phpredis-reference' | |
create_shortcut 'phpredis-reference.desktop' \ | |
'link' \ | |
'PHP Redis reference' \ | |
'/usr/local/share/phpredis-reference/index.html' \ | |
'text-x-generic' | |
break | |
fi | |
done | |
cd "${current_dir}" | |
rm -r -f "${download_dir}" | |
### phpbrew | |
install_packages wget ca-certificates | |
for i in 1 2 3; do | |
if wget -O '/usr/local/bin/phpbrew' 'https://github.com/phpbrew/phpbrew/releases/latest/download/phpbrew.phar'; then | |
chown 'root:root' '/usr/local/bin/phpbrew' | |
chmod 755 '/usr/local/bin/phpbrew' | |
install_packages php-cli php-bz2 php-xml \ | |
autoconf \ | |
automake \ | |
autotools-dev \ | |
gcc g++ make libc6-dev \ | |
gettext \ | |
libbz2-dev \ | |
libcurl4-gnutls-dev \ | |
libfreetype6 libfreetype6-dev \ | |
libgd3 libgd-dev \ | |
libicu-dev \ | |
libjpeg-dev \ | |
libltdl7 libltdl-dev \ | |
libmcrypt4 libmcrypt-dev \ | |
libmhash2 libmhash-dev \ | |
libonig-dev \ | |
libpng16-16 libpng-dev \ | |
libreadline-dev \ | |
libsqlite3-dev \ | |
libssl-dev \ | |
libxml2 libxml2-dev \ | |
libxpm4 \ | |
libxslt-dev libxslt1-dev \ | |
libzip-dev \ | |
openssl \ | |
pkg-config \ | |
re2c | |
sudo -u "${username}" phpbrew init | |
sudo -u "${username}" phpbrew update | |
sudo -u "${username}" phpbrew update --old | |
if [ ! -e "${HOME}/.bashrc" ]; then | |
echo -n '' > "${HOME}/.bashrc" | |
chown "${username}:${username}" "${HOME}/.bashrc" | |
else | |
echo '' >> "${HOME}/.bashrc" | |
fi | |
echo '[[ -e "${HOME}/.phpbrew/bashrc" ]] && source "${HOME}/.phpbrew/bashrc"' >> "${HOME}/.bashrc" | |
break | |
fi | |
done | |
} | |
install__sassc() { install_packages sassc; } | |
install__strace() { install_packages strace; } | |
# Launchers | |
install__launcher_portainer() | |
{ | |
local script_path='/usr/local/bin/portainer.sh' | |
echo '#!/bin/bash' > "${script_path}" | |
#### | |
echo 'if [ ! "$(whoami)" = "root" ]; then' >> "${script_path}" | |
echo 'echo " This launcher starts the Docker web admin panel."' >> "${script_path}" | |
echo 'echo " Answer the questions:"' >> "${script_path}" | |
echo 'echo ""' >> "${script_path}" | |
#### | |
echo 'sudo "${0}" "$(whoami)"' >> "${script_path}" | |
echo 'exit "${?}"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if ! command -v "docker" > /dev/null 2>&1; then' >> "${script_path}" | |
echo 'echo -n "Install docker.io? (y/[N]) "' >> "${script_path}" | |
echo 'read answer' >> "${script_path}" | |
echo 'if [ "${answer}" = "y" ]; then' >> "${script_path}" | |
echo 'apt-get update' >> "${script_path}" | |
echo 'apt-get install --no-install-recommends -y docker.io' >> "${script_path}" | |
echo 'apt-get clean' >> "${script_path}" | |
echo 'else' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if docker ps -a | grep "portainer" > /dev/null 2>&1; then' >> "${script_path}" | |
echo 'if [ "${DISPLAY}" = "" ]; then' >> "${script_path}" | |
echo 'echo "Stopping portainer"' >> "${script_path}" | |
echo 'docker stop portainer' >> "${script_path}" | |
echo 'sleep 3' >> "${script_path}" | |
echo 'else' >> "${script_path}" | |
echo 'echo -n "Open the app? ([Y]/n) "' >> "${script_path}" | |
echo 'read answer' >> "${script_path}" | |
echo 'if [ "${answer}" = "n" ]; then' >> "${script_path}" | |
echo 'echo "Stopping portainer"' >> "${script_path}" | |
echo 'docker stop portainer' >> "${script_path}" | |
echo 'sleep 3' >> "${script_path}" | |
echo 'else' >> "${script_path}" | |
echo 'sudo -u "${1}" sensible-browser "http://127.0.0.1:$(cat /var/run/.portainer.port)" &' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'admin_password="\$2y\$05\$9OufNF57Jv.r6knl6ReFI.AP97ewS6VvRDr44pfpsM.VIGfFgFWDK"' >> "${script_path}" | |
echo 'echo "admin password [adminadminadmin]:"' >> "${script_path}" | |
#### | |
echo 'http_port="9000"' >> "${script_path}" | |
echo 'while netstat --inet -n -a -p | grep ":${http_port}" > 2 2>&1; do' >> "${script_path}" | |
echo 'http_port="$((${http_port}+1))"' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
#### | |
echo 'echo -n "HTTP server port [${http_port}]: "' >> "${script_path}" | |
echo 'read http_port_answer' >> "${script_path}" | |
echo '[ "${http_port_answer}" = "" ] || http_port="${http_port_answer}"' >> "${script_path}" | |
#### | |
echo 'echo "Starting container"' >> "${script_path}" | |
echo 'docker run --rm -d \' >> "${script_path}" | |
echo '--name=portainer \' >> "${script_path}" | |
echo '-p "127.0.0.1:${http_port}:9000" \' >> "${script_path}" | |
echo '-v portainer_data:/data \' >> "${script_path}" | |
echo '-v "/var/run/docker.sock:/var/run/docker.sock" \' >> "${script_path}" | |
echo 'portainer/portainer-ce \' >> "${script_path}" | |
echo '--no-analytics --admin-password="${admin_password}"' >> "${script_path}" | |
#### | |
echo 'echo ""' >> "${script_path}" | |
echo 'echo -n "${http_port}" > "/var/run/.portainer.port"' >> "${script_path}" | |
echo 'if [ ! "${DISPLAY}" = "" ]; then' >> "${script_path}" | |
echo 'echo -n "Press [ENTER] to open the app"' >> "${script_path}" | |
echo 'read enter' >> "${script_path}" | |
echo 'sudo -u "${1}" sensible-browser "http://127.0.0.1:${http_port}" &' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'exit 0' >> "${script_path}" | |
chown 'root:root' "${script_path}" | |
chmod 755 "${script_path}" | |
create_shortcut 'portainer-launcher.desktop' \ | |
'console-application' \ | |
'Portainer' \ | |
"${script_path}" \ | |
'internet-web-browser' | |
} | |
install__launcher_smtp4dev() | |
{ | |
local script_path='/usr/local/bin/smtp4dev.sh' | |
echo '#!/bin/bash' > "${script_path}" | |
#### | |
echo 'if [ ! "$(whoami)" = "root" ]; then' >> "${script_path}" | |
echo 'echo " This launcher starts the local mailbox"' >> "${script_path}" | |
echo 'echo " and reconfigures PHP."' >> "${script_path}" | |
echo 'echo " !!! Do not close this window."' >> "${script_path}" | |
echo 'echo " Answer the questions:"' >> "${script_path}" | |
echo 'echo ""' >> "${script_path}" | |
#### | |
echo 'sudo "${0}" "$(whoami)"' >> "${script_path}" | |
echo 'exit "${?}"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if ! command -v "msmtp" > /dev/null 2>&1; then' >> "${script_path}" | |
echo 'echo -n "Install msmtp? (y/[N]) "' >> "${script_path}" | |
echo 'read answer' >> "${script_path}" | |
echo 'if [ "${answer}" = "y" ]; then' >> "${script_path}" | |
echo 'apt-get update' >> "${script_path}" | |
echo 'apt-get install --no-install-recommends -y msmtp' >> "${script_path}" | |
echo 'apt-get clean' >> "${script_path}" | |
echo 'else' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if ! command -v "docker" > /dev/null 2>&1; then' >> "${script_path}" | |
echo 'echo -n "Install docker.io? (y/[N]) "' >> "${script_path}" | |
echo 'read answer' >> "${script_path}" | |
echo 'if [ "${answer}" = "y" ]; then' >> "${script_path}" | |
echo 'apt-get update' >> "${script_path}" | |
echo 'apt-get install -y docker.io' >> "${script_path}" | |
echo 'apt-get clean' >> "${script_path}" | |
echo 'else' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'http_port="9000"' >> "${script_path}" | |
echo 'while netstat --inet -n -a -p | grep ":${http_port}" > /dev/null 2>&1; do' >> "${script_path}" | |
echo 'http_port="$((${http_port}+1))"' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
#### | |
echo 'smtp_port="$((${http_port}+1))"' >> "${script_path}" | |
echo 'while netstat --inet -n -a -p | grep ":${smtp_port}" > /dev/null 2>&1; do' >> "${script_path}" | |
echo 'smtp_port="$((${smtp_port}+1))"' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
#### | |
echo 'echo -n "HTTP server port [${http_port}]: "' >> "${script_path}" | |
echo 'read http_port_answer' >> "${script_path}" | |
echo '[ "${http_port_answer}" = "" ] || http_port="${http_port_answer}"' >> "${script_path}" | |
#### | |
echo 'echo -n "SMTP server port [${smtp_port}]: "' >> "${script_path}" | |
echo 'read smtp_port_answer' >> "${script_path}" | |
echo '[ "${smtp_port_answer}" = "" ] || smtp_port="${smtp_port_answer}"' >> "${script_path}" | |
#### | |
echo 'if [ ! -e "/var/run/.smtp4dev" ]; then' >> "${script_path}" | |
echo 'mkdir "/var/run/.smtp4dev"' >> "${script_path}" | |
echo 'chown "root:root" "/var/run/.smtp4dev"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'echo "Configuring msmtp"' >> "${script_path}" | |
echo 'echo "defaults" > "/var/run/.smtp4dev/msmtprc"' >> "${script_path}" | |
echo 'echo "tls off" >> "/var/run/.smtp4dev/msmtprc"' >> "${script_path}" | |
echo 'echo "account smtp4dev" >> "/var/run/.smtp4dev/msmtprc"' >> "${script_path}" | |
echo 'echo "host 127.0.0.1" >> "/var/run/.smtp4dev/msmtprc"' >> "${script_path}" | |
echo 'echo "port ${smtp_port}" >> "/var/run/.smtp4dev/msmtprc"' >> "${script_path}" | |
echo 'echo "auth off" >> "/var/run/.smtp4dev/msmtprc"' >> "${script_path}" | |
echo 'echo "from msmtp@localhost" >> "/var/run/.smtp4dev/msmtprc"' >> "${script_path}" | |
echo 'echo "logfile /var/run/.smtp4dev/msmtp.log" >> "/var/run/.smtp4dev/msmtprc"' >> "${script_path}" | |
echo 'echo "account default: smtp4dev" >> "/var/run/.smtp4dev/msmtprc"' >> "${script_path}" | |
echo 'chown "root:root" "/var/run/.smtp4dev/msmtprc"' >> "${script_path}" | |
#### | |
echo 'echo "[mail function]" > "/var/run/.smtp4dev/smtp4dev.ini"' >> "${script_path}" | |
echo 'echo "sendmail_path = \"$(command -v msmtp) -C /var/run/.smtp4dev/msmtprc -t\"" >> "/var/run/.smtp4dev/smtp4dev.ini"' >> "${script_path}" | |
echo 'chown "root:root" "/var/run/.smtp4dev/msmtprc"' >> "${script_path}" | |
#### | |
echo 'if [ ! -e "/var/run/.smtp4dev/msmtp.log" ]; then' >> "${script_path}" | |
echo 'echo -n "" > "/var/run/.smtp4dev/msmtp.log"' >> "${script_path}" | |
echo 'chown "msmtp:msmtp" "/var/run/.smtp4dev/msmtp.log"' >> "${script_path}" | |
echo 'chmod 664 "/var/run/.smtp4dev/msmtp.log"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'echo "Configuring PHP"' >> "${script_path}" | |
echo 'for phpversion in /etc/php/*; do' >> "${script_path}" | |
echo '[ "${phpversion}" = "/etc/php/*" ] && break' >> "${script_path}" | |
echo 'for phpsapi in ${phpversion}/*/conf.d; do' >> "${script_path}" | |
echo '[ "${phpsapi}" = "${phpversion}/*/conf.d" ] && break' >> "${script_path}" | |
echo 'ln -s "/var/run/.smtp4dev/smtp4dev.ini" "${phpsapi}/99-smtp4dev.ini" > /dev/null 2>&1' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
#### | |
echo 'if service apache2 status > /dev/null 2>&1; then' >> "${script_path}" | |
echo 'echo "Restaring Apache2"' >> "${script_path}" | |
echo 'service apache2 restart' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'for phpversion in /etc/php/*; do' >> "${script_path}" | |
echo '[ "${phpversion}" = "/etc/php/*" ] && break' >> "${script_path}" | |
echo 'phpversion="${phpversion##*/}"' >> "${script_path}" | |
echo 'if service "php${phpversion}-fpm" status > /dev/null 2>&1; then' >> "${script_path}" | |
echo 'echo "Restaring php${phpversion}-fpm"' >> "${script_path}" | |
echo 'service "php${phpversion}-fpm" restart' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
#### | |
echo 'if [ ! "${DISPLAY}" = "" ]; then' >> "${script_path}" | |
echo 'echo -n "Open the app? ([Y]/n) "' >> "${script_path}" | |
echo 'read answer' >> "${script_path}" | |
echo 'if [ "${answer}" = "" ] || [ "${answer}" = "Y" ] || [ "${answer}" = "y" ]; then' >> "${script_path}" | |
echo 'sudo -u "${1}" sensible-browser "http://127.0.0.1:${http_port}" &' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
### | |
echo 'echo "Starting container"' >> "${script_path}" | |
echo 'docker run --rm -it \' >> "${script_path}" | |
echo '--name=smtp4dev \' >> "${script_path}" | |
echo '-p "127.0.0.1:${http_port}:80" \' >> "${script_path}" | |
echo '-p "127.0.0.1:${smtp_port}:25" \' >> "${script_path}" | |
echo 'rnwood/smtp4dev' >> "${script_path}" | |
#### | |
echo 'echo "Deconfiguring PHP"' >> "${script_path}" | |
echo 'for phpversion in /etc/php/*; do' >> "${script_path}" | |
echo '[ "${phpversion}" = "/etc/php/*" ] && break' >> "${script_path}" | |
echo 'for phpsapi in ${phpversion}/*/conf.d; do' >> "${script_path}" | |
echo '[ "${phpsapi}" = "${phpversion}/*/conf.d" ] && break' >> "${script_path}" | |
echo 'rm "${phpsapi}/99-smtp4dev.ini" > /dev/null 2>&1' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
#### | |
echo 'if service apache2 status > /dev/null 2>&1; then' >> "${script_path}" | |
echo 'echo "Restaring Apache2"' >> "${script_path}" | |
echo 'service apache2 restart' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'for phpversion in /etc/php/*; do' >> "${script_path}" | |
echo '[ "${phpversion}" = "/etc/php/*" ] && break' >> "${script_path}" | |
echo 'phpversion="${phpversion##*/}"' >> "${script_path}" | |
echo 'if service "php${phpversion}-fpm" status > /dev/null 2>&1; then' >> "${script_path}" | |
echo 'echo "Restaring php${phpversion}-fpm"' >> "${script_path}" | |
echo 'service "php${phpversion}-fpm" restart' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
#### | |
echo 'exit 0' >> "${script_path}" | |
chown 'root:root' "${script_path}" | |
chmod 755 "${script_path}" | |
create_shortcut '/smtp4dev-launcher.desktop' \ | |
'console-application' \ | |
'smtp4dev' \ | |
"${script_path}" \ | |
'mail-send-receive' | |
} | |
### Remote access | |
install__putty() { install_packages putty; } | |
install__ssh() | |
{ | |
install_packages openssh-server openssh-client | |
if [ -d '/etc/systemd/system' ] && command -v 'systemctl' > /dev/null 2>&1; then | |
systemctl enable ssh.socket && systemctl disable ssh.service && systemctl stop ssh.service | |
fi | |
} | |
install__vinagre() { install_packages vinagre; } | |
install__x11vnc() { install_packages x11vnc; } | |
### Virtualization | |
install__qemu() | |
{ | |
install_packages qemu-user-static qemu-utils | |
mkdir -p '/usr/local/etc/modprobe.d' | |
chown 'root:root' '/usr/local/etc/modprobe.d' | |
chmod -s '/usr/local/etc/modprobe.d' | |
echo 'options nbd max_part=16' > '/usr/local/etc/modprobe.d/nbd-max-part.conf' | |
chown 'root:root' '/usr/local/etc/modprobe.d/nbd-max-part.conf' | |
chmod 644 '/usr/local/etc/modprobe.d/nbd-max-part.conf' | |
ln -s '/usr/local/etc/modprobe.d/nbd-max-part.conf' '/etc/modprobe.d/nbd-max-part.conf' | |
} | |
### Web browsers | |
install__chromium() | |
{ | |
install_packages chromium chromium-l10n | |
if grep '^[a-z]*/[a-z]*$' '/etc/debian_version' > /dev/null 2>&1; then | |
install_packages chromium-sandbox | |
else | |
[ "$(sed 's/\..*//' /etc/debian_version)" -le '10' ] && install_packages chromium-sandbox | |
fi | |
} | |
install__firefox() | |
{ | |
local ff_lang='' | |
local i | |
for i in ${LANG} ${LANGUAGE} ${LC_CTYPE} ${LC_NUMERIC} ${LC_TIME} ${LC_COLLATE} ${LC_MONETARY} ${LC_MESSAGES} ${LC_PAPER} ${LC_NAME} ${LC_ADDRESS} ${LC_TELEPHONE} ${LC_MEASUREMENT} ${LC_IDENTIFICATION} ${LC_ALL}; do | |
ff_lang="${i}" | |
done | |
[ ! "${ff_lang}" = '' ] && ff_lang="firefox-esr-l10n-${ff_lang%_*}*" | |
install_packages firefox-esr ${ff_lang} | |
} | |
install__default_browser() { update-alternatives --set 'x-www-browser' '/usr/bin/chromium'; } | |
### Scripts | |
install__add_localhost_domain() | |
{ | |
local script_path='/usr/local/bin/add-localhost-domain.sh' | |
echo '#!/bin/sh' > "${script_path}" | |
#### | |
echo 'if [ ! "$(whoami)" = "root" ]; then' >> "${script_path}" | |
echo 'echo " This program allows you to temporarily"' >> "${script_path}" | |
echo 'echo " add DNS addresses for 127.0.0.1 and ::1"' >> "${script_path}" | |
echo 'echo " by modifying /etc/hosts"' >> "${script_path}" | |
echo 'echo ""' >> "${script_path}" | |
echo 'echo " After restart all changes will be lost"' >> "${script_path}" | |
echo 'echo ""' >> "${script_path}" | |
#### | |
echo 'sudo "${0}" ${@}' >> "${script_path}" | |
echo 'exit "$?"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if [ ! -e "/etc/hosts" ]; then' >> "${script_path}" | |
echo 'echo "/etc/hosts does not exist"' >> "${script_path}" | |
echo 'echo ""' >> "${script_path}" | |
echo 'echo -n "Press [ENTER]"' >> "${script_path}" | |
echo 'read enter' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'print_S1() { echo -n "${1}"; }' >> "${script_path}" | |
echo 'print_S2() { echo -n "${2}"; }' >> "${script_path}" | |
echo 'restart_script()' >> "${script_path}" | |
echo '{' >> "${script_path}" | |
echo 'echo -n "Add another domain? (y/[N]) "' >> "${script_path}" | |
echo 'read answer' >> "${script_path}" | |
echo 'echo ""' >> "${script_path}" | |
echo '[ "${answer}" = "y" ] && exec "${1}"' >> "${script_path}" | |
#### | |
echo 'exit "${2}"' >> "${script_path}" | |
echo '}' >> "${script_path}" | |
#### | |
echo 'if mountpoint -q "/etc/hosts"; then' >> "${script_path}" | |
echo 'echo "Current domains:"' >> "${script_path}" | |
echo 'print_hosts="false"' >> "${script_path}" | |
#### | |
echo 'cat "/etc/hosts" | while read hosts_line; do' >> "${script_path}" | |
echo 'if "${print_hosts}"; then' >> "${script_path}" | |
echo 'echo -n " $(print_S2 ${hosts_line}) "' >> "${script_path}" | |
#### | |
echo 'case "$(print_S1 ${hosts_line})" in' >> "${script_path}" | |
echo '"127.0.0.1")' >> "${script_path}" | |
echo 'echo -n "IPv4"' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo '"::1")' >> "${script_path}" | |
echo 'echo -n "IPv6"' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo 'esac' >> "${script_path}" | |
#### | |
echo 'echo ""' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo '[ "${hosts_line}" = "# Added by add-localhost-domain.sh" ] && print_hosts="true"' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
echo 'else' >> "${script_path}" | |
echo 'echo "Current domains: (none)"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'echo ""' >> "${script_path}" | |
#### | |
echo 'echo -n "New hostname: "' >> "${script_path}" | |
echo 'read new_hostname' >> "${script_path}" | |
echo 'if [ "${new_hostname}" = "" ]; then' >> "${script_path}" | |
echo 'echo "Error: no domain specified"' >> "${script_path}" | |
echo 'echo ""' >> "${script_path}" | |
#### | |
echo 'restart_script "${0}" 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'echo -n "IPv4 [4] (default) | IPv6 [6] | Both [46] : "' >> "${script_path}" | |
echo 'read new_hostname_proto' >> "${script_path}" | |
echo '[ "${new_hostname_proto}" = "" ] && new_hostname_proto="4"' >> "${script_path}" | |
echo 'case "${new_hostname_proto}" in' >> "${script_path}" | |
echo '"4"|"6"|"46") ;;' >> "${script_path}" | |
echo '*)' >> "${script_path}" | |
echo 'echo "Error: wrong protocol"' >> "${script_path}" | |
echo 'echo ""' >> "${script_path}" | |
#### | |
echo 'restart_script "${0}" 1' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo 'esac' >> "${script_path}" | |
#### | |
echo 'if mountpoint -q "/etc/hosts"; then' >> "${script_path}" | |
echo 'check_regex="false"' >> "${script_path}" | |
#### | |
echo 'case "${new_hostname_proto}" in' >> "${script_path}" | |
echo '"4")' >> "${script_path}" | |
echo 'grep "127.0.0.1 ${new_hostname}" "/etc/hosts" > /dev/null 2>&1 && check_regex="true"' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo '"6")' >> "${script_path}" | |
echo 'grep "::1 ${new_hostname}" "/etc/hosts" > /dev/null 2>&1 && check_regex="true"' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo '"46")' >> "${script_path}" | |
echo 'if grep "127.0.0.1 ${new_hostname}" "/etc/hosts" > /dev/null 2>&1 || grep "::1 ${new_hostname}" "/etc/hosts" > /dev/null 2>&1; then' >> "${script_path}" | |
echo 'check_regex="true"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo 'esac' >> "${script_path}" | |
#### | |
echo 'if "${check_regex}"; then' >> "${script_path}" | |
echo 'echo "Error: ${new_hostname} IPv${new_hostname_proto} already exists"' >> "${script_path}" | |
echo 'echo ""' >> "${script_path}" | |
#### | |
echo 'restart_script "${0}" 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'else' >> "${script_path}" | |
echo 'cp "/etc/hosts" "/var/run/.add-localhost-domain.hosts"' >> "${script_path}" | |
echo 'mount --bind "/var/run/.add-localhost-domain.hosts" "/etc/hosts"' >> "${script_path}" | |
#### | |
echo 'echo "" >> "/var/run/.add-localhost-domain.hosts"' >> "${script_path}" | |
echo 'echo "# Added by add-localhost-domain.sh" >> "/var/run/.add-localhost-domain.hosts"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'case "${new_hostname_proto}" in' >> "${script_path}" | |
echo '"4")' >> "${script_path}" | |
echo 'echo "127.0.0.1 ${new_hostname}" >> "/var/run/.add-localhost-domain.hosts"' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo '"6")' >> "${script_path}" | |
echo 'echo "::1 ${new_hostname}" >> "/var/run/.add-localhost-domain.hosts"' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo '"46")' >> "${script_path}" | |
echo 'echo "127.0.0.1 ${new_hostname}" >> "/var/run/.add-localhost-domain.hosts"' >> "${script_path}" | |
echo 'echo "::1 ${new_hostname}" >> "/var/run/.add-localhost-domain.hosts"' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo 'esac' >> "${script_path}" | |
#### | |
echo 'restart_script "${0}" 0' >> "${script_path}" | |
create_shortcut 'add-localhost-domain.desktop' \ | |
'console-application' \ | |
'Add localhost domain' \ | |
"${script_path}" \ | |
'application-x-remote-connection' | |
chown 'root:root' "${script_path}" | |
chmod 755 "${script_path}" | |
} | |
install__apache_helpers() | |
{ | |
local script_path='/usr/local/sbin/a2distmp' | |
echo '#!/bin/sh' > "${script_path}" | |
#### | |
echo 'if [ ! "$(whoami)" = "root" ]; then' >> "${script_path}" | |
echo 'echo "No superuser"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if [ "${0##*/}" = "a2distmp" ]; then' >> "${script_path}" | |
echo 'if [ ! -e "/var/run/.a2enconf-tmp" ]; then' >> "${script_path}" | |
echo 'echo "Error: no overlay was used"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'for i in "conf-enabled" "mods-enabled" "sites-enabled"; do' >> "${script_path}" | |
echo 'if mountpoint -q "/etc/apache2/${i}" > /dev/null 2>&1; then' >> "${script_path}" | |
echo 'echo " -> /etc/apache2/${i}"' >> "${script_path}" | |
echo 'umount "/etc/apache2/${i}"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
#### | |
echo 'for i in /var/run/.a2enconf-tmp/*; do' >> "${script_path}" | |
echo '[ "${i}" = "/var/run/.a2enconf-tmp/*" ] && break' >> "${script_path}" | |
echo 'i="${i##*/}"' >> "${script_path}" | |
#### | |
echo 'echo " -> ${i}"' >> "${script_path}" | |
echo 'umount "/var/run/.a2enconf-tmp/${i}/lower"' >> "${script_path}" | |
echo 'rmdir "/var/run/.a2enconf-tmp/${i}/lower"' >> "${script_path}" | |
echo 'rm -r -f "/var/run/.a2enconf-tmp/${i}/diff"' >> "${script_path}" | |
echo 'rm -r -f "/var/run/.a2enconf-tmp/${i}/tmp"' >> "${script_path}" | |
echo 'rmdir "/var/run/.a2enconf-tmp/${i}"' >> "${script_path}" | |
echo 'done' >> "${script_path}" | |
#### | |
echo 'echo ""' >> "${script_path}" | |
echo 'echo "Restart apache!"' >> "${script_path}" | |
echo 'exit 0' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'case "${0##*/}" in' >> "${script_path}" | |
echo '"a2enconf-tmp"|"a2disconf-tmp")' >> "${script_path}" | |
echo 'script_name="a2enconf"' >> "${script_path}" | |
echo 'data_dir="conf-enabled"' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo '"a2enmod-tmp"|"a2dismod-tmp")' >> "${script_path}" | |
echo 'script_name="a2enmod"' >> "${script_path}" | |
echo 'data_dir="mods-enabled"' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo '"a2ensite-tmp"|"a2dissite-tmp")' >> "${script_path}" | |
echo 'script_name="a2ensite"' >> "${script_path}" | |
echo 'data_dir="sites-enabled"' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo '*)' >> "${script_path}" | |
echo 'echo "Error: I dont know what you are doing"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo 'esac' >> "${script_path}" | |
#### | |
echo 'if [ ! -e "/var/run/.a2enconf-tmp/${script_name}" ]; then' >> "${script_path}" | |
echo 'if ! /sbin/modinfo overlay > /dev/null 2>&1; then' >> "${script_path}" | |
echo 'echo "Error: overlay fs driver is not available"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if [ ! -e "/etc/apache2/${data_dir}" ]; then' >> "${script_path}" | |
echo 'echo "Error: /etc/apache2/${data_dir} does not exist"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if [ ! -e "/var/run/.a2enconf-tmp" ]; then' >> "${script_path}" | |
echo 'mkdir "/var/run/.a2enconf-tmp"' >> "${script_path}" | |
echo 'mount \' >> "${script_path}" | |
echo '-t tmpfs \' >> "${script_path}" | |
echo '-o "nodev,nosuid,noexec,uid=root,gid=root,mode=0711" \' >> "${script_path}" | |
echo '"apache-overlay" \' >> "${script_path}" | |
echo '"/var/run/.a2enconf-tmp"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'mkdir "/var/run/.a2enconf-tmp/${script_name}"' >> "${script_path}" | |
echo 'mkdir "/var/run/.a2enconf-tmp/${script_name}/lower"' >> "${script_path}" | |
echo 'mkdir "/var/run/.a2enconf-tmp/${script_name}/diff"' >> "${script_path}" | |
echo 'mkdir "/var/run/.a2enconf-tmp/${script_name}/tmp"' >> "${script_path}" | |
#### | |
echo 'mount \' >> "${script_path}" | |
echo '--bind --make-rslave \' >> "${script_path}" | |
echo '"/etc/apache2/${data_dir}" \' >> "${script_path}" | |
echo '"/var/run/.a2enconf-tmp/${script_name}/lower"' >> "${script_path}" | |
#### | |
echo 'if ! mount \' >> "${script_path}" | |
echo '-t overlay \' >> "${script_path}" | |
echo '-o "lowerdir=/var/run/.a2enconf-tmp/${script_name}/lower,upperdir=/var/run/.a2enconf-tmp/${script_name}/diff,workdir=/var/run/.a2enconf-tmp/${script_name}/tmp" \' >> "${script_path}" | |
echo '"apache-${script_name}-overlay" \' >> "${script_path}" | |
echo '"/etc/apache2/${data_dir}"' >> "${script_path}" | |
echo 'then' >> "${script_path}" | |
echo 'echo "Error: overlay mount failed"' >> "${script_path}" | |
#### | |
echo 'umount "/var/run/.a2enconf-tmp/${script_name}/lower"' >> "${script_path}" | |
echo 'rmdir "/var/run/.a2enconf-tmp/${script_name}/lower"' >> "${script_path}" | |
echo 'rmdir "/var/run/.a2enconf-tmp/${script_name}/diff"' >> "${script_path}" | |
echo 'rmdir "/var/run/.a2enconf-tmp/${script_name}/tmp"' >> "${script_path}" | |
echo 'rmdir "/var/run/.a2enconf-tmp/${script_name}"' >> "${script_path}" | |
#### | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'script_name="${0##*/}"' >> "${script_path}" | |
echo 'exec "${script_name%-tmp}" ${@}' >> "${script_path}" | |
chown 'root:root' "${script_path}" | |
chmod 755 "${script_path}" | |
local i | |
for i in 'a2enconf-tmp' 'a2disconf-tmp' 'a2enmod-tmp' 'a2dismod-tmp' 'a2ensite-tmp' 'a2dissite-tmp'; do | |
ln -s "./${script_path##*/}" "${script_path%/*}/${i}" | |
done | |
} | |
install__apache_nginx_switcher() | |
{ | |
local script_path='/usr/local/bin/switch-apache-nginx.sh' | |
echo '#!/bin/sh' > "${script_path}" | |
#### | |
echo 'sudo service nginx status > /dev/null 2>&1 && (echo "Switching to Apache2" && sudo service nginx stop && sudo service apache2 start) || (echo "Switching to nginx" && sudo service apache2 stop && sudo service nginx start)' >> "${script_path}" | |
#### | |
echo 'echo "[OK]"' >> "${script_path}" | |
echo 'sleep 1' >> "${script_path}" | |
#### | |
echo 'exit 0' >> "${script_path}" | |
create_shortcut 'switch-apache-nginx.desktop' \ | |
'console-application' \ | |
'Switch Apache2-nginx' \ | |
"${script_path}" \ | |
'system-reboot' | |
chown 'root:root' "${script_path}" | |
chmod 755 "${script_path}" | |
} | |
install__cpsum() | |
{ | |
local repo_owner='MissKittin' | |
local repo_id='c1dcb84bac5f5589759750b5dffef11d' | |
local download_dir=$(mktemp -d) | |
local i | |
for i in 1 2 3; do | |
if wget -O "${download_dir}/cpsum.sh" "https://gist.githubusercontent.com/${repo_owner}/${repo_id}/raw/cpsum.sh"; then | |
mv "${download_dir}/cpsum.sh" '/usr/local/bin/cpsum.sh' | |
chown 'root:root' '/usr/local/bin/cpsum.sh' | |
chmod 755 '/usr/local/bin/cpsum.sh' | |
break | |
fi | |
done | |
rm -r -f "${download_dir}" | |
} | |
install__debootstrap_quick() | |
{ | |
local repo_owner='MissKittin' | |
local repo_id='fff3318051861c3fc017c99100d3c431' | |
install_packages wget ca-certificates | |
local i | |
for i in 1 2 3; do | |
if wget -O '/usr/local/sbin/debootstrap-quick.pl' "https://gist.githubusercontent.com/${repo_owner}/${repo_id}/raw/debootstrap-quick.pl"; then | |
chown 'root:root' '/usr/local/sbin/debootstrap-quick.pl' | |
chmod 755 '/usr/local/sbin/debootstrap-quick.pl' | |
break | |
fi | |
done | |
} | |
install__docker_helpers() | |
{ | |
local repo_owner='MissKittin' | |
local repo_name='docker-lab' | |
local repo_branch='master' | |
local script | |
local i | |
install_packages wget ca-certificates | |
for script in 'factory-reset' 'import-image' 'volume-import-export'; do | |
for i in 1 2 3; do | |
if wget -O "/usr/local/bin/docker-${script}.sh" "https://github.com/${repo_owner}/${repo_name}/raw/${repo_branch}/bin/${script}.sh"; then | |
chown 'root:root' "/usr/local/bin/docker-${script}.sh" | |
chmod 755 "/usr/local/bin/docker-${script}.sh" | |
break | |
fi | |
done | |
done | |
} | |
install__git_toolbox() | |
{ | |
local repo_owner='MissKittin' | |
local repo_id='43afece541d33ae0dced35decc6aabea' | |
install_packages wget ca-certificates openssh-client gpg gpg-agent | |
local i | |
for i in 1 2 3; do | |
if wget -O "${HOME}/git-toolbox.sh" "https://gist.githubusercontent.com/${repo_owner}/${repo_id}/raw/git-toolbox.sh"; then | |
mkdir "${HOME}/git" | |
mv "${HOME}/git-toolbox.sh" "${HOME}/git/git-toolbox.sh" | |
chmod 755 "${HOME}/git/git-toolbox.sh" | |
"${HOME}/git/git-toolbox.sh" generate-config --without-keys | |
chmod 700 "${HOME}/git/git-toolbox.sh" | |
chmod 711 "${HOME}/git/.git-toolbox.conf" | |
chmod 600 "${HOME}/git/.git-toolbox.conf/git-toolbox.conf" | |
chown -R "${username}:${username}" "${HOME}/git" | |
echo '' >> "${HOME}/git/.git-toolbox.conf/git-toolbox.conf" | |
echo '# After completing the above details, you can generate SSH keys: run in this directory' >> "${HOME}/git/.git-toolbox.conf/git-toolbox.conf" | |
echo '# ../git-toolbox.sh generate-ssh-keys' >> "${HOME}/git/.git-toolbox.conf/git-toolbox.conf" | |
echo '# and GPG keys' >> "${HOME}/git/.git-toolbox.conf/git-toolbox.conf" | |
echo '# ../git-toolbox.sh generate-gpg-keys' >> "${HOME}/git/.git-toolbox.conf/git-toolbox.conf" | |
break | |
fi | |
done | |
} | |
install__luks_container() | |
{ | |
local repo_owner='MissKittin' | |
local repo_id='963ca1e94fc66d403523bd67696a23f6' | |
local download_dir=$(mktemp -d) | |
install_packages wget ca-certificates | |
local i | |
for i in 1 2 3; do | |
if wget -O "${download_dir}/lesslinux-luks-container.sh" "https://gist.githubusercontent.com/${repo_owner}/${repo_id}/raw/lesslinux-luks-container.sh"; then | |
local script_path='/usr/local/bin/luks-container.sh' | |
install_packages cryptsetup | |
echo '#!/bin/bash' > "${script_path}" | |
#### | |
echo 'if [ ! "$(whoami)" = 'root' ]; then' >> "${script_path}" | |
echo 'echo "I am not root"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
cat "${download_dir}/lesslinux-luks-container.sh" >> "${script_path}" | |
#### | |
echo '# . "/usr/local/share/luks-container/lesslinux-luks-container.rc" || exit 1' >> "${script_path}" | |
#### | |
echo 'exit_code="1"' >> "${script_path}" | |
echo 'case "${1}" in' >> "${script_path}" | |
echo '"create")' >> "${script_path}" | |
echo 'if [ "${5}" = "" ]; then' >> "${script_path}" | |
echo 'echo "${0##*/} create file-name file-size size-unit dm-name"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'if [ -e "${2}" ]; then' >> "${script_path}" | |
echo 'echo "${2} already exists"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'if [ "${3}" -lt "1" ]; then' >> "${script_path}" | |
echo 'echo "File size is lower than 1"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'if [ "${4}" = "M" ] && [ "${3}" -lt "17" ]; then' >> "${script_path}" | |
echo 'echo "File size is lower than 17 MB"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'if [ -e "/dev/mapper/${5}" ]; then' >> "${script_path}" | |
echo 'echo "/dev/mapper/${5} is already opened"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if luks_create_container "${2}" "${3}" "${4}" && luks_setup "${2}"; then' >> "${script_path}" | |
echo 'luks_open "${2}" "${5}"' >> "${script_path}" | |
echo 'mkfs.ext4 "/dev/mapper/${5}"' >> "${script_path}" | |
echo 'luks_close "${5}"' >> "${script_path}" | |
echo 'exit_code="0"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo '"open")' >> "${script_path}" | |
echo 'if [ "${3}" = "" ]; then' >> "${script_path}" | |
echo 'echo "${0##*/} open file-name dm-name"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'if [ -e "/dev/mapper/${2}" ]; then' >> "${script_path}" | |
echo 'echo "/dev/mapper/${2} is already opened"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'is_luks_container "${2}" && luks_open "${2}" "${3}" && if mkdir "/media/luks-${3}"; then' >> "${script_path}" | |
echo 'mount "/dev/mapper/${3}" "/media/luks-${3}" && echo "Mounted on /media/luks-${3}" || rmdir "/media/luks-${3}"' >> "${script_path}" | |
echo 'exit_code="${?}"' >> "${script_path}" | |
echo 'else' >> "${script_path}" | |
echo 'luks_close "${3}"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo '"close")' >> "${script_path}" | |
echo 'if [ "${2}" = "" ]; then' >> "${script_path}" | |
echo 'echo "${0##*/} close dm-name"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'if [ ! -e "/dev/mapper/${2}" ]; then' >> "${script_path}" | |
echo 'echo "/dev/mapper/${2} is not opened"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if umount "/media/luks-${2}"; then' >> "${script_path}" | |
echo 'luks_close "${2}"' >> "${script_path}" | |
echo 'rmdir "/media/luks-${2}"' >> "${script_path}" | |
echo 'exit_code="${?}"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo '*)' >> "${script_path}" | |
echo 'echo "${0##*/} create file-name file-size size-unit dm-name"' >> "${script_path}" | |
echo 'echo " where size-unit is M or G"' >> "${script_path}" | |
echo 'echo " note: file cannot be smaller than 17MB"' >> "${script_path}" | |
echo 'echo "${0##*/} open file-name dm-name"' >> "${script_path}" | |
echo 'echo "${0##*/} close dm-name"' >> "${script_path}" | |
echo ';;' >> "${script_path}" | |
echo 'esac' >> "${script_path}" | |
#### | |
echo 'exit "${exit_code}"' >> "${script_path}" | |
chown 'root:root' "${script_path}" | |
chmod 755 "${script_path}" | |
break | |
fi | |
done | |
rm -r -f "${download_dir}" | |
} | |
install__mount_smb() | |
{ | |
install_packages cifs-utils | |
local script_path='/usr/local/bin/mount-smb.sh' | |
echo '#!/bin/bash' > "${script_path}" | |
#### | |
echo 'if [ ! "$(whoami)" = "root" ]; then' >> "${script_path}" | |
echo 'echo " This script helps you mount an SMB network share."' >> "${script_path}" | |
echo 'echo " Answer the questions:"' >> "${script_path}" | |
echo 'echo ""' >> "${script_path}" | |
#### | |
echo 'sudo "${0}" "$(whoami)"' >> "${script_path}" | |
echo 'exit 0' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'do_exit()' >> "${script_path}" | |
echo '{' >> "${script_path}" | |
echo 'local exit_code="0"' >> "${script_path}" | |
echo '[ ! "${2}" = "" ] && exit_code="${2}"' >> "${script_path}" | |
#### | |
echo '[ ! "${1}" = "" ] && echo "${1}"' >> "${script_path}" | |
echo 'echo ""' >> "${script_path}" | |
echo 'echo -n "Press [ENTER]"' >> "${script_path}" | |
echo 'read enter' >> "${script_path}" | |
#### | |
echo 'exit "${exit_code}"' >> "${script_path}" | |
echo '}' >> "${script_path}" | |
#### | |
echo '[ ! -e "/media/smb" ] && mkdir "/media/smb"' >> "${script_path}" | |
#### | |
echo 'ipv4defaultgw="$(ip -4 route | grep "^default via " | awk "{print \$3}")"' >> "${script_path}" | |
echo 'ipv6defaultgw="$(ip -6 route | grep "^default via " | awk "{print \$3}")"' >> "${script_path}" | |
echo 'defaultgw=""' >> "${script_path}" | |
echo '[ ! "${ipv6defaultgw}" = "" ] && defaultgw="${ipv6defaultgw}"' >> "${script_path}" | |
echo '[ ! "${ipv4defaultgw}" = "" ] && defaultgw="${ipv4defaultgw}"' >> "${script_path}" | |
#### | |
echo 'additional_options=""' >> "${script_path}" | |
echo 'echo -n "Server address"' >> "${script_path}" | |
echo '[ ! "${defaultgw}" = "" ] && echo -n " [${defaultgw}]: " || echo -n ": "' >> "${script_path}" | |
echo 'read address' >> "${script_path}" | |
echo 'echo -n "Share name: "; read share' >> "${script_path}" | |
echo 'echo -n "User name (optional): "; read username' >> "${script_path}" | |
echo 'echo -n "Password (optional): "; read -s password; echo ""' >> "${script_path}" | |
echo 'echo -n "Additional mount options: "; read additional_options;' >> "${script_path}" | |
echo 'echo ""' >> "${script_path}" | |
#### | |
echo '[ "${address}" = "" ] && [ ! "${defaultgw}" = "" ] && address="${defaultgw}"' >> "${script_path}" | |
echo '[ "${address}" = "" ] && do_exit "Error: no server address given" 1' >> "${script_path}" | |
echo '[ "${share}" = "" ] && do_exit "Error: no share name given" 1' >> "${script_path}" | |
echo '[ ! "${username}" = "" ] && username="username=${username},"' >> "${script_path}" | |
echo '[ ! "${password}" = "" ] && password="password=${password},"' >> "${script_path}" | |
echo '[ ! "${additional_options}" = "" ] && additional_options=",${additional_options}"' >> "${script_path}" | |
#### | |
echo '[ ! -e "/media/smb/${address}-${share}" ] && mkdir "/media/smb/${address}-${share}"' >> "${script_path}" | |
#### | |
echo 'if mount -t cifs -o ${username}${password}file_mode=0644,dir_mode=0755,uid=${1},gid=${1}${additional_options} //${address}/${share} "/media/smb/${address}-${share}"; then' >> "${script_path}" | |
echo 'echo "[ OK ]"' >> "${script_path}" | |
echo 'else' >> "${script_path}" | |
echo 'echo "[FAIL]"' >> "${script_path}" | |
echo 'rmdir "/media/smb/${address}-${share}" > /dev/null 2>&1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'do_exit' >> "${script_path}" | |
create_shortcut 'mount-smb.desktop' \ | |
'console-application' \ | |
'Mount SMB/CIFS' \ | |
"${script_path}" \ | |
'folder-remote' | |
chown 'root:root' "${script_path}" | |
chmod 755 "${script_path}" | |
ln -s '/media/smb' "${HOME}/media-smb" | |
} | |
install__php_cli_docker() | |
{ | |
script_path='/usr/local/bin/php-cli-docker.sh' | |
echo '#!/bin/sh' > "${script_path}" | |
#### | |
echo 'if [ ! "$(whoami)" = "root" ]; then' >> "${script_path}" | |
echo 'sudo "${0}" "${1}" "${2}"' >> "${script_path}" | |
echo 'exit "${?}"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if [ "${1}" = "" ] || [ "${1}" = "-h" ] || [ "${1}" = "--help" ]; then' >> "${script_path}" | |
echo 'echo "Binds the current directory"' >> "${script_path}" | |
echo 'echo "and launches a shell in the docker container"' >> "${script_path}" | |
echo 'echo ""' >> "${script_path}" | |
echo 'echo "Usage: ${0##*/} php-version [distro]"' >> "${script_path}" | |
echo 'echo "eg: ${0##*/} 7.4"' >> "${script_path}" | |
echo 'echo "eg: ${0##*/} 7.4 bullseye"' >> "${script_path}" | |
echo 'echo "note: default distro is alpine"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if ! command -v "docker" > /dev/null 2>&1; then' >> "${script_path}" | |
echo 'echo -n "Install docker.io? (y/[N]) "' >> "${script_path}" | |
echo 'read answer' >> "${script_path}" | |
echo 'if [ "${answer}" = "y" ]; then' >> "${script_path}" | |
echo 'apt-get update' >> "${script_path}" | |
echo 'apt-get install --no-install-recommends -y docker.io' >> "${script_path}" | |
echo 'apt-get clean' >> "${script_path}" | |
echo 'else' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'distro="alpine"' >> "${script_path}" | |
echo '[ ! "${2}" = "" ] && distro="${2}"' >> "${script_path}" | |
#### | |
echo 'echo "Bound $(pwd) to /host"' >> "${script_path}" | |
#### | |
echo 'exec docker run --rm -it \' >> "${script_path}" | |
echo '-v "$(pwd):/host" \' >> "${script_path}" | |
echo '"php:${1}-cli-${distro}" \' >> "${script_path}" | |
echo 'sh' >> "${script_path}" | |
chown 'root:root' "${script_path}" | |
chmod 755 "${script_path}" | |
} | |
install__sh_libs() | |
{ | |
local includes_dir='/usr/local/share/shell-includes' | |
local script_path | |
mkdir -p "${includes_dir}" | |
chown 'root:root' "${includes_dir}" | |
chmod -s "${includes_dir}" | |
if [ ! -e "${HOME}/.bashrc" ]; then | |
echo -n '' > "${HOME}/.bashrc" | |
chown "${username}:${username}" "${HOME}/.bashrc" | |
else | |
echo '' >> "${HOME}/.bashrc" | |
fi | |
### .bashrc | |
script_path="${HOME}/.bashrc" | |
echo 'export LS_COLORS='"'"'rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:'"'" >> "${script_path}" | |
echo 'alias ls="ls --color=auto"' >> "${script_path}" | |
echo 'alias grep="grep --color=auto"' >> "${script_path}" | |
#echo 'alias dos2unix="busybox dos2unix"' >> "${script_path}" | |
#echo 'alias unix2dos="busybox unix2dos"' >> "${script_path}" | |
#echo 'alias vi="busybox vi"' >> "${script_path}" | |
echo -n 'include()' >> "${script_path}" | |
echo -n '{ ' >> "${script_path}" | |
echo -n 'local lib_path="'"${includes_dir}"'";' >> "${script_path}" | |
echo -n 'if [ "${1}" = "" ]; then ' >> "${script_path}" | |
echo -n 'echo "usage: include script_name";' >> "${script_path}" | |
echo -n 'echo "";' >> "${script_path}" | |
echo -n 'echo "Available libraries:";' >> "${script_path}" | |
echo -n 'local i;' >> "${script_path}" | |
echo -n 'for i in ${lib_path}/*; do ' >> "${script_path}" | |
echo -n '[ "${i}" = "${lib_path}/*" ] && break;' >> "${script_path}" | |
echo -n '[ -L "${i}" ] && continue;' >> "${script_path}" | |
echo -n 'i="${i##*/}";' >> "${script_path}" | |
echo -n 'echo " ${i%.*}";' >> "${script_path}" | |
echo -n 'done;' >> "${script_path}" | |
echo -n 'elif [ -e "${lib_path}/${1}.rc" ]; then ' >> "${script_path}" | |
echo -n '. "${lib_path}/${1}.rc";' >> "${script_path}" | |
echo -n 'echo "${1} included";' >> "${script_path}" | |
echo -n 'else ' >> "${script_path}" | |
echo -n 'echo "${1} not found";' >> "${script_path}" | |
echo -n 'fi;' >> "${script_path}" | |
echo -n '}' >> "${script_path}" | |
echo '' >> "${script_path}" | |
### find_broken_symlinks.rc | |
script_path="${includes_dir}/find_broken_symlinks.rc" | |
echo '# find_broken_symlinks [--raw-output]' > "${script_path}" | |
echo -n 'find_broken_symlinks()' >> "${script_path}" | |
echo -n '{ ' >> "${script_path}" | |
echo -n 'if [ "${1}" = "--raw-output" ]; then ' >> "${script_path}" | |
echo -n 'LANG=C LC_ALL=C find ./ -type l -exec file {} \; | grep "broken symbolic link";' >> "${script_path}" | |
echo -n 'else ' >> "${script_path}" | |
echo -n 'local file;' >> "${script_path}" | |
echo -n 'find ./ -type l | while read file; do ' >> "${script_path}" | |
echo -n 'LANG=C LC_ALL=C file "${file}" | grep "broken symbolic link" > /dev/null 2>&1 && echo "${file}";' >> "${script_path}" | |
echo -n 'done;' >> "${script_path}" | |
echo -n 'unset file;' >> "${script_path}" | |
echo -n 'fi;' >> "${script_path}" | |
echo -n '}' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo 'alias find-broken-symlinks="find_broken_symlinks"' >> "${script_path}" | |
ln -s 'find_broken_symlinks.rc' "${includes_dir}/find-broken-symlinks.rc" | |
### find_binary_files.rc | |
script_path="${includes_dir}/find_binary_files.rc" | |
echo 'alias find_binary_files="find . -type f ! -size 0 -exec grep -IL . \"{}\" \;"' > "${script_path}" | |
echo 'alias find-binary-files="find . -type f ! -size 0 -exec grep -IL . \"{}\" \;"' >> "${script_path}" | |
ln -s 'find_binary_files.rc' "${includes_dir}/find-binary-files.rc" | |
### create_gitkeep_recursive.rc | |
script_path="${includes_dir}/create_gitkeep_recursive.rc" | |
echo '# find empty directories and create empty .gitkeep files' > "${script_path}" | |
echo -n 'create_gitkeep_recursive()' >> "${script_path}" | |
echo -n '{ ' >> "${script_path}" | |
echo -n 'local line;' >> "${script_path}" | |
echo -n 'find -type d -empty | while read line; do ' >> "${script_path}" | |
echo -n '[ ! -e "${line}/.gitkeep" ] && echo "${line}/.gitkeep" && echo -n "" > "${line}/.gitkeep";' >> "${script_path}" | |
echo -n 'done;' >> "${script_path}" | |
echo -n '}' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo 'alias create-gitkeep-recursive="create_gitkeep_recursive"' >> "${script_path}" | |
ln -s 'create_gitkeep_recursive.rc' "${includes_dir}/create-gitkeep-recursive.rc" | |
### find_by_modified_date.rc | |
script_path="${includes_dir}/find_by_modified_date.rc" | |
echo '# output: YYYY-MM-DD HH:MM:SS FILE_PATH' > "${script_path}" | |
echo 'alias find-by-modified-date="find . -type f -printf \"%TF %.8TX %p\n\" | sort -n"' >> "${script_path}" | |
echo 'alias find-by-modified-date-no-spaces="find . -type f -printf \"%TF_%.8TX %p\n\" | sort -n"' >> "${script_path}" | |
ln -s 'find_by_modified_date.rc' "${includes_dir}/find-by-modified-date.rc" | |
### search_for.rc | |
script_path="${includes_dir}/search_for.rc" | |
echo '# search "string" in all files' > "${script_path}" | |
echo -n 'search_for()' >> "${script_path}" | |
echo -n '{ ' >> "${script_path}" | |
echo -n 'if [ "${1}" = "" ]; then ' >> "${script_path}" | |
echo -n 'echo "search_for string";' >> "${script_path}" | |
echo -n 'return 1;' >> "${script_path}" | |
echo -n 'fi;' >> "${script_path}" | |
echo -n 'find -type f | while read line; do ' >> "${script_path}" | |
echo -n 'cat "${line}" | grep "${1}" > /dev/null 2>&1 && echo "Found in ${line}";' >> "${script_path}" | |
echo -n 'done;' >> "${script_path}" | |
echo -n '}' >> "${script_path}" | |
echo '' >> "${script_path}" | |
echo 'alias search-for="search_for"' >> "${script_path}" | |
ln -s 'search_for.rc' "${includes_dir}/search-for.rc" | |
### urandom_string.rc | |
script_path="${includes_dir}/urandom_string.rc" | |
echo '# generate random alphanumeric string' > "${script_path}" | |
echo '# urandom_string string-length-int-number [-n]' >> "${script_path}" | |
echo -n 'urandom_string()' >> "${script_path}" | |
echo -n '{ ' >> "${script_path}" | |
echo -n 'if [ "${1}" = "" ]; then ' >> "${script_path}" | |
echo -n 'echo "urandom_string string-length [-n]";' >> "${script_path}" | |
echo -n 'return 1;' >> "${script_path}" | |
echo -n 'fi;' >> "${script_path}" | |
echo -n 'cat "/dev/urandom" | tr -dc "a-zA-Z0-9" | head -c "${1}";' >> "${script_path}" | |
echo -n '[ ! "${2}" = "-n" ] && echo '';' >> "${script_path}" | |
echo -n '}' >> "${script_path}" >> "${script_path}" | |
echo '' >> "${script_path}" >> "${script_path}" | |
echo 'alias urandom-string="urandom_string"' >> "${script_path}" | |
ln -s 'urandom_string.rc' "${includes_dir}/urandom-string.rc" | |
[ -L "${HOME}/.bash_history" ] && mv "${HOME}/.bash_history" "${HOME}/.bash_history.old" | |
} | |
install__lorem_ipsum_generator() | |
{ | |
local repo_owner='MissKittin' | |
local repo_id='521436fecf92efd7c1d8f4486eced624' | |
install_packages wget ca-certificates | |
mkdir -p '/usr/local/share/lorem-ipsum-generator' | |
chown 'root:root' '/usr/local/share/lorem-ipsum-generator' | |
chmod -s '/usr/local/share/lorem-ipsum-generator' | |
local i | |
for i in 1 2 3; do | |
if wget -O '/usr/local/share/lorem-ipsum-generator/index.html' "https://gist.githubusercontent.com/${repo_owner}/${repo_id}/raw/js-lorem-ipsum-generator.html"; then | |
create_shortcut 'lorem-ipsum-generator.desktop' \ | |
'link' \ | |
'Lorem ipsum' \ | |
'/usr/local/share/lorem-ipsum-generator/index.html' \ | |
'text-html' | |
break | |
else | |
rmdir '/usr/local/share/lorem-ipsum-generator' | |
fi | |
done | |
} | |
install__nginx_overlay() | |
{ | |
local script_path='/usr/local/bin/nginx-overlay.sh' | |
echo '#!/bin/sh' > "${script_path}" | |
echo 'overlay_start()' >> "${script_path}" | |
echo '{' >> "${script_path}" | |
echo 'if [ -e "/var/run/.nginx-overlay" ]; then' >> "${script_path}" | |
echo 'echo "Error (start): /var/run/.nginx-overlay already exists"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'mkdir "/var/run/.nginx-overlay"' >> "${script_path}" | |
echo 'mount \' >> "${script_path}" | |
echo '-t tmpfs \' >> "${script_path}" | |
echo '-o "nodev,nosuid,noexec,mode=0755" \' >> "${script_path}" | |
echo '"nginx-overlay" \' >> "${script_path}" | |
echo '"/var/run/.nginx-overlay"' >> "${script_path}" | |
#### | |
echo 'mkdir "/var/run/.nginx-overlay/lower"' >> "${script_path}" | |
echo 'mkdir "/var/run/.nginx-overlay/diff"' >> "${script_path}" | |
echo 'mkdir "/var/run/.nginx-overlay/tmp"' >> "${script_path}" | |
#### | |
echo 'mount \' >> "${script_path}" | |
echo '--bind --make-rslave \' >> "${script_path}" | |
echo '"/etc/nginx" \' >> "${script_path}" | |
echo '"/var/run/.nginx-overlay/lower"' >> "${script_path}" | |
#### | |
echo 'if ! mount \' >> "${script_path}" | |
echo '-t overlay \' >> "${script_path}" | |
echo '-o "lowerdir=/var/run/.nginx-overlay/lower,upperdir=/var/run/.nginx-overlay/diff,workdir=/var/run/.nginx-overlay/tmp" \' >> "${script_path}" | |
echo '"nginx-overlay" \' >> "${script_path}" | |
echo '"/etc/nginx"' >> "${script_path}" | |
echo 'then' >> "${script_path}" | |
echo 'overlay_stop' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if [ -e "/usr/local/etc/nginx" ] && ! mountpoint -q "/usr/local/etc/nginx"; then' >> "${script_path}" | |
echo 'mkdir "/var/run/.nginx-overlay/usr-etc"' >> "${script_path}" | |
echo 'mkdir "/var/run/.nginx-overlay/usr-etc/lower"' >> "${script_path}" | |
echo 'mkdir "/var/run/.nginx-overlay/usr-etc/diff"' >> "${script_path}" | |
echo 'mkdir "/var/run/.nginx-overlay/usr-etc/tmp"' >> "${script_path}" | |
#### | |
echo 'mount \' >> "${script_path}" | |
echo '--bind --make-rslave \' >> "${script_path}" | |
echo '"/usr/local/etc/nginx" \' >> "${script_path}" | |
echo '"/var/run/.nginx-overlay/usr-etc/lower"' >> "${script_path}" | |
#### | |
echo 'mount \' >> "${script_path}" | |
echo '-t overlay \' >> "${script_path}" | |
echo '-o "lowerdir=/var/run/.nginx-overlay/usr-etc/lower,upperdir=/var/run/.nginx-overlay/usr-etc/diff,workdir=/var/run/.nginx-overlay/usr-etc/tmp" \' >> "${script_path}" | |
echo '"nginx-overlay" \' >> "${script_path}" | |
echo '"/usr/local/etc/nginx"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo '}' >> "${script_path}" | |
echo 'overlay_stop()' >> "${script_path}" | |
echo '{' >> "${script_path}" | |
echo 'if [ ! -e "/var/run/.nginx-overlay" ]; then' >> "${script_path}" | |
echo 'echo "Error (stop): /var/run/.nginx-overlay does not exist"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if [ -e "/usr/local/etc/nginx" ] && mountpoint -q "/usr/local/etc/nginx"; then' >> "${script_path}" | |
echo 'umount "/usr/local/etc/nginx"' >> "${script_path}" | |
echo 'umount "/var/run/.nginx-overlay/usr-etc/lower"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'umount "/etc/nginx"' >> "${script_path}" | |
echo 'umount "/var/run/.nginx-overlay/lower"' >> "${script_path}" | |
echo 'umount "/var/run/.nginx-overlay"' >> "${script_path}" | |
echo 'rmdir "/var/run/.nginx-overlay"' >> "${script_path}" | |
echo '}' >> "${script_path}" | |
echo 'overlay_status()' >> "${script_path}" | |
echo '{' >> "${script_path}" | |
echo '[ ! -e "/var/run/.nginx-overlay" ] && return 1' >> "${script_path}" | |
echo 'return 0' >> "${script_path}" | |
echo '}' >> "${script_path}" | |
#### | |
echo 'if [ "$(whoami)" = "root" ]; then' >> "${script_path}" | |
echo 'if ! /sbin/modinfo overlay > /dev/null 2>&1; then' >> "${script_path}" | |
echo 'echo "Error: overlay fs driver is not available"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if [ ! -e "/etc/nginx" ]; then' >> "${script_path}" | |
echo 'echo "Error: /etc/nginx does not exist"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if overlay_status; then' >> "${script_path}" | |
echo 'overlay_stop' >> "${script_path}" | |
echo 'else' >> "${script_path}" | |
echo 'overlay_start' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'else' >> "${script_path}" | |
echo 'echo -n " /etc/nginx is currently in "' >> "${script_path}" | |
echo 'overlay_status && echo -n "temporary" || echo -n "normal"' >> "${script_path}" | |
echo 'echo " mode"' >> "${script_path}" | |
echo 'echo ""' >> "${script_path}" | |
#### | |
echo 'sudo "${0}"' >> "${script_path}" | |
echo 'exit "$?"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'echo ""' >> "${script_path}" | |
echo 'echo -n "Press [ENTER]"' >> "${script_path}" | |
echo 'read enter' >> "${script_path}" | |
#### | |
echo 'exit 0' >> "${script_path}" | |
chown 'root:root' "${script_path}" | |
chmod 755 "${script_path}" | |
create_shortcut 'nginx-overlay.desktop' \ | |
'console-application' \ | |
'/etc/nginx tmpfs overlay' \ | |
"${script_path}" \ | |
'media-removable' | |
} | |
install__var_www_overlay() | |
{ | |
local script_path='/usr/local/bin/var-www-overlay.sh' | |
echo '#!/bin/sh' > "${script_path}" | |
echo 'overlay_start()' >> "${script_path}" | |
echo '{' >> "${script_path}" | |
echo 'if [ -e "/var/run/.var-www-overlay" ]; then' >> "${script_path}" | |
echo 'echo "Error (start): /var/run/.var-www-overlay already exists"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'mkdir "/var/run/.var-www-overlay"' >> "${script_path}" | |
echo 'mount \' >> "${script_path}" | |
echo '-t tmpfs \' >> "${script_path}" | |
echo '-o "nodev,nosuid,noexec,uid=www-data,gid=www-data,mode=0755" \' >> "${script_path}" | |
echo '"var-www-overlay" \' >> "${script_path}" | |
echo '"/var/run/.var-www-overlay"' >> "${script_path}" | |
#### | |
echo 'mkdir "/var/run/.var-www-overlay/lower"' >> "${script_path}" | |
echo 'mkdir "/var/run/.var-www-overlay/diff"' >> "${script_path}" | |
echo 'mkdir "/var/run/.var-www-overlay/tmp"' >> "${script_path}" | |
#### | |
echo 'mount \' >> "${script_path}" | |
echo '--bind --make-rslave \' >> "${script_path}" | |
echo '"/var/www" \' >> "${script_path}" | |
echo '"/var/run/.var-www-overlay/lower"' >> "${script_path}" | |
#### | |
echo 'var_www_owner="$(stat -c %u /var/www):$(stat -c %g /var/www)"' >> "${script_path}" | |
#### | |
echo 'if ! mount \' >> "${script_path}" | |
echo '-t overlay \' >> "${script_path}" | |
echo '-o "lowerdir=/var/run/.var-www-overlay/lower,upperdir=/var/run/.var-www-overlay/diff,workdir=/var/run/.var-www-overlay/tmp" \' >> "${script_path}" | |
echo '"var-www-overlay" \' >> "${script_path}" | |
echo '"/var/www"' >> "${script_path}" | |
echo 'then' >> "${script_path}" | |
echo 'overlay_stop' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'chown "${var_www_owner}" "/var/www"' >> "${script_path}" | |
echo 'chmod 755 "/var/www"' >> "${script_path}" | |
echo '}' >> "${script_path}" | |
echo 'overlay_stop()' >> "${script_path}" | |
echo '{' >> "${script_path}" | |
echo 'if [ ! -e "/var/run/.var-www-overlay" ]; then' >> "${script_path}" | |
echo 'echo "Error (stop): /var/run/.var-www-overlay does not exist"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'umount "/var/www"' >> "${script_path}" | |
echo 'umount "/var/run/.var-www-overlay/lower"' >> "${script_path}" | |
echo 'umount "/var/run/.var-www-overlay"' >> "${script_path}" | |
echo 'rmdir "/var/run/.var-www-overlay"' >> "${script_path}" | |
echo '}' >> "${script_path}" | |
echo 'overlay_status()' >> "${script_path}" | |
echo '{' >> "${script_path}" | |
echo '[ ! -e "/var/run/.var-www-overlay" ] && return 1' >> "${script_path}" | |
echo 'return 0' >> "${script_path}" | |
echo '}' >> "${script_path}" | |
#### | |
echo 'if [ "$(whoami)" = "root" ]; then' >> "${script_path}" | |
echo 'if ! /sbin/modinfo overlay > /dev/null 2>&1; then' >> "${script_path}" | |
echo 'echo "Error: overlay fs driver is not available"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if [ ! -e "/var/www" ]; then' >> "${script_path}" | |
echo 'echo "Error: /var/www does not exist"' >> "${script_path}" | |
echo 'exit 1' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'if overlay_status; then' >> "${script_path}" | |
echo 'overlay_stop' >> "${script_path}" | |
echo 'else' >> "${script_path}" | |
echo 'overlay_start' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
echo 'else' >> "${script_path}" | |
echo 'echo -n " /var/www is currently in "' >> "${script_path}" | |
echo 'overlay_status && echo -n "temporary" || echo -n "normal"' >> "${script_path}" | |
echo 'echo " mode"' >> "${script_path}" | |
echo 'echo ""' >> "${script_path}" | |
#### | |
echo 'sudo "${0}"' >> "${script_path}" | |
echo 'exit "$?"' >> "${script_path}" | |
echo 'fi' >> "${script_path}" | |
#### | |
echo 'echo ""' >> "${script_path}" | |
echo 'echo -n "Press [ENTER]"' >> "${script_path}" | |
echo 'read enter' >> "${script_path}" | |
#### | |
echo 'exit 0' >> "${script_path}" | |
chown 'root:root' "${script_path}" | |
chmod 755 "${script_path}" | |
create_shortcut 'var-www-overlay.desktop' \ | |
'console-application' \ | |
'/var/www tmpfs overlay' \ | |
"${script_path}" \ | |
'media-removable' | |
} | |
### Docs | |
install__html_css_reference() | |
{ | |
install_packages wget ca-certificates | |
mkdir -p '/usr/local/share/html-css-reference' | |
chown 'root:root' '/usr/local/share/html-css-reference' | |
chmod -s '/usr/local/share/html-css-reference' | |
local i | |
for i in 1 2 3; do | |
if wget -O '/usr/local/share/html-css-reference/reference.pdf' 'https://www.dcpehvpm.org/E-Content/BCA/BCA-II/Web%20Technology/the-complete-reference-html-css-fifth-edition.pdf'; then | |
create_shortcut 'HTML-CSS-reference.desktop' \ | |
'application' \ | |
'HTML CSS reference' \ | |
'evince /usr/local/share/html-css-reference/reference.pdf' \ | |
'help-contents' | |
break | |
else | |
rmdir '/usr/local/share/html-css-reference' | |
fi | |
done | |
} | |
### Main | |
packages_list=' | |
wget | |
veracrypt | |
lxqt_sudo | |
nonfree_repo | |
universe_repo | |
buster_backports_repo | |
bookworm_backports_repo | |
tango_icon_theme | |
apache | |
apache_modphp | |
nginx_phpfpm | |
nginx | |
lighttpd | |
lighttpd_phpfpm | |
binutils | |
bless | |
chromium | |
cryptsetup | |
curl | |
debootstrap | |
dos2unix | |
dpkg_dev | |
docker | |
ethtool | |
evince | |
fdisk_gdisk | |
fdupes | |
file | |
file_roller | |
filezilla | |
firefox | |
gcc_gpp | |
git | |
gnome_screenshot | |
gparted | |
htop | |
icewm_devtools_menu | |
inloop_sqlite_viewer | |
inotify_tools | |
isomaster_xorriso_syslinuxutils | |
joebeach_json_path_finder | |
jq | |
launcher_portainer | |
launcher_smtp4dev | |
libxmlutils | |
keepassxc | |
mc | |
memcached_phpmemcachedadmin | |
mirage | |
mousepad | |
mysql_phpmyadmin | |
mysql_overlay | |
net_tools | |
notepadqq | |
netcat | |
nodejs | |
lessc | |
php_phpbrew | |
postgresql_phppgadmin | |
postgresql_overlay | |
proftpd | |
putty | |
qemu | |
rclocal_message | |
redis_phpredisadmin | |
redis_gui | |
sassc | |
ssh | |
sqlite3 | |
sqlitebrowser | |
squashfs_tools | |
strace | |
stunnel | |
synaptic | |
tinycorelinux | |
tmux_vim | |
transmission | |
tree | |
thunar_archive_plugin | |
ucspi_tcp | |
vbox_additions | |
vinagre | |
x11vnc | |
xchm | |
xfce_taskmanager | |
add_localhost_domain | |
apache_helpers | |
apache_nginx_switcher | |
cpsum | |
debootstrap_quick | |
docker_helpers | |
git_toolbox | |
luks_container | |
mount_smb | |
php_cli_docker | |
sh_libs | |
lorem_ipsum_generator | |
nginx_overlay | |
var_www_overlay | |
html_css_reference | |
default_browser | |
' | |
if ! "${_script_sourced}"; then | |
if ! command -v wget > /dev/null 2>&1; then | |
install__wget | |
if ! command -v wget > /dev/null 2>&1; then | |
echo 'wget not installed' | |
exit 1 | |
fi | |
fi | |
if ! wget -O - -q 'http://ftp.debian.org/' > /dev/null 2>&1; then | |
echo 'No internet' | |
exit 1 | |
fi | |
if [ "${3}" = '' ]; then | |
if [ -f "$(dirname ${0})/build-dev-env.list" ]; then | |
echo "Using $(dirname ${0})/build-dev-env.list" | |
packages_list=$(cat $(dirname ${0})/build-dev-env.list) | |
fi | |
else | |
packages_list="${3}" | |
fi | |
for installer in ${packages_list}; do | |
echo '' | |
if set | grep "^install__${installer}" > /dev/null 2>&1; then | |
echo " -> installing package ${installer}" | |
install__${installer} | |
else | |
echo " -> package ${installer} is not defined" | |
fi | |
done | |
[ -e "${HOME}/.wget-hsts" ] && rm "${HOME}/.wget-hsts" | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment