www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

install.sh (7291B)


      1 #!/usr/bin/env bash
      2 set -e
      3 set -x
      4 print_help() {
      5     echo "Usage:"
      6     echo "  -v, --verbose          Verbose output."
      7     echo "  -c, --clean            Force clean build, i.e. delete previously downloaded sources and start from scratch."
      8     echo "  -s, --stream=<stream>  Build a particular branch of Wayfire and other components. Usually master or a release like X.Y.Z"
      9     echo "                           Default is master"
     10     echo "  -p, --prefix=<prefix>  Prefix where to install Wayfire. Default: /opt/wayfire"
     11     echo "  --system-wlroots       Use the system-wide installation of wlroots instead of the bundled one."
     12     echo "  -y                     Run in non-interactive mode (install everything) without overwriting ~/.config/wayfire.ini nor ~/.config/wf-shell.ini if they exist"
     13     echo "  -Y                     Run in non-interactive mode (install everything), will use cp --backup=numbered to backup the existing ~/.config/wayfire.ini to ~/.config/wayfire.ini.~NUMBER~ if it already exists, same for ~/.config/wf-shell.ini"
     14     exit 1
     15 }
     16 
     17 
     18 # Parse arguments
     19 VERBOSE=0
     20 CLEANBUILD=0
     21 NON_INTERACTIVE=0
     22 NON_INTERACTIVE_SAFE_REPLACE_INI=0
     23 PREFIX=/opt/wayfire
     24 STREAM=master
     25 USE_SYSTEM_WLROOTS=disabled
     26 
     27 # Temporarily disable exit on error
     28 set +e
     29 options="$(getopt -o hvcyYs:p: --long verbose --long clean --long stream: --long prefix: --long system-wlroots -- "$@")"
     30 ERROR_CODE="$?"
     31 set -e
     32 
     33 if [ "$ERROR_CODE" != 0 ]; then
     34     print_help
     35     exit 1
     36 fi
     37 
     38 eval set -- "$options"
     39 while true; do
     40     case $1 in
     41         -v|--verbose)
     42             VERBOSE=1
     43             ;;
     44         -c|--clean)
     45             CLEANBUILD=1
     46             ;;
     47         -s|--stream)
     48             shift
     49             STREAM="$1"
     50             ;;
     51         -p|--prefix)
     52             shift
     53             PREFIX="$1"
     54             if test "x$PREFIX" != "x${PREFIX#\~/}"; then
     55                 PREFIX="$HOME/${PREFIX#\~/}"
     56             fi
     57             ;;
     58         --system-wlroots)
     59             USE_SYSTEM_WLROOTS=enabled
     60             ;;
     61         -y)
     62             NON_INTERACTIVE=1
     63             NON_INTERACTIVE_SAFE_REPLACE_INI=0
     64             ;;
     65         -Y)
     66             NON_INTERACTIVE=1
     67             NON_INTERACTIVE_SAFE_REPLACE_INI=1
     68             ;;
     69         -h|--help)
     70             print_help
     71             exit;;
     72         --)
     73             shift
     74             break;;
     75     esac
     76     shift
     77 done
     78 
     79 if [ "$VERBOSE" = 1 ]; then
     80     set -x
     81 fi
     82 
     83 echo "Building Wayfire $STREAM"
     84 echo "Installation prefix: $PREFIX"
     85 
     86 BUILDROOT="$(cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)"
     87 function ask_confirmation {
     88     if test "${NON_INTERACTIVE}" = 1; then
     89         yn=Y
     90     else
     91         while true; do
     92             read -p "$1" yn
     93             case "$yn" in
     94                 [Yy]* ) yn=Y; break;;
     95                 [Nn]* ) yn=N; break;;
     96                 * ) echo "Please answer yes or no.";;
     97             esac
     98         done
     99     fi
    100 }
    101 
    102 # Usually we use sudo, but if prefix is somewhere in ~/, we don't need sudo
    103 SUDO=sudo
    104 if [ -w "$PREFIX" ] || ! which sudo > /dev/null; then
    105     SUDO=
    106 fi
    107 
    108 if [ "${USE_SYSTEM_WLROOTS}" = disabled ] && [ "$PREFIX" = /usr ]; then
    109     ask_confirmation 'The installation of Wayfire may overwrite any system-wide wlroots installation. Continue[y/n]? '
    110     if [ "${yn}" = N ]; then
    111         exit
    112     fi
    113 fi
    114 
    115 # First step, clone necessary repositories
    116 
    117 # First argument: name of the repository to clone
    118 check_download() {
    119     cd "$BUILDROOT"
    120     if [ ! -d "$1" ] || [ "$CLEANBUILD" = 1 ]; then
    121         rm -rf "$1"
    122         git clone "https://github.com/WayfireWM/$1"
    123     fi
    124 
    125     # Checkout the correct stream
    126     cd "$1"
    127     git checkout "origin/${STREAM}"
    128 }
    129 
    130 check_download wayfire
    131 check_download wf-shell
    132 
    133 cd "$BUILDROOT/wayfire"
    134 
    135 meson build --prefix="${PREFIX}" -Duse_system_wfconfig=disabled -Duse_system_wlroots="${USE_SYSTEM_WLROOTS}"
    136 ninja -C build
    137 $SUDO ninja -C build install
    138 DEST_LIBDIR="$(meson configure | grep '^ *libdir ' | awk '{print $2}')"
    139 
    140 cd "$BUILDROOT/wf-shell"
    141 PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${PREFIX}/${DEST_LIBDIR}/pkgconfig" meson build --prefix="${PREFIX}"
    142 ninja -C build
    143 $SUDO ninja -C build install
    144 
    145 if ! pkg-config --exists libsystemd && ! pkg-config --exists libelogind && pkg-config --exists libcap; then
    146     $SUDO setcap cap_sys_admin=eip "$PREFIX/bin/wayfire"
    147 fi
    148 
    149 # Install a minimalistic, but still usable configuration
    150 # First argument is the name of the file
    151 # Second argument is the name of the template
    152 function install_config {
    153     CONFIG_FILE="$BUILDROOT/$1"
    154     cp "$2" "$CONFIG_FILE"
    155 
    156     DEFAULT_CONFIG_PATH="${HOME}/.config/$1"
    157     if [ "${XDG_CONFIG_HOME}" != "" ]; then
    158         DEFAULT_CONFIG_PATH="${XDG_CONFIG_HOME}/$1"
    159     fi
    160 
    161     if [ -f "${DEFAULT_CONFIG_PATH}" ]; then
    162         if test "${NON_INTERACTIVE}" = 1; then
    163             if test "${NON_INTERACTIVE_SAFE_REPLACE_INI}" = 1; then
    164                 yn=Y
    165             else
    166                 yn=N
    167             fi
    168         else
    169             ask_confirmation "Do you want to override the existing config file ${DEFAULT_CONFIG_PATH} [y/n]? "
    170         fi
    171     else
    172         yn=Y
    173     fi
    174 
    175     if [ "$yn" = Y ]; then
    176         mkdir -p "$(dirname "${DEFAULT_CONFIG_PATH}")"
    177         cp --backup=numbered "${CONFIG_FILE}" "${DEFAULT_CONFIG_PATH}"
    178     fi
    179 }
    180 
    181 install_config wayfire.ini "$BUILDROOT/wayfire/wayfire.ini"
    182 install_config wf-shell.ini "$BUILDROOT/wf-shell/wf-shell.ini.example"
    183 
    184 # Generate a startup script, setting necessary env vars.
    185 cp "$BUILDROOT/start_wayfire.sh.in" "$BUILDROOT/start_wayfire.sh"
    186 if [ "${PREFIX}" != '/usr' ]; then
    187     printf "PREFIX=%s" "${PREFIX@Q}"
    188     sed -i "s@^LD_.*@export LD_LIBRARY_PATH=${PREFIX}/${DEST_LIBDIR}:\$LD_LIBRARY_PATH@g" "$BUILDROOT/start_wayfire.sh"
    189     sed -i "s@^PATH.*@export PATH=${PREFIX}/bin:\$PATH@g" "$BUILDROOT/start_wayfire.sh"
    190     sed -i "s@^XDG_.*@export XDG_DATA_DIRS=${PREFIX}/share:\$XDG_DATA_DIRS@g" "$BUILDROOT/start_wayfire.sh"
    191 fi
    192 $SUDO install -m 755 "$BUILDROOT/start_wayfire.sh" "$PREFIX/bin/startwayfire"
    193 
    194 ask_confirmation "Do you want to install wayfire-plugins-extra? [y/n]? "
    195 if [ "$yn" = Y ]; then
    196     check_download wayfire-plugins-extra
    197     cd "$BUILDROOT/wayfire-plugins-extra"
    198     PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${PREFIX}/${DEST_LIBDIR}/pkgconfig" meson build --prefix="${PREFIX}"
    199     ninja -C build
    200     $SUDO ninja -C build install
    201 fi
    202 
    203 ask_confirmation "Do you want to install WCM, a graphical configuration tool for Wayfire [y/n]? "
    204 if [ "$yn" = Y ]; then
    205     check_download wcm
    206     cd "$BUILDROOT/wcm"
    207     PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${PREFIX}/${DEST_LIBDIR}/pkgconfig" meson build --prefix="${PREFIX}"
    208     ninja -C build
    209     $SUDO ninja -C build install
    210 fi
    211 
    212 SESSIONS_DIR=/usr/share/wayland-sessions/
    213 SUDO_FOR_SESSIONS=sudo
    214 if [ -w $SESSIONS_DIR ] || ! which sudo > /dev/null; then
    215   SUDO_FOR_SESSIONS=
    216 fi
    217 ask_confirmation "Do you want to install wayfire.desktop to $SESSIONS_DIR/ [y/n]? "
    218 if [ "$yn" = Y ]; then
    219     cp "$BUILDROOT/wayfire.desktop.in" "$BUILDROOT/wayfire.desktop"
    220     sed -i "s@^Exec.*@Exec=$PREFIX/bin/startwayfire@g" "$BUILDROOT/wayfire.desktop"
    221     sed -i "s@^Icon.*@Icon=$PREFIX/share/wayfire/icons/wayfire.png@g" "$BUILDROOT/wayfire.desktop"
    222     $SUDO_FOR_SESSIONS mkdir -p "$SESSIONS_DIR"
    223     $SUDO_FOR_SESSIONS install -m 644 "$BUILDROOT/wayfire.desktop" "$SESSIONS_DIR"
    224 fi
    225 
    226 echo "Installation done. Run $PREFIX/bin/startwayfire to start wayfire."