Skip to content

Instantly share code, notes, and snippets.

@jimmypoms
Created November 22, 2014 13:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jimmypoms/6ffb10f9fefaab818d4d to your computer and use it in GitHub Desktop.
Save jimmypoms/6ffb10f9fefaab818d4d to your computer and use it in GitHub Desktop.
Bash script to build all of cinnamon desktop and its dependencies on a debian based system
#!/bin/bash
nemo_built=false
Cinnamon_built=false
nemo_installed=false
Cinnamon_installed=false
MODULES=(
"cjs:https://github.com/linuxmint/cjs.git"
"cinnamon-desktop:https://github.com/linuxmint/cinnamon-desktop.git"
"cinnamon-translations:https://github.com/linuxmint/cinnamon-translations.git"
"cinnamon-session:https://github.com/linuxmint/cinnamon-session.git"
"cinnamon-settings-daemon:https://github.com/linuxmint/cinnamon-settings-daemon.git"
"cinnamon-menus:https://github.com/linuxmint/cinnamon-menus.git"
"cinnamon-control-center:https://github.com/linuxmint/cinnamon-control-center.git"
"cinnamon-bluetooth:https://github.com/linuxmint/cinnamon-bluetooth.git"
"cinnamon-screensaver:https://github.com/linuxmint/cinnamon-screensaver.git"
"muffin:https://github.com/linuxmint/muffin.git"
"Cinnamon:https://github.com/linuxmint/Cinnamon.git"
"nemo:https://github.com/linuxmint/nemo.git"
"nemo-extensions:https://github.com/linuxmint/nemo-extensions.git"
)
MV=`which mv`
RM=`which rm`" -f"
MKDIR=`which mkdir`" -p"
DPKG=`which dpkg`
SUDO=`which sudo`
GIT=`which git`
MK_BUILD_DEPS=`which mk-build-deps`
DPKG_BUILDPACKAGE=`which dpkg-buildpackage`
WORKING_DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BUILD_DIRECTORY="$WORKING_DIRECTORY"/build
APT_CACHE=`which apt-cache`
AWK=`which awk`
GREP=`which grep`
master=false
latest=false
clean=true
download=true
deps=true
build=true
install=true
assume_yes=false
me=`basename $0`
usage() {
echo "
Usage: $me [options] <command> [modules]
This scripts builds cinnamon and all of its dependencies.
If called without a, space seperated, list of modules as an argument, the given command will be applied to all modules.
If you do want to skip any supported module, it is possible to create a file named 'skip-module' inside the module's root directory in order to ignore any action taken from this script. This also works for nemo-extensions.
The following modules are supported:"
for module in "${MODULES[@]}" ; do
echo " ${module%%:*}"
done
echo "
The following options are supported:
--no-clean
--no-download
--no-build
--no-install
--no-deps
-m | --master build master branch
-l | --latest build latest git tag
-y | --assume-yes assume yes for apt install commands
The following commands are supported:
install all in one command
download clone or pull changes to local git repo
build build the module(s) packages
deps build the module(s) dependencies
check check for changes in dev dependencies today
"
exit
}
sort_version_ignore_text() {
for ver in $(echo "$1" | sort -V);
do
if [[ "$ver" =~ [[:alpha:]] ]]; then
continue
fi
echo "$ver";
done;
}
get_only_text() {
for textt in $1;
do
if [[ "$ver" =~ [[:alpha:]] ]]; then
echo $ver
fi
done;
}
style_bold() {
echo -en "\e[1m"
}
style_green() {
style_bold
echo -en "\e[32m"
}
style_red() {
style_bold
echo -en "\e[31m"
}
style_default() {
echo -en "\e[21m"
echo -en "\e[39m"
}
print_header() {
style_green
echo "=========================================================="
echo " $1"
echo "=========================================================="
style_default
sleep 1
}
print() {
style_default
echo $1
}
print_info() {
style_bold
echo $1
style_default
}
print_error() {
style_red
echo "=========================================================="
echo " $1"
echo "=========================================================="
style_default
}
check_module() {
if [ -n "$1" ]; then
for module in "${MODULES[@]}" ; do
KEY=${module%%:*}
if [ "$1" == "$KEY" ]; then
return 0
fi
done
usage
print_error "$1 is not a valid cinnamon module"
exit 1
fi
}
check_prerequisites() {
SANE=true
if [ ! -x $SUDO ]; then
SANE=false
print_info "'sudo' command is needed for the execution of this script ('sudo' package on debian)"
fi
if [ ! -x $GIT ]; then
SANE=false
print_info "'git' command is needed for the execution of this script ('git' package on debian)"
fi
if [ ! -x $MK_BUILD_DEPS ]; then
SANE=false
print_info "'mk-build_deps' command is needed for the execution of this script ('devscripts' package on debian)"
fi
if [ ! -x $DPKG_BUILDPACKAGE ]; then
SANE=false
print_info "'dpkg-buildpackage' command is needed for the execution of this script ('dpkg-dev' package on debian)"
fi
if [[ "$SANE" == false ]]; then
exit 1
fi
}
install_debs() {
if [ -z "$1" ]; then
for module in "${MODULES[@]}" ; do
install_debs ${module%%:*}
done
return
fi
print_info "installing module(s) $@"
FILES=""
for mod in "$@" ; do
if is_skipped "$mod"; then
continue
fi
if [ "$mod" == "nemo" ] && [ "$nemo_installed" == true ]; then
continue
fi
if [ "$mod" == "Cinnamon" ] && [ "$Cinnamon_installed" == true ]; then
continue
fi
if [ "$mod" == "nemo-extensions" ]; then
install_debs_nemo_extensions
continue
fi
MODULE_DIRECTORY=$WORKING_DIRECTORY/$mod
FILES_FILE=$MODULE_DIRECTORY/debian/files
for file in `$GREP -Eo '^[^ ]+' $FILES_FILE` ; do
FILES=$FILES" "$BUILD_DIRECTORY/$file
done
if [ "$mod" == "nemo" ]; then
nemo_installed=true
fi
if [ "$mod" == "Cinnamon" ]; then
Cinnamon_installed=true
fi
done
if [ -z "$FILES" ]; then
return
fi
$SUDO $DPKG -i $FILES
if [ $? -ne 0 ]; then
print_error "error installing $file ($@)"
exit 1
fi
}
install_debs_nemo_extensions() {
PWD=`pwd`
cd $WORKING_DIRECTORY/nemo-extensions
$SUDO $DPKG -i *.deb
cd $PWD
}
cleanup() {
if [ -z "$1" ]; then
for module in "${MODULES[@]}" ; do
cleanup ${module%%:*}
done
return
fi
print_info "cleaning up module $1"
if is_skipped "$1"; then
return
fi
if [ "$1" == "nemo-extensions" ]; then
cleanup_nemo_extensions
return
fi
MODULE_DIRECTORY=$WORKING_DIRECTORY/$1
FILES_FILE=$MODULE_DIRECTORY/debian/files
if [ -a $FILES_FILE ]; then
for file in `$GREP -Eo '^[^ ]+' $FILES_FILE` ; do
$RM $file
done
fi
filename=${1,,}
cd $MODULE_DIRECTORY
$DPKG_BUILDPACKAGE -Tclean
cd $WORKING_DIRECTORY
}
cleanup_nemo_extensions() {
PWD=`pwd`
cd $WORKING_DIRECTORY/nemo-extensions
rm *.deb
rm *.changes
rm *.dsc
rm *.tar.gz
rm *.tar.xz
for i in `find ./ -maxdepth 1 -mindepth 1 -type d`; do
if [ $i = "./.git" ]; then
continue
fi
if is_skipped "nemo-extensions/$i"; then
continue
fi
echo $i
cd $i
$DPKG_BUILDPACKAGE -Tclean
cd ..
done
cd $PWD
}
get() {
for module in "${MODULES[@]}" ; do
key=${module%%:*}
if [ "$1" == "$key" ]; then
value=${module#*:}
echo "$value"
return
fi
done
}
check_git() {
if [ $? -ne 0 ]; then
module=$1
command=${*:2}
resolved=false
while [ $resolved == false ]; do
print_error "something went wrong with git $command for $module"
print_info "what do you want to do?"
print_info "Checkout and $command (c), stash and $command (s), show diff (d), reinstall $module (r), quit (q)"
read what
case $what in
c )
$GIT checkout .
$GIT $command
resolved=true
;;
s )
$GIT stash
$GIT $command
resolved=true
;;
d )
$GIT diff
;;
r )
MODULE_DIRECTORY=$WORKING_DIRECTORY/$module
MODULE_REPOSITORY=`get $module`
cd ..
rm -Rf $module
$GIT clone $MODULE_REPOSITORY $module
cd $module
$GIT $command
resolved=true
;;
q )
exit 1
;;
esac
done
fi
}
download() {
if [ -z "$1" ]; then
for module in "${MODULES[@]}" ; do
download ${module%%:*}
done
return
fi
if is_skipped $1; then
return
fi
check_module $1
print_info "checking out module $1"
MODULE_DIRECTORY=$WORKING_DIRECTORY/$1
MODULE_REPOSITORY=`get $1`
if [ -d $MODULE_DIRECTORY ]; then
cd $MODULE_DIRECTORY
$GIT checkout master
check_git $1 checkout master
$GIT pull
check_git $1 pull
if [ $? -ne 0 ]; then
print_error "something went wrong pulling latest changes for $1"
exit 1
fi
cd $WORKING_DIRECTORY
else
$GIT clone $MODULE_REPOSITORY $1
if [ $? -ne 0 ]; then
print_error "something went wrong checking out $1"
exit 1
fi
fi
cd $MODULE_DIRECTORY
tags=$(sort_version_ignore_text "`$GIT tag`")
options=($(get_only_text "$tags") $(sort_version_ignore_text "$tags") master)
itLen=${#options[@]}
latestTag=${options[`expr $itLen - 2`]}
if [ "$master" == true ]; then
$GIT checkout master
check_git $1 heckout master
elif [ "$latest" == true ]; then
$GIT checkout $latestTag
check_git $1 checkout $latestTag
else
PS3="Please enter version to use for $1: "
select tag in ${options[*]}
do
$GIT checkout $tag
check_git $1 checkout $tag
break
done
fi
cd $WORKING_DIRECTORY
}
build_dep() {
if [ -z "$1" ]; then
for module in "${MODULES[@]}" ; do
build_dep ${module%%:*}
done
return
fi
if is_skipped $1; then
return
fi
if [ $deps == false ]; then
return
fi
check_module $1
print_info "building dependencies for module $1"
if [ "$1" == "nemo-extensions" ]; then
build_dep_nemo_extensions
return
fi
MODULE_DIRECTORY=$WORKING_DIRECTORY/$1
cd $MODULE_DIRECTORY
if [ "$assume_yes" == true ]; then
$SUDO $MK_BUILD_DEPS -i -r -t "apt-get --no-install-recommends -y"
else
$SUDO $MK_BUILD_DEPS -i -r
fi
if [ $? -ne 0 ]; then
print_error "something went wrong installing build dependencies for $1"
exit 1
fi
cd $WORKING_DIRECTORY
}
build_dep_nemo_extensions() {
PWD=`pwd`
cd $WORKING_DIRECTORY/nemo-extensions
for i in `find ./ -maxdepth 1 -mindepth 1 -type d`; do
if [ $i = "./.git" ]; then
continue
fi
if is_skipped "nemo-extensions/$i"; then
continue
fi
cd $i
if [ "$assume_yes" == true ]; then
$SUDO $MK_BUILD_DEPS -i -r -t "apt-get --no-install-recommends -y"
else
$SUDO $MK_BUILD_DEPS -i -r
fi
cd ..
done
cd $PWD
}
move_generated_files() {
if is_skipped "$1"; then
return
fi
print_info "moving generated files for $1"
MODULE_DIRECTORY=$WORKING_DIRECTORY/$1
FILES_FILE=$MODULE_DIRECTORY/debian/files
for file in `$GREP -Eo '^[^ ]+' $FILES_FILE` ; do
$MV $WORKING_DIRECTORY/$file $BUILD_DIRECTORY
done
}
rebuild=""
print=true
check() {
package_rebuild=false
if [ -z "$1" ]; then
print=false
for module in "${MODULES[@]}" ; do
check ${module%%:*}
done
if [ -n "$rebuild" ]; then
print_header "$rebuild rebuild recommended"
fi
return
fi
if is_skipped "$1"; then
return
fi
print_info "checking dependency changes for $1"
packages=`$APT_CACHE depends $1-build-deps | $GREP "\-dev" | $AWK 'NF>1{print $NF}'`
for package in $packages; do
currentdate=`date -I`
if [[ `$GREP "$currentdate" /var/log/dpkg.log | $AWK '$3~/^upgrade$/ {print $4;}' | $GREP -c $package` -ne 0 ]]; then
print "$package changed"
package_rebuild=true
continue
fi
done
if [ "$package_rebuild" == true ]; then
rebuild=$rebuild" "$1
fi
if [ -n "$rebuild" ] && [ "$print" == true ]; then
print_header "$rebuild rebuild required"
fi
}
build() {
if [ -z "$1" ]; then
for module in "${MODULES[@]}" ; do
build ${module%%:*}
done
return
fi
if is_skipped "$1"; then
return
fi
if [ "$1" == "nemo" ] && [ "$nemo_built" == true ]; then
return
fi
if [ "$1" == "Cinnamon" ] && [ "$Cinnamon_built" == true ]; then
return
fi
check_module $1
build_dep $1
print_info "building module $1"
if [ "$1" == "nemo-extensions" ]; then
build_nemo_extensions
return
fi
MODULE_DIRECTORY=$WORKING_DIRECTORY/$1
cd $MODULE_DIRECTORY
$DPKG_BUILDPACKAGE -uc -us -j4
if [ $? -ne 0 ]; then
print_error "something went wrong building $1"
exit 1
fi
move_generated_files $1
cd $WORKING_DIRECTORY
print_info "files generated in '$BUILD_DIRECTORY'"
if [ "$1" == "nemo" ]; then
nemo_built=true
fi
if [ "$1" == "Cinnamon" ]; then
Cinnamon_built=true
fi
}
build_nemo_extensions() {
PWD=`pwd`
cd $WORKING_DIRECTORY/nemo-extensions
for i in `find ./ -maxdepth 1 -mindepth 1 -type d`; do
if [ $i = "./.git" ]; then
continue
fi
if is_skipped "nemo-extensions/$i"; then
continue
fi
cd $i
$DPKG_BUILDPACKAGE -uc -us -j4
cd ..
done
cd $PWD
}
build_install() {
if [ -z "$1" ]; then
for module in "${MODULES[@]}" ; do
build_install ${module%%:*}
done
return
fi
if is_skipped "$1"; then
return
fi
if [ "$1" == "nemo" ] && [ "$Cinnamon_built" == false ]; then
build nemo
build Cinnamon
elif [ "$1" == "Cinnamon" ] && [ "$nemo_built" == false ]; then
build nemo
build Cinnamon
else
build $1
fi
if [[ "$install" == true ]]; then
if [ "$1" == "nemo" ] && [ "$Cinnamon_installed" == false ]; then
install_debs nemo Cinnamon
elif [ "$1" == "Cinnamon" ] && [ "$nemo_installed" == false ]; then
install_debs nemo Cinnamon
else
install_debs $1
fi
fi
}
install() {
if [ -z "$1" ]; then
if [[ "$clean" == true ]]; then
print_header "cleaning up all modules"
cleanup
fi
if [[ "$download" == true ]]; then
print_header "checking out all modules"
download
fi
if [[ "$build" == true ]]; then
print_header "building and installing all modules"
build_install
fi
return
fi
if is_skipped "$1"; then
return
fi
check_module $1
if [[ "$clean" == true ]]; then
cleanup $1
fi
if [[ "$download" == true ]]; then
download $1
fi
if [[ "$build" == true ]]; then
build_install $1
fi
}
deps() {
build_dep $@
}
clean() {
PWD=`pwd`
cd $BUILD_DIRECTORY
$RM *
cd $WORKING_DIRECTORY
$RM *$filename*.changes
$RM *$filename*.dsc
$RM *$filename*.tar.gz
$RM *$filename*.tar.xz
cd $PWD
cleanup $@
}
is_skipped() {
if [ -e $WORKING_DIRECTORY/$1/skip-module ]; then
print_info "$1 is skipped hence ignoring (remove $1/skip-module to unskip)"
return 0
fi
return 1
}
start() {
if [ "$command" != false ]; then
$MKDIR $BUILD_DIRECTORY
if [ -z "$modules" ]; then
$command
fi
for module in $modules; do
$command $module
done
else
usage
exit 1
fi
}
check_prerequisites
command=false
modules=''
while [ "$1" != "" ]; do
case $1 in
install | download | build | deps | clean | check )
command=$1
modules=${*:2}
break
;;
--no-clean )
clean=false
;;
--no-download )
download=false
;;
--no-build )
build=false
;;
--no-deps )
deps=false
;;
--no-install )
install=false
;;
-m | --master )
master=true
;;
-l | --latest )
latest=true
;;
-y | --assume-yes )
assume_yes=true
;;
* )
usage
exit 1
esac
shift
done
start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment