Also check if sudo exists in run.sh

More distributions supported
Now supports OpenSUSE's default package manager
This commit is contained in:
Howard Wu 2022-09-23 16:31:12 +08:00
parent dca675e5f6
commit 9bf6f6ce1b
3 changed files with 61 additions and 20 deletions

View File

@ -14,11 +14,22 @@
- Recommended Use
- Ubuntu (You can use [WSL2](https://apps.microsoft.com/store/search?publisher=Canonical%20Group%20Limited))
`run.sh` will handle all dependencies automatically.
No need to type any commands.
Ready to use right out of the box.
- Debian (You can use [WSL2](https://apps.microsoft.com/store/detail/debian/9MSVKQC78PK6))
Need to add `contrib` sources to the source list to install winetricks.
- OpenSUSE (You can use [WSL2](https://apps.microsoft.com/store/search?publisher=SUSE))
Ready to use right out of the box.
`run.sh` will handle all dependencies automatically.
No need to type any commands.
- Other Distributions
Install the dependencies manually.
Use the command-line program `build.sh`.
## Features

View File

@ -39,6 +39,9 @@ DOWNLOAD_CONF_NAME=download.list
OUTPUT_DIR=../output
MOUNT_DIR="$WORK_DIR"/system
SUDO="$(which sudo 2>/dev/null)"
if [ -z "$SUDO" ]; then
unset SUDO
fi
umount_clean() {
if [ -d "$MOUNT_DIR" ]; then
echo "Cleanup Work Directory"
@ -277,15 +280,18 @@ if [ "$DEBUG" ]; then
fi
require_su() {
if test -z $SUDO && test $(whoami) != "root"; then
echo "ROOT/SUDO is required to run this script"
if test "$(whoami)" != "root"; then
if [ -z "$SUDO" ] && [ "$($SUDO whoami)" != "root" ]; then
echo "ROOT/SUDO is required to run this script"
abort
fi
fi
}
declare -A RELEASE_NAME_MAP=(["retail"]="Retail" ["RP"]="Release Preview" ["WIS"]="Insider Slow" ["WIF"]="Insider Fast")
RELEASE_NAME=${RELEASE_NAME_MAP[$RELEASE_TYPE]} || abort
echo -e "build: RELEASE_TYPE=$RELEASE_NAME"
echo -e "Build: RELEASE_TYPE=$RELEASE_NAME"
WSA_ZIP_PATH=$DOWNLOAD_DIR/wsa-$ARCH-$RELEASE_TYPE.zip
vclibs_PATH=$DOWNLOAD_DIR/vclibs-"$ARCH".appx
@ -803,10 +809,11 @@ if [ ! -d "$OUTPUT_DIR" ]; then
fi
if [ "$COMPRESS_OUTPUT" ]; then
rm -f "${OUTPUT_DIR:?}"/"$artifact_name.7z" || abort
7z a "$OUTPUT_DIR"/"$artifact_name.7z" "$WORK_DIR/wsa/$ARCH/" || abort
mv "$WORK_DIR/wsa/$ARCH" "$WORK_DIR/wsa/$artifact_name"
7z a "$OUTPUT_DIR"/"$artifact_name.7z" "$WORK_DIR/wsa/$artifact_name" || abort
else
rm -rf "${OUTPUT_DIR:?}/${artifact_name}" || abort
mv "$WORK_DIR"/wsa/"$ARCH" "$OUTPUT_DIR/$artifact_name" || abort
cp -r "$WORK_DIR"/wsa/"$ARCH" "$OUTPUT_DIR/$artifact_name" || abort
fi
echo -e "done\n"

View File

@ -26,15 +26,22 @@ if [ ! "$BASH_VERSION" ]; then
exit 1
fi
cd "$(dirname "$0")" || exit 1
SUDO="$(which sudo 2>/dev/null)"
abort() {
echo "Dependencies: an error has occurred, exit"
exit 1
}
require_su() {
if test "$(whoami)" != "root"; then
if [ -z "$SUDO" ] && [ "$($SUDO whoami)" != "root" ]; then
echo "ROOT/SUDO is required to run this script"
abort
fi
fi
}
echo "Checking and ensuring dependencies"
check_dependencies() {
command -v whiptail >/dev/null 2>&1 || NEED_INSTALL+=("whiptail")
command -v whiptail >/dev/null 2>&1 || command -v dialog >/dev/null 2>&1 || NEED_INSTALL+=("dialog")
command -v seinfo >/dev/null 2>&1 || NEED_INSTALL+=("setools")
command -v lzip >/dev/null 2>&1 || NEED_INSTALL+=("lzip")
command -v wine64 >/dev/null 2>&1 || NEED_INSTALL+=("wine")
@ -47,11 +54,12 @@ check_dependencies() {
command -v setfattr > /dev/null 2>&1 || NEED_INSTALL+=("attr")
}
check_dependencies
osrel=$(sed -n '/^ID_LIKE=/s/^.*=//p' /etc/os-release);
declare -A os_pm_install;
# os_pm_install["/etc/redhat-release"]=yum
# os_pm_install["/etc/arch-release"]=pacman
# os_pm_install["/etc/gentoo-release"]=emerge
# os_pm_install["/etc/SuSE-release"]=zypp
os_pm_install["/etc/SuSE-release"]=zypper
os_pm_install["/etc/debian_version"]=apt-get
# os_pm_install["/etc/alpine-release"]=apk
@ -59,7 +67,7 @@ declare -A PM_UPDATE_MAP;
PM_UPDATE_MAP["yum"]="check-update"
PM_UPDATE_MAP["pacman"]="-Syu --noconfirm"
PM_UPDATE_MAP["emerge"]="-auDN @world"
PM_UPDATE_MAP["zypp"]="update -y"
PM_UPDATE_MAP["zypper"]="ref"
PM_UPDATE_MAP["apt-get"]="update"
PM_UPDATE_MAP["apk"]="update"
@ -67,7 +75,7 @@ declare -A PM_INSTALL_MAP;
PM_INSTALL_MAP["yum"]="install -y"
PM_INSTALL_MAP["pacman"]="-S --noconfirm --needed"
PM_INSTALL_MAP["emerge"]="-a"
PM_INSTALL_MAP["zypp"]="install -y"
PM_INSTALL_MAP["zypper"]="in -y"
PM_INSTALL_MAP["apt-get"]="install -y"
PM_INSTALL_MAP["apk"]="add"
@ -75,20 +83,33 @@ check_package_manager() {
for f in "${!os_pm_install[@]}"; do
if [[ -f $f ]]; then
PM="${os_pm_install[$f]}"
readarray -td ' ' UPDATE_OPTION <<<"${PM_UPDATE_MAP[$PM]} "; unset 'UPDATE_OPTION[-1]';
readarray -td ' ' INSTALL_OPTION <<<"${PM_INSTALL_MAP[$PM]} "; unset 'INSTALL_OPTION[-1]';
break
fi
done
if [[ "$osrel" = *"suse"* ]]; then
PM="zypper"
fi
if [ -n "$PM" ]; then
readarray -td ' ' UPDATE_OPTION <<<"${PM_UPDATE_MAP[$PM]} "; unset 'UPDATE_OPTION[-1]';
readarray -td ' ' INSTALL_OPTION <<<"${PM_INSTALL_MAP[$PM]} "; unset 'INSTALL_OPTION[-1]';
fi
}
check_package_manager
if [ -n "${NEED_INSTALL[*]}" ]; then
if [ -z "$PM" ]; then
echo "Unable to determine package manager: unknown distribution"
echo "Unable to determine package manager: Unsupported distros"
abort
else
if ! (sudo "$PM" "${UPDATE_OPTION[@]}" && sudo "$PM" "${INSTALL_OPTION[@]}" "${NEED_INSTALL[@]}") then abort; fi
if [ "$PM" = "zypper" ]; then
NEED_INSTALL=${NEED_INSTALL[*]}
readarray -td ' ' NEED_INSTALL <<<"${NEED_INSTALL//setools/setools-console} "; unset 'NEED_INSTALL[-1]';
elif [ "$PM" = "apk" ]; then
NEED_INSTALL=${NEED_INSTALL[*]}
readarray -td ' ' NEED_INSTALL <<<"${NEED_INSTALL//p7zip-full/p7zip} "; unset 'NEED_INSTALL[-1]';
fi
require_su
if ! ($SUDO "$PM" "${UPDATE_OPTION[@]}" && $SUDO "$PM" "${INSTALL_OPTION[@]}" "${NEED_INSTALL[@]}") then abort; fi
fi
fi
pip list --disable-pip-version-check | grep -E "^requests " >/dev/null 2>&1 || python3 -m pip install requests
@ -97,11 +118,13 @@ winetricks list-installed | grep -E "^msxml6" >/dev/null 2>&1 || {
cp -r ../wine/.cache/* ~/.cache
winetricks msxml6 || abort
}
WHIPTAIL=$(command -v whiptail 2>/dev/null)
DIALOG=$(command -v dialog 2>/dev/null)
DIALOG=${WHIPTAIL:DIALOG}
function Radiolist {
declare -A o="$1"
shift
if ! whiptail --nocancel --radiolist "${o[title]}" 0 0 0 "$@" 3>&1 1>&2 2>&3; then
if ! $DIALOG --nocancel --radiolist "${o[title]}" 0 0 0 "$@" 3>&1 1>&2 2>&3; then
echo "${o[default]}"
fi
}
@ -109,7 +132,7 @@ function Radiolist {
function YesNoBox {
declare -A o="$1"
shift
whiptail --title "${o[title]}" --yesno "${o[text]}" 0 0
$DIALOG --title "${o[title]}" --yesno "${o[text]}" 0 0
}
ARCH=$(