72 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
#### Variables
APT_UPDATE="apt -y update"
APT_INST="apt --no-install-recommends -y install"
APT_PURGE="apt -y purge"
APT_REMOVE="apt -y autoremove"
PKG_DEPS="curl wget git php php-cli php-curl php-mbstring php-readline php-mysql php-pgsql php-sqlite3 php-xml php-zip php-intl"
BIN_DEPS=(composer)
#### Functions
check_root() {
if [ "$EUID" -ne 0 ]; then
echo "Must be root to run $0"
exit
fi
}
choice() {
echo -ne "[y/n]"
while true
do
read -rN1 input
case $input in
[yY][eE][sS]|[yY])
return 0
break
;;
[nN][oO]|[nN])
return 1
;;
esac
done
}
check_deps_pkg() {
for NAME in "${PKG_DEPS[@]}"
do
dpkg -s $NAME 2> /dev/null
CODE=$?
if ! [ "$CODE" -ne 1 ]; then
echo -ne "\nInstall $NAME ? "
if choice 2>/dev/null; then
echo -ne "\n$APT_INST $NAME\n"
$APT_INST $NAME
else
echo -ne "\n\nAbort install script, package $NAME is required for work $PKG_NAME.\n"
exit 1;
fi
fi
done
}
check_deps_bin() {
for NAME in "${BIN_DEPS[@]}"
do
if ! [ -x "$(command -v $NAME)" ]; then
echo "Error: $NAME is not installed. Please install $NAME before start this script." >&2
exit 1;
fi
done
}
#### Main
check_root
check_deps_bin
check_deps_pkg
echo -ne "\nNow is all ready for create new project, example:\n\ncomposer create-project codeigniter4/appstarter project-root\n"