Merge pull request #1 from Ceda-EI/bash_port

Dropped PHP as a dependency
This commit is contained in:
Ceda EI 2018-04-02 02:08:41 +05:30 committed by GitHub
commit 0445a4e7e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 70 deletions

2
.gitignore vendored
View File

@ -1,2 +0,0 @@
vendor/
composer.lock

View File

@ -4,8 +4,8 @@ This prorgam downloads a new image from [Unsplash][1]. It checks whether the scr
## Dependencies
+ [PHP][2] - Available in repositories of most popular distributions.
+ [Composer][3] - Available in repositories of most popular distributions.
+ [jq][2] - Needed for parsing JSON.
+ [curl][3] - Available in most software repositories. Also, most probably installed already.
+ [Imagemagick][4] - Specifically, the `convert` command.
+ [i3lock-color][5] - Available in AUR (For Arch users). Fork of i3lock with more features. Do not use i3lock since this program utilizes the features of i3lock-color.
+ [bash][6] - Most probably will be installed already.
@ -49,8 +49,8 @@ The lock screen customization has been made easier using `~/.config/lock_prefere
<!--Links-->
[1]: https://unsplash.com
[2]: https://php.net
[3]: https://getcomposer.org
[2]: https://stedolan.github.io/jq/
[3]: https://curl.haxx.se
[4]: https://imagemagick.org
[5]: https://github.com/PandorasFox/i3lock-color
[6]: https://www.gnu.org/software/bash/

View File

@ -1,5 +0,0 @@
{
"require": {
"crewlabs/unsplash": "^2.4"
}
}

View File

@ -11,7 +11,7 @@ while : ; do
# If no, wait 300 secs and check again.
[[ `< $HOME/.config/lock_screen.sta` -eq 0 ]] && sleep 300 && continue
# Download the new image
$HOME/i3lock-delta/downloader.php
$HOME/i3lock-delta/downloader.sh
if [[ $? -eq 0 ]]; then
name_photographer="`< /tmp/name_photographer`"

View File

@ -1,46 +0,0 @@
#!/usr/bin/env php
<?php
require __DIR__.'/vendor/autoload.php';
# Initialize API
Crew\Unsplash\HttpClient::init([
'applicationId' => file_get_contents(getenv('HOME').'/i3lock-delta/api_key'),
'utmSource' => 'i3lock-Delta'
]);
# Get custom search queries
$queries_file_name = getenv('HOME') . '/.config/lock_preferences';
$queries = file($queries_file_name);
# Create the random photo limitations
if (count($queries) == 0){
$filters = [
'featured' => false,
'orientation' => 'landscape'
];
}
else {
$filters = [
'featured' => false,
'query' => $queries[rand(0,count($queries) - 1)],
'orientation' => 'landscape'
];
}
# Get the random photo
$img = Crew\Unsplash\Photo::random($filters);
# Download the photo
$url = $img->download();
$output = file_get_contents($url);
# Write image to a file
$image_filename =getenv('HOME') . '/.rand_bg';
$image_file = fopen($image_filename, 'w');
fwrite($image_file, $output);
fclose($image_file);
# Write author's name to a file
$name_file = fopen('/tmp/name_photographer', 'w');
fwrite($name_file, $img->{'user'}['name']);
fclose($name_file);

32
downloader.sh Executable file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env bash
# Get the api key
key=$(cat ~/i3lock-delta/api_key)
# Get the queries
queries=$(cat ~/.config/lock_preferences | xargs)
# Construct the base url
url="https://api.unsplash.com/photos/random?client_id=$key&orientation=landscape&featured=false"
# Check if there are any queries
if [ -n "$queries" ]; then
url="$url&query=$(shuf -n 1 ~/.config/lock_preferences)"
fi
# make API call and check if curl fails
if ! json=$(curl -s $url); then
exit 1
fi
# Get image location from json
image_download_url=$(echo $json | jq -r ".links.download_location")
image_download_url="$image_download_url?client_id=$key"
image_url=$(curl -s $image_download_url | jq -r .url)
if [[ $? -ne 0 ]] ; then exit 1; fi
# Download image and check if curl fails
curl $image_url > ~/.rand_bg
if [[ $? -ne 0 ]] ; then exit 1; fi
# Write author's name to file
user_name=$(echo $json | jq -r ".user.name")
echo "$user_name" > /tmp/name_photographer

14
install
View File

@ -17,8 +17,8 @@ function check_exec() {
echo -e "${blue}Checking Dependencies $reset"
check_exec php PHP
check_exec composer Composer
check_exec jq jq
check_exec curl curl
check_exec i3lock i3lock-color
check_exec convert Imagemagick
@ -33,16 +33,6 @@ else
echo "OK"
fi
echo -e "${blue}Checked repository location $reset \n"
echo -e "${blue}Installing Libraries $reset"
sleep 1
composer install
if [[ $? -ne 0 ]]; then
echo -e "$red Unable to install libraries. Check your internet connection"
echo -e "If the problem persists, open an issue at https://github.com/Ceda-EI/i3lock-delta/issues"
echo -e "$reset"
fi
echo -e "${blue}Finished Installing Libraries $reset \n"
echo -e "${blue}Creating Required Files$reset"